Skip to content

Commit

Permalink
fix: mak test's schema paths relative to cyclonedx package (#338)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck authored Jan 12, 2023
1 parent b7f1028 commit 1f0c05f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
7 changes: 4 additions & 3 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@
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):

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:
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_spdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 1f0c05f

Please sign in to comment.