This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Expand file tree
/
Copy pathtest_rtmbot_runner.py
More file actions
79 lines (68 loc) · 1.93 KB
/
test_rtmbot_runner.py
File metadata and controls
79 lines (68 loc) · 1.93 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
import os
from contextlib import contextmanager
from rtmbot.bin.run_rtmbot import load_overrides_from_env
@contextmanager
def override_env(env):
_environ = dict(os.environ)
try:
os.environ.clear()
os.environ.update(env)
yield
finally:
os.environ.clear()
os.environ.update(_environ)
def test_normal_overrides():
config = {
'SLACK_TOKEN': 'xoxb-foo-bar',
'BASE_PATH': os.getcwd(),
'LOGFILE': 'foobar.log',
'DEBUG': True,
'DAEMON': True
}
override = {
'SLACK_TOKEN': 'xoxb-this-should-change',
'BASE_PATH': '/opt/nope',
'LOGFILE': 'awesome.log',
'DEBUG': 'false',
'DAEMON': 'false'
}
with override_env(override):
load_overrides_from_env(config)
expected = {
'SLACK_TOKEN': 'xoxb-this-should-change',
'BASE_PATH': '/opt/nope',
'LOGFILE': 'awesome.log',
'DEBUG': False,
'DAEMON': False
}
assert config == expected
def test_plugin_overrides():
config = {
'ACTIVE_PLUGINS': ['plugins.AwesomePlugin']}
override = {
'AWESOME_PLUGIN_FOO': '1',
'AWESOME_PLUGIN_BAR_BAR': 'some_awesome_value'
}
with override_env(override):
load_overrides_from_env(config)
expected = {
'foo': '1',
'bar_bar': 'some_awesome_value'
}
assert config['plugins.AwesomePlugin'] == expected
def test_plugin_config_already_exists():
config = {
'ACTIVE_PLUGINS': ['plugins.AwesomePlugin'],
'plugins.AwesomePlugin': {
'some_credential': 'foo'
}
}
override = {
'AWESOME_PLUGIN_SOME_CREDENTIAL': 'bar'
}
with override_env(override):
load_overrides_from_env(config)
expected = {
'some_credential': 'bar'
}
assert config['plugins.AwesomePlugin'] == expected