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

tests: meaningful names to validation tests #588

Merged
merged 1 commit into from
Apr 12, 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
11 changes: 9 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# Copyright (c) OWASP Foundation. All Rights Reserved.
import re
from os import getenv, path
from os.path import join
from typing import TYPE_CHECKING, Any, Generator, Iterable, List, Optional, TypeVar, Union
from os.path import basename, join, splitext
from typing import TYPE_CHECKING, Any, Generator, Iterable, List, Optional, Tuple, TypeVar, Union
from unittest import TestCase
from uuid import UUID

Expand Down Expand Up @@ -183,3 +183,10 @@ def is_valid_for_schema_version(purpose: Union[Any], sv: SchemaVersion) -> bool:

def mksname(purpose: Union[Any], sv: SchemaVersion, f: OutputFormat) -> str:
return f'{_get_purpose_as_str(purpose)}-{sv.to_version()}.{_SNAME_EXT[f]}'


class DpTuple(Tuple[SchemaVersion, str]):
@property
def __name__(self) -> str:
schema_version, test_data_file = self
return f'{schema_version.to_version()}-{splitext(basename(test_data_file))[0]}'
4 changes: 2 additions & 2 deletions tests/test_validation_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
from cyclonedx.exception import MissingOptionalDependencyException
from cyclonedx.schema import OutputFormat, SchemaVersion
from cyclonedx.validation.json import JsonStrictValidator, JsonValidator
from tests import SCHEMA_TESTDATA_DIRECTORY
from tests import SCHEMA_TESTDATA_DIRECTORY, DpTuple

UNSUPPORTED_SCHEMA_VERSIONS = {SchemaVersion.V1_0, SchemaVersion.V1_1, }


def _dp(prefix: str) -> Generator:
return (
(sv, tf) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
DpTuple((sv, tf)) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
for tf in iglob(join(SCHEMA_TESTDATA_DIRECTORY, sv.to_version(), f'{prefix}-*.json'))
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_validation_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
from cyclonedx.exception import MissingOptionalDependencyException
from cyclonedx.schema import OutputFormat, SchemaVersion
from cyclonedx.validation.xml import XmlValidator
from tests import SCHEMA_TESTDATA_DIRECTORY
from tests import SCHEMA_TESTDATA_DIRECTORY, DpTuple

UNSUPPORTED_SCHEMA_VERSIONS = set()


def _dp(prefix: str) -> Generator:
return (
(sv, tf) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
DpTuple((sv, tf)) for sv in SchemaVersion if sv not in UNSUPPORTED_SCHEMA_VERSIONS
for tf in iglob(join(SCHEMA_TESTDATA_DIRECTORY, sv.to_version(), f'{prefix}-*.xml'))
)

Expand Down
Loading