-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathevaluation_context.py
More file actions
90 lines (78 loc) · 1.91 KB
/
evaluation_context.py
File metadata and controls
90 lines (78 loc) · 1.91 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
"""Requirement 3.1.2"""
from datetime import datetime
from openfeature.evaluation_context import EvaluationContext
# positive
EvaluationContext(
targeting_key="key",
attributes={"bool": True},
)
EvaluationContext(
targeting_key="key",
attributes={"int": 42},
)
EvaluationContext(
targeting_key="key",
attributes={"float": 3.14},
)
EvaluationContext(
targeting_key="key",
attributes={"str": "value"},
)
EvaluationContext(
targeting_key="key",
attributes={"date": datetime.now()},
)
EvaluationContext(
targeting_key="key",
attributes={
"bool_list": [True, False],
"int_list": [1, 2],
"float_list": [1.1, 2.2],
"date_list": [datetime.now(), datetime.now()],
"str_list": ["a", "b"],
"list_list": [
["a", "b"],
["c", "d"],
],
"dict_list": [
{"int": 42},
{"str": "value"},
],
},
)
EvaluationContext(
targeting_key="key",
attributes={
"user": {
"id": 12345,
"name": "John Doe",
"active": True,
"last_login": datetime.now(),
"permissions": ["read", "write", "admin"],
"metadata": {
"source": "api",
"version": 2.1,
"tags": ["premium", "beta"],
"config": {
"nested_deeply": [
{"item": 1, "enabled": True},
{"item": 2, "enabled": False},
]
},
},
},
},
)
# negative
EvaluationContext(
targeting_key="key",
attributes={"null": None}, # ty: ignore[invalid-argument-type]
)
EvaluationContext(
targeting_key="key",
attributes={"complex": -4.5j}, # ty: ignore[invalid-argument-type]
)
EvaluationContext(
targeting_key="key",
attributes={42: 42}, # ty: ignore[invalid-argument-type]
)