-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy path__init__.py
More file actions
127 lines (101 loc) · 2.95 KB
/
Copy path__init__.py
File metadata and controls
127 lines (101 loc) · 2.95 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
# Copyright (c) nexB Inc. and others.
# SPDX-License-Identifier: Apache-2.0
#
# Visit https://aboutcode.org and https://github.com/aboutcode-org/univers for support and download.
from typing import NamedTuple
from typing import Union
class SchemaDrivenVersTest(NamedTuple):
test_type: str
test_group: str
input: dict
expected_output: Union[list, bool]
@classmethod
def from_data(cls, data: dict):
return cls(**data)
def assert_result(self):
assert self.result == self.expected_output
@property
def result(self):
if self.test_type == "equality":
return self.equality()
elif self.test_type == "comparison":
return self.comparison()
elif self.test_type == "containment":
return self.containment()
elif self.test_type == "roundtrip":
return self.roundtrip()
elif self.test_type == "from_native":
return self.from_native()
raise Exception(f"Unknown test_type: {self.test_type}")
def equality(self):
raise NotImplementedError
def comparison(self):
raise NotImplementedError
def containment(self):
raise NotImplementedError
def roundtrip(self):
raise NotImplementedError
def from_native(self):
raise NotImplementedError
@property
def input_scheme(self):
return self.input["input_scheme"]
@property
def input_native_range(self):
return self.input["native_range"]
@property
def input_version1(self):
return self.input["versions"][0]
@property
def input_version2(self):
return self.input["versions"][1]
def get_test_data_comp(scheme, versions, output):
return {
"test_group": "advanced",
"test_type": "comparison",
"input": {
"input_scheme": scheme,
"versions": versions,
},
"expected_output": output,
}
def get_test_data_eq(scheme, versions, output):
return {
"test_group": "advanced",
"test_type": "equality",
"input": {
"input_scheme": scheme,
"versions": versions,
},
"expected_output": output,
}
def get_test_data_containment(vers, version, output):
return {
"test_group": "advanced",
"test_type": "containment",
"input": {
"vers": vers,
"version": version,
},
"expected_output": output,
}
def get_test_data_roundtrip(vers, output):
return {
"test_group": "advanced",
"test_type": "roundtrip",
"input": {
"vers": vers,
},
"expected_output": output,
}
def get_test_data_from_native(native_range, schema, output):
return {
"test_group": "advanced",
"test_type": "from_native",
"input": {
"native_range": native_range,
"scheme": schema,
},
"expected_output": output,
}