Skip to content

Commit

Permalink
test for validation is optional
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Oct 8, 2023
1 parent cea377c commit f5fdfb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions tests/test_output_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from ddt import data, ddt, idata, named_data, unpack

from cyclonedx.exception import CycloneDxException
from cyclonedx.exception import CycloneDxException, MissingOptionalDependencyException
from cyclonedx.exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
from cyclonedx.exception.output import FormatNotSupportedException
from cyclonedx.model.bom import Bom
Expand All @@ -31,7 +31,7 @@
from tests import SnapshotMixin, mksname, uuid_generator
from tests._data.models import all_get_bom_funct_invalid, all_get_bom_funct_valid

UNSUPPORTED_SV = frozenset((SchemaVersion.V1_1, SchemaVersion.V1_0, ))
UNSUPPORTED_SV = frozenset((SchemaVersion.V1_1, SchemaVersion.V1_0,))


@ddt
Expand All @@ -56,7 +56,10 @@ def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **_
snapshot_name = mksname(get_bom, sv, OutputFormat.JSON)
bom = get_bom()
json = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
errors = JsonStrictValidator(sv).validate_str(json)
try:
errors = JsonStrictValidator(sv).validate_str(json)
except MissingOptionalDependencyException:
errors = None # skipped validation
self.assertIsNone(errors)
self.assertEqualSnapshot(json, snapshot_name)

Expand Down
7 changes: 5 additions & 2 deletions tests/test_output_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ddt import ddt, idata, named_data, unpack

from cyclonedx.exception import CycloneDxException
from cyclonedx.exception import CycloneDxException, MissingOptionalDependencyException
from cyclonedx.exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
from cyclonedx.model.bom import Bom
from cyclonedx.output.xml import BY_SCHEMA_VERSION, Xml
Expand All @@ -45,7 +45,10 @@ def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **_
snapshot_name = mksname(get_bom, sv, OutputFormat.XML)
bom = get_bom()
xml = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
errors = XmlValidator(sv).validate_str(xml)
try:
errors = XmlValidator(sv).validate_str(xml)
except MissingOptionalDependencyException:
errors = None # skipped validation
self.assertIsNone(errors)
self.assertEqualSnapshot(xml, snapshot_name)

Expand Down

0 comments on commit f5fdfb6

Please sign in to comment.