From 7b25e57cb380b0491b5d2f0759e28a554ad3a70a Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Wed, 21 Aug 2024 15:03:11 +0200 Subject: [PATCH 1/5] Provide type safeness (#9) --- conftest.py | 2 +- pyproject.toml | 4 +++ testguide_report_generator/ReportGenerator.py | 1 - testguide_report_generator/model/TestCase.py | 28 +++++++++---------- .../model/TestCaseFolder.py | 5 ++-- testguide_report_generator/model/TestSuite.py | 6 ++-- tests/__init__.py | 0 tests/e2e/__init__.py | 0 tests/e2e/test_e2e.py | 7 +++++ tests/model/__init__.py | 0 10 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/e2e/__init__.py create mode 100644 tests/model/__init__.py diff --git a/conftest.py b/conftest.py index 86e0363..6bb56ec 100644 --- a/conftest.py +++ b/conftest.py @@ -242,7 +242,7 @@ def value_storage(): class ValueStorage: def __init__(self) -> None: - self.e2e_atxid = None + self.e2e_atxid: str | None = None self.remote_testcases_json = None self.BASE_URL = os.getenv("TEST_GUIDE_URL") self.AUTHKEY = os.getenv("TEST_GUIDE_AUTHKEY") diff --git a/pyproject.toml b/pyproject.toml index 984ed9d..ccf4015 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,10 @@ pytest-cov = "==4.0.0" pylint = "==3.1.0" cyclonedx-bom = "==3.8.0" jsonschema = "==4.16.0" +types-jsonschema = "^4.21.0.20240331" +types-toml = "^0.10.8.20240310" +types-requests = "^2.31.0.20240406" +mypy = "^1.5.1" [tool.poetry.group.docs.dependencies] sphinx = "^5.3.0" diff --git a/testguide_report_generator/ReportGenerator.py b/testguide_report_generator/ReportGenerator.py index c2c3be7..9770387 100644 --- a/testguide_report_generator/ReportGenerator.py +++ b/testguide_report_generator/ReportGenerator.py @@ -30,7 +30,6 @@ class Generator: please conduct the README. """ - __testsuite = None def __init__(self, testsuite: TestSuite, json_schema_path: str = DEFAULT_JSON_SCHEMA_PATH): """ diff --git a/testguide_report_generator/model/TestCase.py b/testguide_report_generator/model/TestCase.py index 7081b37..1d1bde3 100644 --- a/testguide_report_generator/model/TestCase.py +++ b/testguide_report_generator/model/TestCase.py @@ -295,10 +295,10 @@ def __init__(self, name: str, verdict: Verdict, expected_result: str = ''): if not isinstance(verdict, Verdict): raise TypeError("Argument 'verdict' must be of type 'Verdict'.") - self.__description = None + self.__description: str | None = None self.__verdict = verdict self.__expected_result = expected_result - self.__artifacts = [] + self.__artifacts: list[Artifact] = [] def set_description(self, desc: str): """ @@ -377,8 +377,8 @@ def __init__(self, name: str): :type name: str """ self.__name = check_name_length(name, gen_error_msg("TestStepFolder", name)) - self.__description = None - self.__teststeps = [] + self.__description: str | None = None + self.__teststeps: list[Union[TestStep, TestStepFolder]] = [] def set_description(self, desc: str): """ @@ -458,21 +458,21 @@ def __init__(self, name: str, timestamp: int, verdict: Verdict): self.__verdict = verdict self.__execution_time = 0 - self.__description = None + self.__description: str | None = None - self.__setup_teststeps = [] - self.__execution_teststeps = [] - self.__teardown_teststeps = [] + self.__setup_teststeps: list[Union[TestStep, TestStepFolder]] = [] + self.__execution_teststeps: list[Union[TestStep, TestStepFolder]] = [] + self.__teardown_teststeps: list[Union[TestStep, TestStepFolder]] = [] - self.__param_set = None - self.__parameters = [] + self.__param_set: str | None = None + self.__parameters: list[Parameter] = [] - self.__attributes = [] - self.__constants = [] + self.__attributes: list[Attribute] = [] + self.__constants: list[Constant] = [] - self.__artifacts = [] + self.__artifacts: list[Artifact] = [] - self.__review = None + self.__review: Review | None = None def set_description(self, desc: str): """ diff --git a/testguide_report_generator/model/TestCaseFolder.py b/testguide_report_generator/model/TestCaseFolder.py index 9dcfce0..f3ec928 100644 --- a/testguide_report_generator/model/TestCaseFolder.py +++ b/testguide_report_generator/model/TestCaseFolder.py @@ -8,6 +8,7 @@ This module contains the TestCaseFolder class. """ +from typing_extensions import Self from testguide_report_generator.model.TestCase import TestCase from testguide_report_generator.util.Json2AtxRepr import Json2AtxRepr from testguide_report_generator.util.ValidityChecks import check_name_length, gen_error_msg, \ @@ -32,9 +33,9 @@ def __init__(self, name: str): :type name: str """ self.__name = check_name_length(name, gen_error_msg("TestCaseFolder", name)) - self.__testcases = [] + self.__testcases: list[TestCase | TestCaseFolder] = [] - def add_testcase(self, testcase): + def add_testcase(self, testcase: TestCase | Self) -> Self: # pylint: disable=R0801 """ Adds a TestCase or TestCaseFolder to the testcase folder. diff --git a/testguide_report_generator/model/TestSuite.py b/testguide_report_generator/model/TestSuite.py index 7088121..9415596 100644 --- a/testguide_report_generator/model/TestSuite.py +++ b/testguide_report_generator/model/TestSuite.py @@ -37,7 +37,7 @@ def __init__(self, name: str, timestamp: int): """ self.__name = check_name_length(name, self.NAME_ERROR_MSG) self.__timestamp = timestamp - self.__testcases = [] + self.__testcases: list[Union[TestCase, TestCaseFolder]] = [] def add_testcase(self, testcase: Union[TestCase, TestCaseFolder]): """ @@ -54,14 +54,14 @@ def add_testcase(self, testcase: Union[TestCase, TestCaseFolder]): self.__testcases.append(testcase) return self - def get_testcases(self): + def get_testcases(self) -> list: """ :return: Testcases or TestCaseFolders :rtype: list """ return self.__testcases - def create_json_repr(self): + def create_json_repr(self) -> dict: """ @see: :class:`Json2AtxRepr` """ diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/e2e/__init__.py b/tests/e2e/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/e2e/test_e2e.py b/tests/e2e/test_e2e.py index 30d4b4f..0d44ec9 100644 --- a/tests/e2e/test_e2e.py +++ b/tests/e2e/test_e2e.py @@ -21,6 +21,9 @@ def test_upload(value_storage: ValueStorage): assert os.path.exists("e2e.json") assert os.path.exists("e2e.zip") + if value_storage.BASE_URL is None: + raise ValueError("BASE_URL in value_storage cannot be None.") + upload_url = value_storage.BASE_URL + "api/upload-file" params = { "projectId": value_storage.PROJECT_ID, @@ -55,6 +58,10 @@ def test_download(value_storage: ValueStorage): """ Test downloads data from test.guide """ + + if value_storage.BASE_URL is None: + raise ValueError("BASE_URL in value_storage cannot be None.") + query_url = value_storage.BASE_URL + "api/report/testCaseExecutions/filter" params = {"projectId": value_storage.PROJECT_ID, "offset": 0, "limit": 100, "authKey": value_storage.AUTHKEY} filter = { diff --git a/tests/model/__init__.py b/tests/model/__init__.py new file mode 100644 index 0000000..e69de29 From 10b0ff31e4e264103f0e833a052a8cdc4b6db518 Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Wed, 21 Aug 2024 15:04:02 +0200 Subject: [PATCH 2/5] Extend github workflow (#9) --- .github/workflows/lint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 12820e9..ef57401 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT name: Lint -run-name: Linting code +run-name: Linting code and type checking on: push: @@ -31,3 +31,5 @@ jobs: run: poetry install --without workflow --no-root - name: Execute Linting run: poetry run pylint --rcfile default.pylintrc testguide_report_generator + - name: Execute Type Checking + run: poetry run mypy . From 6e033c77b41e15fab4b5276d2d9129464eaa7b3e Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Thu, 22 Aug 2024 08:55:59 +0200 Subject: [PATCH 3/5] Fix allowlist and extend README (#9) --- README.md | 32 ++++++++++++++++---------------- config/license/allowlist.json | 12 ++++++------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 2f0f8dc..9774f4f 100644 --- a/README.md +++ b/README.md @@ -111,22 +111,22 @@ A more extensive example is given in [example_TestSuite.py](example_TestSuite.py ### Available classes and their purpose -| Class | Arguments | Description | -|----------------------------------------------------------------------|----------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| -| [TestStep](testguide_report_generator/model/TestCase.py) | name, verdict, (expected result) | a fundamental teststep, is added to TestCase or TestStepFolder | -| [TestStepArtifact](testguide_report_generator/model/TestCase.py) | filepath, type | artifact which gets attached directly to a teststep (such as plots) | -| [TestStepArtifactType](testguide_report_generator/model/TestCase.py) | | the type of a teststep artifact (only used with TestStepArtifact) | -| [TestStepFolder](testguide_report_generator/model/TestCase.py) | name | contains teststeps or teststep folders, is added to TestCase | -| [TestCase](testguide_report_generator/model/TestCase.py) | name, timestamp, verdict | a testcase, may contain teststeps or teststep folders, as well as further specific elements; is added to TestCaseFolder or TestSuite | -| [TestCaseFolder](testguide_report_generator/model/TestCaseFolder.py) | name | contains testcases or testcase folders, is added to TestSuite or TestCaseFolder | -| [TestSuite](testguide_report_generator/model/TestSuite.py) | name, timestamp | the testsuite, may contain TestCases or TestCaseFolder | -| [Verdict](testguide_report_generator/model/TestCase.py) | | the verdict of the test object | -| [Artifact](testguide_report_generator/model/TestCase.py) | filepath | an optional artifact to an existing filepath, can be added to TestCase | -| [Parameter](testguide_report_generator/model/TestCase.py) | name, value, direction | a testcase parameter, can be added to TestCase | -| [Direction](testguide_report_generator/model/TestCase.py) | | direction of a Parameter (only used with Parameter) | -| [Constant](testguide_report_generator/model/TestCase.py) | key, value | a test constant, can be added to TestCase | -| [Attribute](testguide_report_generator/model/TestCase.py) | key, value | a test attribute, can be added to TestCase | -| [Review](testguide_report_generator/model/TestCase.py) | comment, author, timestamp | review, can be added to TestCase | +| Class | Arguments | Description | +|----------------------------------------------------------------------|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------| +| [TestStep](testguide_report_generator/model/TestCase.py) | name of `type string`, verdict of `type Verdict`, (expected result of `type string`) | a fundamental teststep, is added to TestCase or TestStepFolder | +| [TestStepArtifact](testguide_report_generator/model/TestCase.py) | filepath of `type string`, type of `type TestStepArtifactType` | artifact which gets attached directly to a teststep (such as plots) | +| [TestStepArtifactType](testguide_report_generator/model/TestCase.py) | | the type of a teststep artifact (only used with TestStepArtifact) | +| [TestStepFolder](testguide_report_generator/model/TestCase.py) | name of `type string` | contains teststeps or teststep folders, is added to TestCase | +| [TestCase](testguide_report_generator/model/TestCase.py) | name of `type string`, timestamp of `type int`, verdict of `type Verdict` | a testcase, may contain teststeps or teststep folders, as well as further specific elements; is added to TestCaseFolder or TestSuite | +| [TestCaseFolder](testguide_report_generator/model/TestCaseFolder.py) | name of `type string` | contains testcases or testcase folders, is added to TestSuite or TestCaseFolder | +| [TestSuite](testguide_report_generator/model/TestSuite.py) | name of `type string`, timestamp of `type int` | the testsuite, may contain TestCases or TestCaseFolder | +| [Verdict](testguide_report_generator/model/TestCase.py) | | the verdict of the test object | +| [Artifact](testguide_report_generator/model/TestCase.py) | filepath of `type string` | an optional artifact to an existing filepath, can be added to TestCase | +| [Parameter](testguide_report_generator/model/TestCase.py) | name of `type string`, value of `type string or int`, direction of `type Direction` | a testcase parameter, can be added to TestCase | +| [Direction](testguide_report_generator/model/TestCase.py) | | direction of a Parameter (only used with Parameter) | +| [Constant](testguide_report_generator/model/TestCase.py) | key of `type string`, value of `type string` | a test constant, can be added to TestCase | +| [Attribute](testguide_report_generator/model/TestCase.py) | key of `type string`, value of `type string` | a test attribute, can be added to TestCase | +| [Review](testguide_report_generator/model/TestCase.py) | comment of `type string`, author of `type string`, timestamp of `type int` | review, can be added to TestCase | * (): arguments in parentheses are _optional_ diff --git a/config/license/allowlist.json b/config/license/allowlist.json index 80ff5ba..6366c37 100644 --- a/config/license/allowlist.json +++ b/config/license/allowlist.json @@ -2,18 +2,18 @@ "allowedLicenses": [ { "moduleLicense": "MIT", - "moduleVersion": "23.2.0", + "moduleVersion": "24.2.0", "moduleName": "attrs", - "licenseUrl": "https://github.com/python-attrs/attrs/blob/23.2.0/LICENSE", + "licenseUrl": "https://github.com/python-attrs/attrs/blob/24.2.0/LICENSE", "moduleCopyright": "Copyright (c) 2015 Hynek Schlawack and the attrs contributors", "actualLicense": "MIT", "violationAllowance": "" }, { "moduleLicense": "Apache-2.0", - "moduleVersion": "6.4.0", + "moduleVersion": "6.4.3", "moduleName": "importlib-resources", - "licenseUrl": "https://github.com/python/importlib_resources/blob/v6.4.0/LICENSE", + "licenseUrl": "https://github.com/python/importlib_resources/blob/v6.4.3/LICENSE", "moduleCopyright": "", "actualLicense": "Apache-2.0", "violationAllowance": "" @@ -47,9 +47,9 @@ }, { "moduleLicense": "MIT", - "moduleVersion": "3.18.1", + "moduleVersion": "3.20.0", "moduleName": "zipp", - "licenseUrl": "https://github.com/jaraco/zipp/blob/v3.18.1/LICENSE", + "licenseUrl": "https://github.com/jaraco/zipp/blob/v3.20.0/LICENSE", "moduleCopyright": "", "actualLicense": "MIT", "violationAllowance": "" From ac3aeb5bea912b0f663ec5f4ecf1be6a85e666cb Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Thu, 22 Aug 2024 09:06:36 +0200 Subject: [PATCH 4/5] Adjust moduleVersion in allowlist (#9) --- config/license/allowlist.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/license/allowlist.json b/config/license/allowlist.json index 6366c37..0057ada 100644 --- a/config/license/allowlist.json +++ b/config/license/allowlist.json @@ -11,9 +11,9 @@ }, { "moduleLicense": "Apache-2.0", - "moduleVersion": "6.4.3", + "moduleVersion": "6.4.4", "moduleName": "importlib-resources", - "licenseUrl": "https://github.com/python/importlib_resources/blob/v6.4.3/LICENSE", + "licenseUrl": "https://github.com/python/importlib_resources/blob/v6.4.4/LICENSE", "moduleCopyright": "", "actualLicense": "Apache-2.0", "violationAllowance": "" From ef1f47c4ac742d7b06adab6cd8fe406f31cf3b78 Mon Sep 17 00:00:00 2001 From: Mario Fuchs Date: Thu, 22 Aug 2024 09:30:35 +0200 Subject: [PATCH 5/5] Provide copyright information in init files (#9) --- tests/__init__.py | 3 +++ tests/e2e/__init__.py | 3 +++ tests/model/__init__.py | 3 +++ tests/util/__init__.py | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 tests/util/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..f7e1150 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2023-2024 tracetronic GmbH +# +# SPDX-License-Identifier: MIT diff --git a/tests/e2e/__init__.py b/tests/e2e/__init__.py index e69de29..f7e1150 100644 --- a/tests/e2e/__init__.py +++ b/tests/e2e/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2023-2024 tracetronic GmbH +# +# SPDX-License-Identifier: MIT diff --git a/tests/model/__init__.py b/tests/model/__init__.py index e69de29..f7e1150 100644 --- a/tests/model/__init__.py +++ b/tests/model/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2023-2024 tracetronic GmbH +# +# SPDX-License-Identifier: MIT diff --git a/tests/util/__init__.py b/tests/util/__init__.py new file mode 100644 index 0000000..f7e1150 --- /dev/null +++ b/tests/util/__init__.py @@ -0,0 +1,3 @@ +# Copyright (c) 2023-2024 tracetronic GmbH +# +# SPDX-License-Identifier: MIT