From 7a5d17e1b7806577c1373ff0d556f3d1cc44fcda Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Wed, 27 Nov 2019 11:21:33 +0800 Subject: [PATCH] tiny-test-fw: move to tools/esp_python_packages: make `tiny_test_fw` as a package and move to root path of idf python packages --- .../python_packages/tiny_test_fw}/App.py | 0 .../python_packages/tiny_test_fw}/DUT.py | 0 .../python_packages/tiny_test_fw}/Env.py | 0 .../tiny_test_fw}/EnvConfig.py | 0 .../tiny_test_fw}/EnvConfigTemplate.yml | 0 .../python_packages/tiny_test_fw}/TinyFW.py | 0 .../tiny_test_fw}/Utility/CIAssignTest.py | 8 ++++-- .../tiny_test_fw}/Utility/CaseConfig.py | 20 +++++++------- .../tiny_test_fw}/Utility/GitlabCIJob.py | 0 .../tiny_test_fw}/Utility/SearchCases.py | 3 ++- .../tiny_test_fw/Utility}/TestCase.py | 0 .../tiny_test_fw}/Utility/__init__.py | 0 .../python_packages/tiny_test_fw/__init__.py} | 0 .../tiny_test_fw/bin}/Runner.py | 4 +-- .../tiny_test_fw/bin}/example.py | 0 .../tiny_test_fw}/docs/Makefile | 0 .../tiny_test_fw/docs/_static/.keep | 0 .../tiny_test_fw}/docs/conf.py | 0 .../tiny_test_fw}/docs/index.rst | 0 .../tiny_test_fw}/requirements.txt | 0 .../ttfw_idf}/CIAssignExampleTest.py | 26 +++++++++++-------- .../ttfw_idf}/CIAssignUnitTest.py | 13 ++++------ .../python_packages/ttfw_idf}/IDFApp.py | 2 +- .../python_packages/ttfw_idf}/IDFDUT.py | 3 +-- .../python_packages/ttfw_idf}/__init__.py | 7 +++-- tools/ci/setup_python.sh | 3 +++ .../tiny_test_fw}/Utility/Attenuator.py | 0 .../tiny_test_fw}/Utility/LineChart.py | 0 .../tiny_test_fw}/Utility/PowerControl.py | 0 29 files changed, 49 insertions(+), 40 deletions(-) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/App.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/DUT.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Env.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/EnvConfig.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/EnvConfigTemplate.yml (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/TinyFW.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Utility/CIAssignTest.py (98%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Utility/CaseConfig.py (95%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Utility/GitlabCIJob.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Utility/SearchCases.py (99%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw/Utility}/TestCase.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/Utility/__init__.py (100%) rename tools/{tiny-test-fw/docs/_static/.keep => ci/python_packages/tiny_test_fw/__init__.py} (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw/bin}/Runner.py (96%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw/bin}/example.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/docs/Makefile (100%) create mode 100644 tools/ci/python_packages/tiny_test_fw/docs/_static/.keep rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/docs/conf.py (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/docs/index.rst (100%) rename tools/{tiny-test-fw => ci/python_packages/tiny_test_fw}/requirements.txt (100%) rename tools/{tiny-test-fw => ci/python_packages/ttfw_idf}/CIAssignExampleTest.py (79%) rename tools/{tiny-test-fw => ci/python_packages/ttfw_idf}/CIAssignUnitTest.py (96%) rename tools/{tiny-test-fw/IDF => ci/python_packages/ttfw_idf}/IDFApp.py (99%) rename tools/{tiny-test-fw/IDF => ci/python_packages/ttfw_idf}/IDFDUT.py (99%) rename tools/{tiny-test-fw/IDF => ci/python_packages/ttfw_idf}/__init__.py (97%) rename tools/{tiny-test-fw => esp_python_packages/tiny_test_fw}/Utility/Attenuator.py (100%) rename tools/{tiny-test-fw => esp_python_packages/tiny_test_fw}/Utility/LineChart.py (100%) rename tools/{tiny-test-fw => esp_python_packages/tiny_test_fw}/Utility/PowerControl.py (100%) diff --git a/tools/tiny-test-fw/App.py b/tools/ci/python_packages/tiny_test_fw/App.py similarity index 100% rename from tools/tiny-test-fw/App.py rename to tools/ci/python_packages/tiny_test_fw/App.py diff --git a/tools/tiny-test-fw/DUT.py b/tools/ci/python_packages/tiny_test_fw/DUT.py similarity index 100% rename from tools/tiny-test-fw/DUT.py rename to tools/ci/python_packages/tiny_test_fw/DUT.py diff --git a/tools/tiny-test-fw/Env.py b/tools/ci/python_packages/tiny_test_fw/Env.py similarity index 100% rename from tools/tiny-test-fw/Env.py rename to tools/ci/python_packages/tiny_test_fw/Env.py diff --git a/tools/tiny-test-fw/EnvConfig.py b/tools/ci/python_packages/tiny_test_fw/EnvConfig.py similarity index 100% rename from tools/tiny-test-fw/EnvConfig.py rename to tools/ci/python_packages/tiny_test_fw/EnvConfig.py diff --git a/tools/tiny-test-fw/EnvConfigTemplate.yml b/tools/ci/python_packages/tiny_test_fw/EnvConfigTemplate.yml similarity index 100% rename from tools/tiny-test-fw/EnvConfigTemplate.yml rename to tools/ci/python_packages/tiny_test_fw/EnvConfigTemplate.yml diff --git a/tools/tiny-test-fw/TinyFW.py b/tools/ci/python_packages/tiny_test_fw/TinyFW.py similarity index 100% rename from tools/tiny-test-fw/TinyFW.py rename to tools/ci/python_packages/tiny_test_fw/TinyFW.py diff --git a/tools/tiny-test-fw/Utility/CIAssignTest.py b/tools/ci/python_packages/tiny_test_fw/Utility/CIAssignTest.py similarity index 98% rename from tools/tiny-test-fw/Utility/CIAssignTest.py rename to tools/ci/python_packages/tiny_test_fw/Utility/CIAssignTest.py index 00e3054bdd..056d75f1c9 100644 --- a/tools/tiny-test-fw/Utility/CIAssignTest.py +++ b/tools/ci/python_packages/tiny_test_fw/Utility/CIAssignTest.py @@ -44,8 +44,12 @@ import re import json import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader -from Utility import (CaseConfig, SearchCases, GitlabCIJob, console_log) +from . import (CaseConfig, SearchCases, GitlabCIJob, console_log) class Group(object): @@ -164,7 +168,7 @@ class AssignTest(object): def _parse_gitlab_ci_config(self, ci_config_file): with open(ci_config_file, "r") as f: - ci_config = yaml.load(f) + ci_config = yaml.load(f, Loader=Loader) job_list = list() for job_name in ci_config: diff --git a/tools/tiny-test-fw/Utility/CaseConfig.py b/tools/ci/python_packages/tiny_test_fw/Utility/CaseConfig.py similarity index 95% rename from tools/tiny-test-fw/Utility/CaseConfig.py rename to tools/ci/python_packages/tiny_test_fw/Utility/CaseConfig.py index ee6234da8e..b08c520c71 100644 --- a/tools/tiny-test-fw/Utility/CaseConfig.py +++ b/tools/ci/python_packages/tiny_test_fw/Utility/CaseConfig.py @@ -20,7 +20,7 @@ Template Config File:: TestConfig: app: - path: Users/Test/TinyTestFW/IDF/IDFApp.py + package: ttfw_idf class: Example dut: path: @@ -38,16 +38,19 @@ Template Config File:: extra_data: some extra data passed to case with kwarg extra_data overwrite: # overwrite test configs app: - path: Users/Test/TinyTestFW/IDF/IDFApp.py + package: ttfw_idf class: Example - name: xxx """ +import importlib import yaml +try: + from yaml import CLoader as Loader +except ImportError: + from yaml import Loader as Loader -import TestCase - -from Utility import load_source +from . import TestCase def _convert_to_lower_case_bytes(item): @@ -154,7 +157,7 @@ class Parser(object): configs = cls.DEFAULT_CONFIG.copy() if config_file: with open(config_file, "r") as f: - configs.update(yaml.load(f)) + configs.update(yaml.load(f, Loader=Loader)) return configs @classmethod @@ -167,9 +170,8 @@ 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"]) + module = importlib.import_module(overwrite[key]["package"]) + output[key] = module.__getattribute__(overwrite[key]["class"]) return output @classmethod diff --git a/tools/tiny-test-fw/Utility/GitlabCIJob.py b/tools/ci/python_packages/tiny_test_fw/Utility/GitlabCIJob.py similarity index 100% rename from tools/tiny-test-fw/Utility/GitlabCIJob.py rename to tools/ci/python_packages/tiny_test_fw/Utility/GitlabCIJob.py diff --git a/tools/tiny-test-fw/Utility/SearchCases.py b/tools/ci/python_packages/tiny_test_fw/Utility/SearchCases.py similarity index 99% rename from tools/tiny-test-fw/Utility/SearchCases.py rename to tools/ci/python_packages/tiny_test_fw/Utility/SearchCases.py index a0930d307e..94cb9d2ca4 100644 --- a/tools/tiny-test-fw/Utility/SearchCases.py +++ b/tools/ci/python_packages/tiny_test_fw/Utility/SearchCases.py @@ -17,7 +17,8 @@ import os import fnmatch import types import copy -from Utility import load_source + +from . import load_source class Search(object): diff --git a/tools/tiny-test-fw/TestCase.py b/tools/ci/python_packages/tiny_test_fw/Utility/TestCase.py similarity index 100% rename from tools/tiny-test-fw/TestCase.py rename to tools/ci/python_packages/tiny_test_fw/Utility/TestCase.py diff --git a/tools/tiny-test-fw/Utility/__init__.py b/tools/ci/python_packages/tiny_test_fw/Utility/__init__.py similarity index 100% rename from tools/tiny-test-fw/Utility/__init__.py rename to tools/ci/python_packages/tiny_test_fw/Utility/__init__.py diff --git a/tools/tiny-test-fw/docs/_static/.keep b/tools/ci/python_packages/tiny_test_fw/__init__.py similarity index 100% rename from tools/tiny-test-fw/docs/_static/.keep rename to tools/ci/python_packages/tiny_test_fw/__init__.py diff --git a/tools/tiny-test-fw/Runner.py b/tools/ci/python_packages/tiny_test_fw/bin/Runner.py similarity index 96% rename from tools/tiny-test-fw/Runner.py rename to tools/ci/python_packages/tiny_test_fw/bin/Runner.py index ea124c1489..a233de64f5 100644 --- a/tools/tiny-test-fw/Runner.py +++ b/tools/ci/python_packages/tiny_test_fw/bin/Runner.py @@ -26,8 +26,8 @@ import sys import argparse import threading -import TinyFW -from Utility import SearchCases, CaseConfig +from tiny_test_fw import TinyFW +from tiny_test_fw.Utility import SearchCases, CaseConfig class Runner(threading.Thread): diff --git a/tools/tiny-test-fw/example.py b/tools/ci/python_packages/tiny_test_fw/bin/example.py similarity index 100% rename from tools/tiny-test-fw/example.py rename to tools/ci/python_packages/tiny_test_fw/bin/example.py diff --git a/tools/tiny-test-fw/docs/Makefile b/tools/ci/python_packages/tiny_test_fw/docs/Makefile similarity index 100% rename from tools/tiny-test-fw/docs/Makefile rename to tools/ci/python_packages/tiny_test_fw/docs/Makefile diff --git a/tools/ci/python_packages/tiny_test_fw/docs/_static/.keep b/tools/ci/python_packages/tiny_test_fw/docs/_static/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/tiny-test-fw/docs/conf.py b/tools/ci/python_packages/tiny_test_fw/docs/conf.py similarity index 100% rename from tools/tiny-test-fw/docs/conf.py rename to tools/ci/python_packages/tiny_test_fw/docs/conf.py diff --git a/tools/tiny-test-fw/docs/index.rst b/tools/ci/python_packages/tiny_test_fw/docs/index.rst similarity index 100% rename from tools/tiny-test-fw/docs/index.rst rename to tools/ci/python_packages/tiny_test_fw/docs/index.rst diff --git a/tools/tiny-test-fw/requirements.txt b/tools/ci/python_packages/tiny_test_fw/requirements.txt similarity index 100% rename from tools/tiny-test-fw/requirements.txt rename to tools/ci/python_packages/tiny_test_fw/requirements.txt diff --git a/tools/tiny-test-fw/CIAssignExampleTest.py b/tools/ci/python_packages/ttfw_idf/CIAssignExampleTest.py similarity index 79% rename from tools/tiny-test-fw/CIAssignExampleTest.py rename to tools/ci/python_packages/ttfw_idf/CIAssignExampleTest.py index bd6bdaf3b8..85beb1f086 100644 --- a/tools/tiny-test-fw/CIAssignExampleTest.py +++ b/tools/ci/python_packages/ttfw_idf/CIAssignExampleTest.py @@ -22,25 +22,29 @@ import sys import re import argparse -try: - from Utility.CIAssignTest import AssignTest -except ImportError: - test_fw_path = os.getenv("TEST_FW_PATH") - if test_fw_path: - sys.path.insert(0, test_fw_path) - from Utility.CIAssignTest import AssignTest - -from Utility.CIAssignTest import Group +import gitlab_api +from tiny_test_fw.Utility import CIAssignTest -class ExampleGroup(Group): +class ExampleGroup(CIAssignTest.Group): SORT_KEYS = CI_JOB_MATCH_KEYS = ["env_tag", "chip"] -class CIExampleAssignTest(AssignTest): +class CIExampleAssignTest(CIAssignTest.AssignTest): CI_TEST_JOB_PATTERN = re.compile(r"^example_test_.+") +class ArtifactFile(object): + def __init__(self, project_id, job_name, artifact_file_path): + self.gitlab_api = gitlab_api.Gitlab(project_id) + + def process(self): + pass + + def output(self): + pass + + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("test_case", diff --git a/tools/tiny-test-fw/CIAssignUnitTest.py b/tools/ci/python_packages/ttfw_idf/CIAssignUnitTest.py similarity index 96% rename from tools/tiny-test-fw/CIAssignUnitTest.py rename to tools/ci/python_packages/ttfw_idf/CIAssignUnitTest.py index 75af78201a..6f2ff00b69 100644 --- a/tools/tiny-test-fw/CIAssignUnitTest.py +++ b/tools/ci/python_packages/ttfw_idf/CIAssignUnitTest.py @@ -3,19 +3,16 @@ Command line tool to assign unit tests to CI test jobs. """ import re -import os -import sys import argparse import yaml try: - from Utility import CIAssignTest + from yaml import CLoader as Loader except ImportError: - test_fw_path = os.getenv("TEST_FW_PATH") - if test_fw_path: - sys.path.insert(0, test_fw_path) - from Utility import CIAssignTest + from yaml import Loader as Loader + +from tiny_test_fw.Utility import CIAssignTest class Group(CIAssignTest.Group): @@ -133,7 +130,7 @@ class UnitTestAssignTest(CIAssignTest.AssignTest): try: with open(test_case_path, "r") as f: - raw_data = yaml.load(f) + raw_data = yaml.load(f, Loader=Loader) test_cases = raw_data["test cases"] for case in test_cases: case["tags"] = set(case["tags"]) diff --git a/tools/tiny-test-fw/IDF/IDFApp.py b/tools/ci/python_packages/ttfw_idf/IDFApp.py similarity index 99% rename from tools/tiny-test-fw/IDF/IDFApp.py rename to tools/ci/python_packages/ttfw_idf/IDFApp.py index f3bf8cb5f7..385af49c2c 100644 --- a/tools/tiny-test-fw/IDF/IDFApp.py +++ b/tools/ci/python_packages/ttfw_idf/IDFApp.py @@ -17,7 +17,7 @@ import subprocess import os import json -import App +from tiny_test_fw import App class IDFApp(App.BaseApp): diff --git a/tools/tiny-test-fw/IDF/IDFDUT.py b/tools/ci/python_packages/ttfw_idf/IDFDUT.py similarity index 99% rename from tools/tiny-test-fw/IDF/IDFDUT.py rename to tools/ci/python_packages/ttfw_idf/IDFDUT.py index a5ab3194b9..9f64cbea9d 100644 --- a/tools/tiny-test-fw/IDF/IDFDUT.py +++ b/tools/ci/python_packages/ttfw_idf/IDFDUT.py @@ -30,8 +30,7 @@ except ImportError: from serial.tools import list_ports -import DUT -import Utility +from tiny_test_fw import DUT, Utility try: import esptool diff --git a/tools/tiny-test-fw/IDF/__init__.py b/tools/ci/python_packages/ttfw_idf/__init__.py similarity index 97% rename from tools/tiny-test-fw/IDF/__init__.py rename to tools/ci/python_packages/ttfw_idf/__init__.py index 56db1b2872..001da23095 100644 --- a/tools/tiny-test-fw/IDF/__init__.py +++ b/tools/ci/python_packages/ttfw_idf/__init__.py @@ -14,10 +14,9 @@ import os import re -import TinyFW -import Utility -from IDF.IDFApp import IDFApp, Example, UT -from IDF.IDFDUT import IDFDUT +from tiny_test_fw import TinyFW, Utility +from IDFApp import IDFApp, Example, UT +from IDFDUT import IDFDUT def format_case_id(chip, case_name): diff --git a/tools/ci/setup_python.sh b/tools/ci/setup_python.sh index c134ba816b..a0e1723be0 100644 --- a/tools/ci/setup_python.sh +++ b/tools/ci/setup_python.sh @@ -51,3 +51,6 @@ else echo 'No /opt/pyenv/activate exists and no Python interpreter is found!' exit 1 fi + +# add esp-idf local package path to PYTHONPATH so it can be imported directly +export PYTHONPATH="$IDF_PATH/tools:$IDF_PATH/tools/ci/python_packages:$PYTHONPATH" diff --git a/tools/tiny-test-fw/Utility/Attenuator.py b/tools/esp_python_packages/tiny_test_fw/Utility/Attenuator.py similarity index 100% rename from tools/tiny-test-fw/Utility/Attenuator.py rename to tools/esp_python_packages/tiny_test_fw/Utility/Attenuator.py diff --git a/tools/tiny-test-fw/Utility/LineChart.py b/tools/esp_python_packages/tiny_test_fw/Utility/LineChart.py similarity index 100% rename from tools/tiny-test-fw/Utility/LineChart.py rename to tools/esp_python_packages/tiny_test_fw/Utility/LineChart.py diff --git a/tools/tiny-test-fw/Utility/PowerControl.py b/tools/esp_python_packages/tiny_test_fw/Utility/PowerControl.py similarity index 100% rename from tools/tiny-test-fw/Utility/PowerControl.py rename to tools/esp_python_packages/tiny_test_fw/Utility/PowerControl.py