| | |
| | |
| | |
| | |
| | |
| | |
| | from __future__ import annotations |
| |
|
| | import nox |
| |
|
| | PREFIX_TESTS_FUNCTIONAL = "tests/functional" |
| | PREFIX_TESTS_UNIT = "tests/unit" |
| |
|
| |
|
| | def build_and_run_test(session: nox.Session, folders: list, extras: str = "") -> None: |
| | """ |
| | This function is responsible for setting up the testing environment and running the test suite for specific feature. |
| | |
| | The function performs the following tasks: |
| | 1. Installs the required dependencies for executing any test |
| | 2. If the `extras` parameter is provided, the function installs the additional dependencies |
| | 3. the function runs the pytest command with the specified folders as arguments, executing the test suite. |
| | |
| | Parameters |
| | ---------- |
| | session: nox.Session |
| | The current Nox session object, which is used to manage the virtual environment and execute commands. |
| | folders: List |
| | A list of folder paths that contain the test files to be executed. |
| | extras: Optional[str] |
| | A string representing additional dependencies that should be installed for the test environment. |
| | If not provided, the function will install the project with basic dependencies |
| | """ |
| |
|
| | |
| | session.install("poetry", "pytest", "pytest-mock", "pytest_socket") |
| |
|
| | |
| | if extras: |
| | session.install(f"./[{extras}]") |
| | else: |
| | session.install("./") |
| |
|
| | |
| | session.run("pytest", *folders) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_only_required_packages(session: nox.Session): |
| | """Tests that only depends for required libraries""" |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/logger/required_dependencies/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/metrics/required_dependencies/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/required_dependencies/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/typing/required_dependencies/", |
| | f"{PREFIX_TESTS_UNIT}/data_classes/required_dependencies/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/event_handler/required_dependencies/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/batch/required_dependencies/", |
| | ], |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_datadog_as_required_package(session: nox.Session): |
| | """Tests that depends on Datadog library""" |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/metrics/datadog/", |
| | ], |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_xray_sdk_as_required_package(session: nox.Session): |
| | """Tests that depends on AWS XRAY SDK library""" |
| | |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/tracer/_aws_xray_sdk/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/middleware_factory/_aws_xray_sdk/", |
| | ], |
| | extras="tracer", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_boto3_sdk_as_required_package(session: nox.Session): |
| | """Tests that depends on boto3/botocore library""" |
| | |
| | |
| | |
| | |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/parameters/_boto3/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/feature_flags/_boto3/", |
| | f"{PREFIX_TESTS_UNIT}/data_classes/_boto3/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/streaming/_boto3/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/idempotency/_boto3/", |
| | ], |
| | extras="aws-sdk", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_fastjsonschema_as_required_package(session: nox.Session): |
| | """Tests that depends on fastjsonschema library""" |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/validator/_fastjsonschema/", |
| | ], |
| | extras="validation", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_aws_encryption_sdk_as_required_package(session: nox.Session): |
| | """Tests that depends on aws_encryption_sdk library""" |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/data_masking/_aws_encryption_sdk/", |
| | f"{PREFIX_TESTS_UNIT}/data_masking/_aws_encryption_sdk/", |
| | ], |
| | extras="datamasking", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_pydantic_required_package(session: nox.Session): |
| | """Tests that only depends for Pydantic library v2""" |
| | |
| | |
| | |
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/event_handler/_pydantic/", |
| | f"{PREFIX_TESTS_FUNCTIONAL}/batch/_pydantic/", |
| | f"{PREFIX_TESTS_UNIT}/parser/_pydantic/", |
| | f"{PREFIX_TESTS_UNIT}/event_handler/_pydantic/", |
| | ], |
| | extras="parser", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_boto3_and_pydantic_required_package(session: nox.Session): |
| | """Tests that only depends for Boto3 + Pydantic library v2""" |
| | |
| |
|
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/idempotency/_pydantic/", |
| | ], |
| | extras="aws-sdk,parser", |
| | ) |
| |
|
| |
|
| | @nox.session() |
| | def test_with_redis_and_boto3_sdk_as_required_package(session: nox.Session): |
| | """Tests that depends on Redis library""" |
| | |
| |
|
| | |
| | session.run("pip", "install", "multiprocess") |
| |
|
| | build_and_run_test( |
| | session, |
| | folders=[ |
| | f"{PREFIX_TESTS_FUNCTIONAL}/idempotency/_redis/", |
| | ], |
| | extras="redis,aws-sdk", |
| | ) |
| |
|