Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type safeness (#9) #12

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT

name: Lint
run-name: Linting code
run-name: Linting code and type checking

on:
push:
Expand Down Expand Up @@ -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 .
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_

Expand Down
12 changes: 6 additions & 6 deletions config/license/allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.4",
"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.4/LICENSE",
"moduleCopyright": "",
"actualLicense": "Apache-2.0",
"violationAllowance": ""
Expand Down Expand Up @@ -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": ""
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion testguide_report_generator/ReportGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
28 changes: 14 additions & 14 deletions testguide_report_generator/model/TestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
5 changes: 3 additions & 2 deletions testguide_report_generator/model/TestCaseFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions testguide_report_generator/model/TestSuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
"""
Expand All @@ -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<testguide_report_generator.Json2AtxRepr>`
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
3 changes: 3 additions & 0 deletions tests/e2e/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
7 changes: 7 additions & 0 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions tests/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
3 changes: 3 additions & 0 deletions tests/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2023-2024 tracetronic GmbH
#
# SPDX-License-Identifier: MIT
Loading