Skip to content

Commit 1f0c05f

Browse files
authored
fix: mak test's schema paths relative to cyclonedx package (#338)
Signed-off-by: Jan Kowalleck <[email protected]> Signed-off-by: Jan Kowalleck <[email protected]>
1 parent b7f1028 commit 1f0c05f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

tests/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
from os import getenv, path
2121

22+
import cyclonedx
23+
24+
CDX_SCHEMA_DIRECTORY = path.join(path.dirname(cyclonedx.__file__), 'schema')
25+
2226
FIXTURES_DIRECTORY = path.join(path.dirname(__file__), 'fixtures')
2327

2428
RECREATE_SNAPSHOTS = bool(getenv('CDX_TEST_RECREATE_SNAPSHOTS'))

tests/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,19 @@
4242
else:
4343
from importlib_metadata import version
4444

45+
from . import CDX_SCHEMA_DIRECTORY
46+
4547
cyclonedx_lib_name: str = 'cyclonedx-python-lib'
4648
cyclonedx_lib_version: str = version(cyclonedx_lib_name)
4749
single_uuid: str = 'urn:uuid:{}'.format(uuid4())
48-
schema_directory = os.path.join(os.path.dirname(__file__), '..', 'cyclonedx', 'schema')
4950

5051

5152
class BaseJsonTestCase(TestCase):
5253

5354
def assertValidAgainstSchema(self, bom_json: str, schema_version: SchemaVersion) -> None:
5455
if sys.version_info >= (3, 7):
5556
schema_fn = os.path.join(
56-
schema_directory,
57+
CDX_SCHEMA_DIRECTORY,
5758
f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.schema.json'
5859
)
5960
with open(schema_fn) as schema_fd:
@@ -107,7 +108,7 @@ def assertEqualJsonBom(self, a: str, b: str) -> None:
107108
class BaseXmlTestCase(TestCase):
108109

109110
def assertValidAgainstSchema(self, bom_xml: str, schema_version: SchemaVersion) -> None:
110-
xsd_fn = os.path.join(schema_directory, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.xsd')
111+
xsd_fn = os.path.join(CDX_SCHEMA_DIRECTORY, f'bom-{schema_version.name.replace("_", ".").replace("V", "")}.xsd')
111112
with open(xsd_fn) as xsd_fd:
112113
xsd_doc = etree.parse(xsd_fd)
113114

tests/test_spdx.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
from itertools import chain
2121
from json import load as json_load
22-
from os.path import dirname, join as path_join
22+
from os.path import join as path_join
2323
from unittest import TestCase
2424

2525
from ddt import data, ddt, idata, unpack
2626

2727
from cyclonedx import spdx
2828

29-
with open(path_join(dirname(__file__), '..', 'cyclonedx', 'schema', 'spdx.schema.json')) as spdx_schema:
29+
from . import CDX_SCHEMA_DIRECTORY
30+
31+
with open(path_join(CDX_SCHEMA_DIRECTORY, 'spdx.schema.json')) as spdx_schema:
3032
KNOWN_SPDX_IDS = json_load(spdx_schema)['enum']
3133

3234
VALID_COMPOUND_EXPRESSIONS = {

0 commit comments

Comments
 (0)