-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
82 lines (65 loc) · 2.23 KB
/
testing.py
File metadata and controls
82 lines (65 loc) · 2.23 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
from enum import Enum
from comprehensiveconfig import ConfigSpec
from comprehensiveconfig.json import JsonWriter
from comprehensiveconfig.spec import (
Table,
TableSpec,
Section,
Integer,
Float,
Text,
List,
ConfigEnum
)
from comprehensiveconfig.toml import TomlWriter
class Example(TableSpec):
x = Integer(10)
class testEnum(Enum):
'''An example doc comment to explain what our enumeration structure does'''
foo = "burger"
bar = "chicken"
class MyConfigSpec(ConfigSpec,
default_file="test.toml",
writer=TomlWriter,
create_file=True):
class MySection(Section, name="Funny_Section"):
"""Example comment under section"""
some_field = Integer(10)
other_field = Text("Some Default Text")
class SubSection(Section):
x = Integer(10)
class Credentials(Section, name="Credentials"):
email = Text(
"example@email.com",
regex=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$",
doc="email of the account"
)
password = Text("MyPassword")
some_field = Float(6.9)
example_list_field = List(
["12", "13", "14", 22], inner_type=Text(regex=r"[0-9]*") | Integer()
)
model_example = Example()
list_of_models = List([{"x": 12}, {"x": 12}], inner_type=Example())
list_of_sections: Table[str, Credentials | int] = Table(
{"google_creds": Credentials(email="example@email.com", password="passwd")},
key_type=Text(),
value_type=Credentials | Integer(),
)
test_enum = ConfigEnum(testEnum, testEnum.foo, by_name=False, doc="testing additional doc")
print(MyConfigSpec.some_field)
print(MyConfigSpec.MySection.other_field)
MyConfigSpec.some_field = 12.2
print(MyConfigSpec.some_field)
print(MyConfigSpec.MySection.other_field)
# print(MyConfigSpec.list_of_sections)
x = MyConfigSpec.load("test.toml", TomlWriter)
print(x.MySection.some_field)
x.some_field = 12
p = x.some_field
j = x.MySection.other_field
# MyConfigSpec.reset_global()
print(MyConfigSpec.some_field)
print(MyConfigSpec.MySection.other_field)
MyConfigSpec._INST.save("test.toml", TomlWriter)
MyConfigSpec._INST.save("test.json", JsonWriter)