Skip to content

Commit 7186b52

Browse files
committed
tests: use internal json strict validation
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 839fe11 commit 7186b52

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

tests/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from cyclonedx.exception import MissingOptionalDependencyException
3232
from cyclonedx.output import SchemaVersion
33-
from cyclonedx.validation.json import JsonValidator
33+
from cyclonedx.validation.json import JsonStrictValidator
3434
from cyclonedx.validation.xml import XmlValidator
3535

3636
single_uuid: str = 'urn:uuid:{}'.format(uuid4())
@@ -40,7 +40,7 @@ class BaseJsonTestCase(TestCase):
4040

4141
def assertValidAgainstSchema(self, bom_json: str, schema_version: SchemaVersion) -> None:
4242
try:
43-
validation_error = JsonValidator(schema_version).validate_str(bom_json)
43+
validation_error = JsonStrictValidator(schema_version).validate_str(bom_json)
4444
except MissingOptionalDependencyException:
4545
return # some deps are missing - skip the validation
4646
self.assertIsNone(validation_error,

tests/test_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:
4949
@unpack
5050
def test_fails_on_wrong_args(self, of: OutputFormat, sv: SchemaVersion, raisesRegex: Tuple) -> None:
5151
bom = Mock(spec=Bom)
52-
with self.assertRaisesRegexp(*raisesRegex):
52+
with self.assertRaisesRegex(*raisesRegex):
5353
get_outputter(bom, of, sv)

tests/test_validation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
from cyclonedx.schema import OutputFormat, SchemaVersion
2828
from cyclonedx.validation import get_instance as get_validator
2929

30-
UndefinedFormatVersion = {(OutputFormat.JSON, SchemaVersion.V1_1), (OutputFormat.JSON, SchemaVersion.V1_0), }
30+
UNDEFINED_FORMAT_VERSION = {
31+
(OutputFormat.JSON, SchemaVersion.V1_1),
32+
(OutputFormat.JSON, SchemaVersion.V1_0),
33+
}
3134

3235

3336
@ddt
@@ -36,7 +39,7 @@ class TestGetInstance(TestCase):
3639
@named_data(*([f'{f.name} {v.name}', f, v]
3740
for f, v
3841
in product(OutputFormat, SchemaVersion)
39-
if (f, v) not in UndefinedFormatVersion))
42+
if (f, v) not in UNDEFINED_FORMAT_VERSION))
4043
@unpack
4144
def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:
4245
validator = get_validator(of, sv)
@@ -45,7 +48,7 @@ def test_as_expected(self, of: OutputFormat, sv: SchemaVersion) -> None:
4548

4649
@data(
4750
*(('foo', sv, (TypeError, "unexpected output_format: 'foo'")) for sv in SchemaVersion),
48-
*((f, v, (ValueError, f'unsupported schema_version: {v}')) for f, v in UndefinedFormatVersion)
51+
*((f, v, (ValueError, f'unsupported schema_version: {v}')) for f, v in UNDEFINED_FORMAT_VERSION)
4952
)
5053
@unpack
5154
def test_fails_on_wrong_args(self, of: OutputFormat, sv: SchemaVersion, raisesRegex: Tuple) -> None:

0 commit comments

Comments
 (0)