Skip to content

Commit 0ce5de6

Browse files
committed
test: refactor to work on PY < 3.10
Signed-off-by: Paul Horton <[email protected]>
1 parent a51766d commit 0ce5de6

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

tests/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def assertValidAgainstSchema(self, bom_xml: str, schema_version: SchemaVersion)
117117

118118
if not schema_validates:
119119
print(xml_schema.error_log.last_error)
120-
self.assertTrue(schema_validates, 'Failed to validate Generated SBOM against XSD Schema')
120+
self.assertTrue(schema_validates, f'Failed to validate Generated SBOM against XSD Schema:'
121+
f'{bom_xml}')
121122

122123
def assertEqualXml(self, a: str, b: str) -> None:
123124
da, db = minidom.parseString(a), minidom.parseString(b)

tests/test_output_xml.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# SPDX-License-Identifier: Apache-2.0
1818
# Copyright (c) OWASP Foundation. All Rights Reserved.
1919
from os.path import dirname, join
20-
from typing import List
2120
from unittest.mock import Mock, patch
2221

2322
from cyclonedx.model.bom import Bom
@@ -29,22 +28,12 @@
2928
get_bom_with_nested_services, get_bom_with_services_simple, get_bom_with_services_complex
3029
from tests.base import BaseXmlTestCase
3130

31+
TEST_UUIDS = [
32+
MOCK_UUID_1, MOCK_UUID_2, MOCK_UUID_3, MOCK_UUID_4, MOCK_UUID_5, MOCK_UUID_6
33+
]
3234

33-
class TestOutputXml(BaseXmlTestCase):
34-
35-
UUID_INDEX: int = 0
36-
UUIDS: List[str] = [
37-
MOCK_UUID_1, MOCK_UUID_2, MOCK_UUID_3, MOCK_UUID_4, MOCK_UUID_5, MOCK_UUID_6
38-
]
3935

40-
def setUp(self) -> None:
41-
TestOutputXml.UUID_INDEX = 0
42-
43-
@staticmethod
44-
def iter_uuid() -> str:
45-
uuid = TestOutputXml.UUIDS[TestOutputXml.UUID_INDEX]
46-
TestOutputXml.UUID_INDEX += 1
47-
return uuid
36+
class TestOutputXml(BaseXmlTestCase):
4837

4938
def test_simple_bom_v1_4(self) -> None:
5039
self._validate_xml_bom(
@@ -249,7 +238,7 @@ def test_bom_v1_0_with_metadata_component(self, mock_uuid: Mock) -> None:
249238
mock_uuid.assert_called()
250239

251240
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_6)
252-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
241+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
253242
def test_bom_v1_4_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
254243
self._validate_xml_bom(
255244
bom=get_bom_with_services_simple(), schema_version=SchemaVersion.V1_4,
@@ -259,7 +248,7 @@ def test_bom_v1_4_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
259248
mock_uuid_s.assert_called()
260249

261250
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_5)
262-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
251+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
263252
def test_bom_v1_3_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
264253
self._validate_xml_bom(
265254
bom=get_bom_with_services_simple(), schema_version=SchemaVersion.V1_3,
@@ -269,7 +258,7 @@ def test_bom_v1_3_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
269258
mock_uuid_s.assert_called()
270259

271260
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_4)
272-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
261+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
273262
def test_bom_v1_2_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
274263
self._validate_xml_bom(
275264
bom=get_bom_with_services_simple(), schema_version=SchemaVersion.V1_2,
@@ -279,7 +268,7 @@ def test_bom_v1_2_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
279268
mock_uuid_s.assert_called()
280269

281270
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_1)
282-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
271+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
283272
def test_bom_v1_1_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
284273
self._validate_xml_bom(
285274
bom=get_bom_with_services_simple(), schema_version=SchemaVersion.V1_1,
@@ -289,7 +278,7 @@ def test_bom_v1_1_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
289278
mock_uuid_s.assert_called()
290279

291280
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_1)
292-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
281+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
293282
def test_bom_v1_0_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
294283
self._validate_xml_bom(
295284
bom=get_bom_with_services_simple(), schema_version=SchemaVersion.V1_0,
@@ -299,7 +288,7 @@ def test_bom_v1_0_services_simple(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
299288
mock_uuid_s.assert_called()
300289

301290
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_6)
302-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
291+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
303292
def test_bom_v1_4_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
304293
self._validate_xml_bom(
305294
bom=get_bom_with_services_complex(), schema_version=SchemaVersion.V1_4,
@@ -309,7 +298,7 @@ def test_bom_v1_4_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
309298
mock_uuid_s.assert_called()
310299

311300
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_5)
312-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
301+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
313302
def test_bom_v1_3_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
314303
self._validate_xml_bom(
315304
bom=get_bom_with_services_complex(), schema_version=SchemaVersion.V1_3,
@@ -319,7 +308,7 @@ def test_bom_v1_3_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
319308
mock_uuid_s.assert_called()
320309

321310
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_4)
322-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
311+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
323312
def test_bom_v1_2_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
324313
self._validate_xml_bom(
325314
bom=get_bom_with_services_complex(), schema_version=SchemaVersion.V1_2,
@@ -329,7 +318,7 @@ def test_bom_v1_2_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
329318
mock_uuid_s.assert_called()
330319

331320
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_3)
332-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
321+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
333322
def test_bom_v1_1_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
334323
self._validate_xml_bom(
335324
bom=get_bom_with_services_complex(), schema_version=SchemaVersion.V1_1,
@@ -339,7 +328,7 @@ def test_bom_v1_1_services_complex(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -
339328
mock_uuid_s.assert_called()
340329

341330
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_6)
342-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
331+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
343332
def test_bom_v1_4_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
344333
self._validate_xml_bom(
345334
bom=get_bom_with_nested_services(), schema_version=SchemaVersion.V1_4,
@@ -349,7 +338,7 @@ def test_bom_v1_4_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
349338
mock_uuid_s.assert_called()
350339

351340
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_5)
352-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
341+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
353342
def test_bom_v1_3_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
354343
self._validate_xml_bom(
355344
bom=get_bom_with_nested_services(), schema_version=SchemaVersion.V1_3,
@@ -359,7 +348,7 @@ def test_bom_v1_3_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) ->
359348
mock_uuid_s.assert_called()
360349

361350
@patch('cyclonedx.model.component.uuid4', return_value=MOCK_UUID_4)
362-
@patch('cyclonedx.model.service.uuid4', side_effect=iter_uuid)
351+
@patch('cyclonedx.model.service.uuid4', side_effect=TEST_UUIDS)
363352
def test_bom_v1_2_services_nested(self, mock_uuid_c: Mock, mock_uuid_s: Mock) -> None:
364353
self._validate_xml_bom(
365354
bom=get_bom_with_nested_services(), schema_version=SchemaVersion.V1_2,

0 commit comments

Comments
 (0)