From 5d2f5eb85c092aeadb4918c3b773cd43e24610ef Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Mon, 9 Dec 2024 22:36:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- .../generator/scaffold/golang/README.md | 7 ++- .../generator/scaffold/golang/check.sh | 53 +++++++++++++++++++ .../scaffold/golang/cmd/discover/discover.go | 2 +- .../scaffold/golang/cmd/execute/execute.go | 2 +- .../generator/scaffold/python/README.md | 8 +-- .../generator/scaffold/python/check.sh | 2 +- .../src/testsolar_replace_____me/collector.py | 12 ++--- .../src/testsolar_replace_____me/executor.py | 16 +++--- uv.lock | 2 +- 10 files changed, 83 insertions(+), 23 deletions(-) create mode 100755 src/testtools_cli/generator/scaffold/golang/check.sh mode change 100644 => 100755 src/testtools_cli/generator/scaffold/python/check.sh diff --git a/pyproject.toml b/pyproject.toml index 49878b2..ee59451 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testtools-cli" -version = "0.2.17" +version = "0.2.18" description = "TestSolar TestTool CLI" authors = [ { name = "asiazhang", email = "asiazhang2002@gmail.com" }, diff --git a/src/testtools_cli/generator/scaffold/golang/README.md b/src/testtools_cli/generator/scaffold/golang/README.md index 2b0cf31..3819511 100644 --- a/src/testtools_cli/generator/scaffold/golang/README.md +++ b/src/testtools_cli/generator/scaffold/golang/README.md @@ -1 +1,6 @@ -# {{ replace_____me }} \ No newline at end of file +# replace_____me + +## 注意事项 + +- 默认项目依赖golang版本>=1.22 +- 调用`./check.sh`对代码进行静态检查并执行单测,静态检查依赖`golangci-lint`,具体安装方式请参考[golangci-lint](https://golangci-lint.run/welcome/install/) \ No newline at end of file diff --git a/src/testtools_cli/generator/scaffold/golang/check.sh b/src/testtools_cli/generator/scaffold/golang/check.sh new file mode 100755 index 0000000..439632d --- /dev/null +++ b/src/testtools_cli/generator/scaffold/golang/check.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +NC='\033[0m' + +info() { + echo -e "${GREEN}$1${NC}" +} + +error() { + echo -e "${RED}$1${NC}" +} + +# go fmt +info "Running go fmt..." +if ! go fmt ./...; then + error "go fmt failed" + exit 1 +fi + +# go vet +info "Running go vet..." +if ! go vet ./...; then + error "go vet failed" + exit 1 +fi + +# go lint +info "Running golangci-lint..." +if ! golangci-lint run; then + error "golangci-lint failed" + exit 1 +fi + +# go test +trap "rm coverage.out" EXIT +COVERAGE_THRESHOLD=70 + +go test -p 1 -coverprofile=coverage.out ./... + +COVERAGE=$(go tool cover -func=coverage.out | awk '/total:/ {print substr($3, 1, length($3)-1)}') + +info "Total test coverage: ${COVERAGE}%" + +if (( $(echo "$COVERAGE < $COVERAGE_THRESHOLD" | bc -l) )); then + error "Coverage below threshold: ${COVERAGE_THRESHOLD}%" + exit 1 +else + info "Coverage meets the threshold: ${COVERAGE_THRESHOLD}%" +fi \ No newline at end of file diff --git a/src/testtools_cli/generator/scaffold/golang/cmd/discover/discover.go b/src/testtools_cli/generator/scaffold/golang/cmd/discover/discover.go index 43f743d..0dddd49 100644 --- a/src/testtools_cli/generator/scaffold/golang/cmd/discover/discover.go +++ b/src/testtools_cli/generator/scaffold/golang/cmd/discover/discover.go @@ -77,7 +77,7 @@ func (o *DiscoverOptions) RunDiscover(cmd *cobra.Command) error { // config.ProjectPath: test cases root directory, example: /data/workspace // config.TaskId: task id, as the unique identifier for this task, example: task-xxx // config.FileReportPath: local test case result save file path, example: /data/report - time.Sleep(1) + time.Sleep(1 * time.Second) // 2. __TODO__: after loading the test cases, report the results. // successfully loaded test cases can be added to load_result.Tests diff --git a/src/testtools_cli/generator/scaffold/golang/cmd/execute/execute.go b/src/testtools_cli/generator/scaffold/golang/cmd/execute/execute.go index 15d5835..f217c4b 100644 --- a/src/testtools_cli/generator/scaffold/golang/cmd/execute/execute.go +++ b/src/testtools_cli/generator/scaffold/golang/cmd/execute/execute.go @@ -65,7 +65,7 @@ func (o *ExecuteOptions) RunExecute(cmd *cobra.Command) error { // config.ProjectPath: test cases root directory, example: /data/workspace // config.TaskId: task id, as the unique identifier for this task, example: task-xxx // config.FileReportPath: local test case result save file path, example: /data/report - time.Sleep(1) + time.Sleep(1 * time.Second) // 2. __TODO__: After test cases had been executed, construct the test case results and report. // TestResult: test case execution result diff --git a/src/testtools_cli/generator/scaffold/python/README.md b/src/testtools_cli/generator/scaffold/python/README.md index baa0610..eb33eee 100644 --- a/src/testtools_cli/generator/scaffold/python/README.md +++ b/src/testtools_cli/generator/scaffold/python/README.md @@ -1,5 +1,7 @@ -# {{ replace_____me }} +# replace_____me -## 执行要求 +## 注意事项 -- 测试镜像中python >= 3.9 +- 本项目基于`uv`管理依赖,具体安装方式请参考[uv](https://github.com/astral-sh/uv?tab=readme-ov-file#uv) +- 默认项目依赖python版本>=3.9 +- 调用`./check.sh`对代码进行静态检查并执行单测 diff --git a/src/testtools_cli/generator/scaffold/python/check.sh b/src/testtools_cli/generator/scaffold/python/check.sh old mode 100644 new mode 100755 index c485628..41b1c56 --- a/src/testtools_cli/generator/scaffold/python/check.sh +++ b/src/testtools_cli/generator/scaffold/python/check.sh @@ -9,4 +9,4 @@ uv run ruff check src uv run ruff check tests uv run mypy src --strict uv run pytest tests --durations=5 --cov=. --cov-fail-under=90 --cov-report term -uv export --no-dev --locked >requirements.txt \ No newline at end of file +uv export --no-dev --no-hashes --locked >requirements.txt \ No newline at end of file diff --git a/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/collector.py b/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/collector.py index ef71a5c..c2d0d6d 100644 --- a/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/collector.py +++ b/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/collector.py @@ -16,21 +16,21 @@ def collect_testcases(entry_param: EntryParam) -> None: ) # 1. __TODO__: load test cases based on `entry_param` # The following are the parameters that need attention: - # entry_param.TestSelectors: expected list of test cases to load, possibly with multiple inputs + # entry_param.TestSelectors: expected list of test cases to load, possibly with multiple inputs # example: # - tests // expected test case directory to be loaded # - tests/test_hello.py // expected test case file to be loaded # - tests/test_hello.py?name=MathTest // expected test case to be loaded # - tests/test_hello.py?MathTest/test_add // equivalent to the previous example, the 'name' parameter can be omitted # entry_param.ProjectPath: test cases root directory, example: /data/workspace - # entry_param.TaskId: task id, as the unique identifier for this task, example: task-xxx - # entry_param.FileReportPath: local test case result save file path, example: /data/report + # entry_param.TaskId: task id, as the unique identifier for this task, example: task-xxx + # entry_param.FileReportPath: local test case result save file path, example: /data/report time.sleep(1) - + # 2. __TODO__: after loading the test cases, report the results. # successfully loaded test cases can be added to load_result.Tests - # and failed test cases can be added to load_result.LoadErrors - # Tests: + # and failed test cases can be added to load_result.LoadErrors + # Tests: # [ # TestCase: single test case # Name: test case name, example: tests/test_hello.py?MathTest/test_add diff --git a/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/executor.py b/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/executor.py index 44725d6..d06917c 100644 --- a/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/executor.py +++ b/src/testtools_cli/generator/scaffold/python/src/testsolar_replace_____me/executor.py @@ -40,17 +40,17 @@ def run_single_case(case: TestCase, reporter: FileReporter) -> None: reporter.report_case_result(tr) # 2. __TODO__: execute test cases based on `entry_param` # The following are the parameters that need attention: - # entry_param.TestSelectors: expected list of test cases to execute, possibly with multiple inputs + # entry_param.TestSelectors: expected list of test cases to execute, possibly with multiple inputs # example: # - tests // expected test case directory to be executed # - tests/test_hello.py // expected test case file to be executed # - tests/test_hello.py?name=MathTest // expected test case to be executed # - tests/test_hello.py?MathTest/test_add // equivalent to the previous example, the 'name' parameter can be omitted # entry_param.ProjectPath: test cases root directory, example: /data/workspace - # entry_param.TaskId: task id, as the unique identifier for this task, example: task-xxx - # entry_param.FileReportPath: local test case result save file path, example: /data/report + # entry_param.TaskId: task id, as the unique identifier for this task, example: task-xxx + # entry_param.FileReportPath: local test case result save file path, example: /data/report sleep(1) - + # 3. __TODO__: After test cases had been executed, construct the test case results and report. # TestResult: test case execution result # Test: test case name @@ -59,16 +59,16 @@ def run_single_case(case: TestCase, reporter: FileReporter) -> None: # StartTime: test case start time # EndTime: test case end time # ResultType: execution result of the test case - # TestCaseStep: execution steps of the test case, - # one test case result can contain multiple steps, + # TestCaseStep: execution steps of the test case, + # one test case result can contain multiple steps, # and each step can contain multiple logs # Title: step name # Steps: test case logs in current step # [ # TestCaseStep: single test case log - # Time: record time + # Time: record time # Level: log level - # Content: log content + # Content: log content # ] # StartTime: step start time # EndTime: step end time diff --git a/uv.lock b/uv.lock index 1042aae..f1788d2 100644 --- a/uv.lock +++ b/uv.lock @@ -693,7 +693,7 @@ wheels = [ [[package]] name = "testtools-cli" -version = "0.2.17" +version = "0.2.18" source = { editable = "." } dependencies = [ { name = "pydantic-settings" }, From a320c95cad45caa8677c1e22cef04b4aba7dce08 Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Thu, 20 Mar 2025 15:12:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87utf-8?= =?UTF-8?q?=E5=AF=B9=E6=A8=A1=E7=89=88=E8=BF=9B=E8=A1=8C=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/testtools_cli/generator/template_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testtools_cli/generator/template_generator.py b/src/testtools_cli/generator/template_generator.py index 3ccb0f3..ce1e89c 100644 --- a/src/testtools_cli/generator/template_generator.py +++ b/src/testtools_cli/generator/template_generator.py @@ -6,7 +6,7 @@ def __init__(self, tool_name: str): self.tool_name = tool_name def render_template_path(self, template_path: Path) -> str: - with template_path.open() as f: + with template_path.open(encoding="utf-8") as f: return self.render_template(f.read()) def render_template(self, template_string: str) -> str: From c59219d99ae07eb3e7c662015c2b2f8b6c42fdb8 Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Thu, 20 Mar 2025 17:38:33 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=A5utf-8=E7=9A=84?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E6=96=B9=E5=BC=8F=E6=89=93=E5=BC=80=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- src/testtools_cli/debug/debugger.py | 2 +- uv.lock | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ee59451..b505810 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testtools-cli" -version = "0.2.18" +version = "0.2.19" description = "TestSolar TestTool CLI" authors = [ { name = "asiazhang", email = "asiazhang2002@gmail.com" }, diff --git a/src/testtools_cli/debug/debugger.py b/src/testtools_cli/debug/debugger.py index 4592e37..ea55367 100644 --- a/src/testtools_cli/debug/debugger.py +++ b/src/testtools_cli/debug/debugger.py @@ -40,7 +40,7 @@ def _generate_testcontainer_yaml(self) -> str: test_container.build = Build(commands=self._cmd) d = test_container.dict(by_alias=True, exclude_none=True) yaml_path = os.path.join(self._root, "testcontainer.yaml") - with open(yaml_path, "w") as f: + with open(yaml_path, "w", encoding="utf-8") as f: yaml.dump(d, f, default_flow_style=False) return yaml_path diff --git a/uv.lock b/uv.lock index f1788d2..c3d0513 100644 --- a/uv.lock +++ b/uv.lock @@ -1,4 +1,5 @@ version = 1 +revision = 1 requires-python = ">=3.9" resolution-markers = [ "python_full_version < '3.13'", @@ -97,7 +98,7 @@ name = "click" version = "8.1.7" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "colorama", marker = "platform_system == 'Windows'" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/96/d3/f04c7bfcf5c1862a2a5b845c6b2b360488cf47af55dfa79c98f6a6bf98b5/click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de", size = 336121 } wheels = [ @@ -362,8 +363,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b5/bf/798630923b67f4201059c2d690105998f20a6a8fb9b5ab68d221985155b3/pycryptodome-3.20.0-cp35-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:210ba1b647837bfc42dd5a813cdecb5b86193ae11a3f5d972b9a0ae2c7e9e4b4", size = 2155230 }, { url = "https://files.pythonhosted.org/packages/39/12/5fe7f5b9212dda9f5a26f842a324d6541fe1ca8059602124ff30db1e874b/pycryptodome-3.20.0-cp35-abi3-win32.whl", hash = "sha256:8d6b98d0d83d21fb757a182d52940d028564efe8147baa9ce0f38d057104ae72", size = 1723464 }, { url = "https://files.pythonhosted.org/packages/1f/90/d131c0eb643290230dfa4108b7c2d135122d88b714ad241d77beb4782a76/pycryptodome-3.20.0-cp35-abi3-win_amd64.whl", hash = "sha256:9b3ae153c89a480a0ec402e23db8d8d84a3833b65fa4b15b81b83be9d637aab9", size = 1759588 }, - { url = "https://files.pythonhosted.org/packages/17/87/c7153fcd400df0f4a67d7d92cdb6b5e43f309c22434374b8a61849dfb280/pycryptodome-3.20.0-pp27-pypy_73-manylinux2010_x86_64.whl", hash = "sha256:4401564ebf37dfde45d096974c7a159b52eeabd9969135f0426907db367a652a", size = 1639310 }, - { url = "https://files.pythonhosted.org/packages/68/9a/88d984405b087e8c8dd9a9d4c81a6fa675454e5fcf2ae01d9553b3128637/pycryptodome-3.20.0-pp27-pypy_73-win32.whl", hash = "sha256:ec1f93feb3bb93380ab0ebf8b859e8e5678c0f010d2d78367cf6bc30bfeb148e", size = 1708332 }, { url = "https://files.pythonhosted.org/packages/c7/10/88fb67d2fa545ce2ac61cfda70947bcbb1769f1956315c4b919d79774897/pycryptodome-3.20.0-pp310-pypy310_pp73-macosx_10_9_x86_64.whl", hash = "sha256:acae12b9ede49f38eb0ef76fdec2df2e94aad85ae46ec85be3648a57f0a7db04", size = 1565619 }, { url = "https://files.pythonhosted.org/packages/a2/40/63dff38fa4f7888f812263494d4a745eeed180ff09dd7b8350a81eb09d21/pycryptodome-3.20.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f47888542a0633baff535a04726948e876bf1ed880fddb7c10a736fa99146ab3", size = 1606403 }, { url = "https://files.pythonhosted.org/packages/8b/61/522235ca81d9dcfcf8b4cbc253b3a8a1f2231603d486369a8a02eb998f31/pycryptodome-3.20.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6e0e4a987d38cfc2e71b4a1b591bae4891eeabe5fa0f56154f576e26287bfdea", size = 1637284 }, @@ -693,7 +692,7 @@ wheels = [ [[package]] name = "testtools-cli" -version = "0.2.18" +version = "0.2.19" source = { editable = "." } dependencies = [ { name = "pydantic-settings" },