Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork252
Expand file tree
/
Copy pathtest_config.py
More file actions
105 lines (84 loc) · 2.7 KB
/
test_config.py
File metadata and controls
105 lines (84 loc) · 2.7 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
importos
importtempfile
importtextwrap
importunittest
frompathlibimportPath
frombpythonimportconfig
TEST_THEME_PATH=Path(os.path.join(os.path.dirname(__file__),"test.theme"))
classTestConfig(unittest.TestCase):
defload_temp_config(self,content):
"""Write config to a temporary file and load it."""
withtempfile.NamedTemporaryFile()asf:
f.write(content.encode("utf8"))
f.flush()
returnconfig.Config(Path(f.name))
deftest_load_theme(self):
color_scheme=dict()
config.load_theme(TEST_THEME_PATH,color_scheme,dict())
expected= {"keyword":"y"}
self.assertEqual(color_scheme,expected)
defaults= {"name":"c"}
expected.update(defaults)
config.load_theme(TEST_THEME_PATH,color_scheme,defaults)
self.assertEqual(color_scheme,expected)
deftest_keybindings_default_contains_no_duplicates(self):
struct=self.load_temp_config("")
keys= (attrforattrindir(struct)ifattr.endswith("_key"))
mapped_keys= [
getattr(struct,key)forkeyinkeysifgetattr(struct,key)
]
mapped_keys_set=set(mapped_keys)
self.assertEqual(len(mapped_keys),len(mapped_keys_set))
deftest_keybindings_use_default(self):
struct=self.load_temp_config(
textwrap.dedent(
"""
[keyboard]
help = F1
"""
)
)
self.assertEqual(struct.help_key,"F1")
deftest_keybindings_use_other_default(self):
struct=self.load_temp_config(
textwrap.dedent(
"""
[keyboard]
help = C-h
"""
)
)
self.assertEqual(struct.help_key,"C-h")
self.assertEqual(struct.backspace_key,"")
deftest_keybindings_use_other_default_issue_447(self):
struct=self.load_temp_config(
textwrap.dedent(
"""
[keyboard]
help = F2
show_source = F9
"""
)
)
self.assertEqual(struct.help_key,"F2")
self.assertEqual(struct.show_source_key,"F9")
deftest_keybindings_unset(self):
struct=self.load_temp_config(
textwrap.dedent(
"""
[keyboard]
help =
"""
)
)
self.assertFalse(struct.help_key)
deftest_keybindings_unused(self):
struct=self.load_temp_config(
textwrap.dedent(
"""
[keyboard]
help = F4
"""
)
)
self.assertEqual(struct.help_key,"F4")