-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathtest_schema_SchemaVersion.py
80 lines (66 loc) · 2.45 KB
/
test_schema_SchemaVersion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This file is part of CycloneDX Python Library
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.
from unittest import TestCase
from ddt import ddt, idata, unpack
from cyclonedx.schema import SchemaVersion
SORTED_SV = (
SchemaVersion.V1_6,
SchemaVersion.V1_5,
SchemaVersion.V1_4,
SchemaVersion.V1_3,
SchemaVersion.V1_2,
SchemaVersion.V1_1,
SchemaVersion.V1_0
)
# do not use any value-comparisons or implicit hash-functions here !
# just work with the position in tuple SORTED_SCHEMA_VERSIONS
td_gt = tuple((a, b) for i, a in enumerate(SORTED_SV) for b in SORTED_SV[i + 1:])
td_ge = tuple((a, b) for i, a in enumerate(SORTED_SV) for b in SORTED_SV[i:])
td_eq = tuple((v, v) for v in SORTED_SV)
td_le = tuple((b, a) for a, b in td_ge)
td_lt = tuple((b, a) for a, b in td_gt)
td_ne = tuple((a, b) for i, a in enumerate(SORTED_SV) for j, b in enumerate(SORTED_SV) if i != j)
@ddt
class TestSchemaVersion(TestCase):
@idata(v for v in SchemaVersion)
def test_version_roundtrip(self, v: SchemaVersion) -> None:
v2 = SchemaVersion.from_version(v.to_version())
self.assertIs(v, v2)
@idata(td_ne)
@unpack
def test_ne(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertNotEqual(a, b)
@idata(td_gt)
@unpack
def test_gt(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertGreater(a, b)
@idata(td_ge)
@unpack
def test_ge(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertGreaterEqual(a, b)
@idata(td_eq)
@unpack
def test_eq(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertEqual(a, b)
@idata(td_lt)
@unpack
def test_lt(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertLess(a, b)
@idata(td_le)
@unpack
def test_le(self, a: SchemaVersion, b: SchemaVersion) -> None:
self.assertLessEqual(a, b)