-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_context_shape.py
More file actions
60 lines (51 loc) · 1.54 KB
/
test_context_shape.py
File metadata and controls
60 lines (51 loc) · 1.54 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
from prefab_cloud_python.context_shape import ContextShape, MAPPING
import prefab_pb2 as Prefab
class Dummy(object):
pass
class TestContextShape:
def test_field_type_number(self):
data = [
[1, 1],
[9999999999999999999, 1],
[-9999999999999999999, 1],
["a", 2],
["michael", 2],
[1.0, 4],
[999999999999999999999.0, 4],
[-999999999999999999999.0, 4],
[True, 5],
[False, 5],
[[], 10],
[[1, 2, 3], 10],
[["a", "b", "c"], 10],
[Dummy(), 2],
]
for [v, t] in data:
assert ContextShape.field_type_number(v) == t
# If this test fails, it means that we've added a new type to the ConfigValue
def test_mapping_is_exhaustive(self):
unsupported = [
"bytes",
"limit_definition",
"log_level",
"weighted_values",
"int_range",
"provided",
"confidential",
"decrypt_with",
"duration",
"schema",
]
supported = list(
map(
lambda x: x.number,
filter(
lambda x: x.name not in unsupported,
list(Prefab.ConfigValue.DESCRIPTOR.fields),
),
)
)
mapped = list(set(MAPPING.values()))
assert (
mapped == supported
), f"ContextShape MAPPING needs update: {mapped} != {supported}"