mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'test/http_server_advanced_tests' into 'master'
test: Refactor http_server advanced_tests to use regular import method See merge request espressif/esp-idf!6803
This commit is contained in:
commit
5ba70e713a
@ -40,8 +40,9 @@ import Utility
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
# Import client module
|
||||
# TODO: replace with import
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
client = Utility.load_source("client", expath + "/scripts/test.py")
|
||||
client = Utility.load_source(expath + "/scripts/test.py")
|
||||
|
||||
|
||||
# Due to connectivity issues (between runner host and DUT) in the runner environment,
|
||||
|
@ -42,8 +42,9 @@ import Utility
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
# Import client module
|
||||
# TODO: replace with import
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
client = Utility.load_source("client", expath + "/scripts/adder.py")
|
||||
client = Utility.load_source(expath + "/scripts/adder.py")
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
|
@ -44,7 +44,7 @@ import Utility
|
||||
|
||||
# Import client module
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
client = Utility.load_source("client", expath + "/scripts/client.py")
|
||||
client = Utility.load_source(expath + "/scripts/client.py")
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
|
@ -172,9 +172,9 @@ class Parser(object):
|
||||
"""
|
||||
output = dict()
|
||||
for key in overwrite:
|
||||
_path = overwrite[key]["path"]
|
||||
_module = load_source(str(hash(_path)), overwrite[key]["path"])
|
||||
output[key] = _module.__getattribute__(overwrite[key]["class"])
|
||||
path = overwrite[key]["path"]
|
||||
module = load_source(path)
|
||||
output[key] = module.__getattribute__(overwrite[key]["class"])
|
||||
return output
|
||||
|
||||
@classmethod
|
||||
|
@ -30,7 +30,7 @@ class Search(object):
|
||||
print("Try to get cases from: " + file_name)
|
||||
test_functions = []
|
||||
try:
|
||||
mod = load_source(str(hash(file_name)), file_name)
|
||||
mod = load_source(file_name)
|
||||
for func in [mod.__getattribute__(x) for x in dir(mod)
|
||||
if isinstance(mod.__getattribute__(x), types.FunctionType)]:
|
||||
try:
|
||||
|
@ -1,4 +1,5 @@
|
||||
from __future__ import print_function
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
|
||||
@ -45,16 +46,26 @@ __LOADED_MODULES = dict()
|
||||
# it will lead to strange errors like `isinstance(object, type_of_this_object)` return False
|
||||
|
||||
|
||||
def load_source(name, path):
|
||||
def load_source(path):
|
||||
"""
|
||||
Dynamic loading python file. Note that this function SHOULD NOT be used to replace ``import``.
|
||||
It should only be used when the package path is only available in runtime.
|
||||
|
||||
:param path: The path of python file
|
||||
:return: Loaded object
|
||||
"""
|
||||
path = os.path.realpath(path)
|
||||
# load name need to be unique, otherwise it will update the already loaded module
|
||||
load_name = str(len(__LOADED_MODULES))
|
||||
try:
|
||||
return __LOADED_MODULES[name]
|
||||
return __LOADED_MODULES[path]
|
||||
except KeyError:
|
||||
try:
|
||||
from importlib.machinery import SourceFileLoader
|
||||
ret = SourceFileLoader(name, path).load_module()
|
||||
ret = SourceFileLoader(load_name, path).load_module()
|
||||
except ImportError:
|
||||
# importlib.machinery doesn't exists in Python 2 so we will use imp (deprecated in Python 3)
|
||||
import imp
|
||||
ret = imp.load_source(name, path)
|
||||
__LOADED_MODULES[name] = ret
|
||||
ret = imp.load_source(load_name, path)
|
||||
__LOADED_MODULES[path] = ret
|
||||
return ret
|
||||
|
Loading…
x
Reference in New Issue
Block a user