Skip to content

Commit f5fdfb6

Browse files
committed
test for validation is optional
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent cea377c commit f5fdfb6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

tests/test_output_json.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

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

24-
from cyclonedx.exception import CycloneDxException
24+
from cyclonedx.exception import CycloneDxException, MissingOptionalDependencyException
2525
from cyclonedx.exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
2626
from cyclonedx.exception.output import FormatNotSupportedException
2727
from cyclonedx.model.bom import Bom
@@ -31,7 +31,7 @@
3131
from tests import SnapshotMixin, mksname, uuid_generator
3232
from tests._data.models import all_get_bom_funct_invalid, all_get_bom_funct_valid
3333

34-
UNSUPPORTED_SV = frozenset((SchemaVersion.V1_1, SchemaVersion.V1_0, ))
34+
UNSUPPORTED_SV = frozenset((SchemaVersion.V1_1, SchemaVersion.V1_0,))
3535

3636

3737
@ddt
@@ -56,7 +56,10 @@ def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **_
5656
snapshot_name = mksname(get_bom, sv, OutputFormat.JSON)
5757
bom = get_bom()
5858
json = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
59-
errors = JsonStrictValidator(sv).validate_str(json)
59+
try:
60+
errors = JsonStrictValidator(sv).validate_str(json)
61+
except MissingOptionalDependencyException:
62+
errors = None # skipped validation
6063
self.assertIsNone(errors)
6164
self.assertEqualSnapshot(json, snapshot_name)
6265

tests/test_output_xml.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from ddt import ddt, idata, named_data, unpack
2424

25-
from cyclonedx.exception import CycloneDxException
25+
from cyclonedx.exception import CycloneDxException, MissingOptionalDependencyException
2626
from cyclonedx.exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
2727
from cyclonedx.model.bom import Bom
2828
from cyclonedx.output.xml import BY_SCHEMA_VERSION, Xml
@@ -45,7 +45,10 @@ def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **_
4545
snapshot_name = mksname(get_bom, sv, OutputFormat.XML)
4646
bom = get_bom()
4747
xml = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
48-
errors = XmlValidator(sv).validate_str(xml)
48+
try:
49+
errors = XmlValidator(sv).validate_str(xml)
50+
except MissingOptionalDependencyException:
51+
errors = None # skipped validation
4952
self.assertIsNone(errors)
5053
self.assertEqualSnapshot(xml, snapshot_name)
5154

0 commit comments

Comments
 (0)