diff --git a/tests/__init__.py b/tests/__init__.py index e9466ea4..4c965300 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -19,6 +19,10 @@ from os import getenv, path +import cyclonedx + +CDX_SCHEMA_DIRECTORY = path.join(path.dirname(cyclonedx.__file__), 'schema') + FIXTURES_DIRECTORY = path.join(path.dirname(__file__), 'fixtures') RECREATE_SNAPSHOTS = bool(getenv('CDX_TEST_RECREATE_SNAPSHOTS')) diff --git a/tests/base.py b/tests/base.py index 35fcc3d6..76dee340 100644 --- a/tests/base.py +++ b/tests/base.py @@ -42,10 +42,11 @@ else: from importlib_metadata import version +from . import CDX_SCHEMA_DIRECTORY + cyclonedx_lib_name: str = 'cyclonedx-python-lib' cyclonedx_lib_version: str = version(cyclonedx_lib_name) single_uuid: str = 'urn:uuid:{}'.format(uuid4()) -schema_directory = os.path.join(os.path.dirname(__file__), '..', 'cyclonedx', 'schema') class BaseJsonTestCase(TestCase): @@ -53,7 +54,7 @@ class BaseJsonTestCase(TestCase): def assertValidAgainstSchema(self, bom_json: str, schema_version: SchemaVersion) -> None: if sys.version_info >= (3, 7): schema_fn = os.path.join( - schema_directory, + CDX_SCHEMA_DIRECTORY, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.schema.json' ) with open(schema_fn) as schema_fd: @@ -107,7 +108,7 @@ def assertEqualJsonBom(self, a: str, b: str) -> None: class BaseXmlTestCase(TestCase): def assertValidAgainstSchema(self, bom_xml: str, schema_version: SchemaVersion) -> None: - xsd_fn = os.path.join(schema_directory, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.xsd') + xsd_fn = os.path.join(CDX_SCHEMA_DIRECTORY, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.xsd') with open(xsd_fn) as xsd_fd: xsd_doc = etree.parse(xsd_fd) diff --git a/tests/test_spdx.py b/tests/test_spdx.py index 6395f86d..ff4c951b 100644 --- a/tests/test_spdx.py +++ b/tests/test_spdx.py @@ -19,14 +19,16 @@ from itertools import chain from json import load as json_load -from os.path import dirname, join as path_join +from os.path import join as path_join from unittest import TestCase from ddt import data, ddt, idata, unpack from cyclonedx import spdx -with open(path_join(dirname(__file__), '..', 'cyclonedx', 'schema', 'spdx.schema.json')) as spdx_schema: +from . import CDX_SCHEMA_DIRECTORY + +with open(path_join(CDX_SCHEMA_DIRECTORY, 'spdx.schema.json')) as spdx_schema: KNOWN_SPDX_IDS = json_load(spdx_schema)['enum'] VALID_COMPOUND_EXPRESSIONS = {