@@ -113,6 +113,32 @@ def test_validate_expected_error_iterator(self, schema_version: SchemaVersion, t
113113 self .assertIsNotNone (validation_error .data )
114114
115115
116+
117+ def test_validation_error_has_useful_message_and_path (self ) -> None :
118+ validator = JsonValidator (SchemaVersion .V1_6 )
119+ test_data = '{"bomFormat": "CycloneDX", "specVersion": "1.6", "version": 1, "metadata": {"timestamp": true}}'
120+ try :
121+ validation_error = validator .validate_str (test_data )
122+ except MissingOptionalDependencyException :
123+ self .skipTest ('MissingOptionalDependencyException' )
124+ self .assertIsNotNone (validation_error )
125+ assert validation_error is not None
126+ self .assertTrue (validation_error .message )
127+ self .assertEqual (('metadata' , 'timestamp' ), validation_error .path )
128+ self .assertNotEqual (str (validation_error .data ), str (validation_error ))
129+
130+ def test_validation_error_prefers_nested_context_message (self ) -> None :
131+ validator = JsonValidator (SchemaVersion .V1_6 )
132+ test_data = '{"bomFormat": "CycloneDX", "specVersion": "1.6", "version": 1, "components": [{"type": "library", "name": "demo", "version": 1}]}'
133+ try :
134+ validation_error = validator .validate_str (test_data )
135+ except MissingOptionalDependencyException :
136+ self .skipTest ('MissingOptionalDependencyException' )
137+ self .assertIsNotNone (validation_error )
138+ assert validation_error is not None
139+ self .assertEqual (('components' , 0 , 'version' ), validation_error .path )
140+ self .assertIn ('is not of type' , validation_error .message )
141+
116142@ddt
117143class TestJsonStrictValidator (TestCase ):
118144
0 commit comments