-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_application.py
More file actions
58 lines (42 loc) · 1.87 KB
/
test_application.py
File metadata and controls
58 lines (42 loc) · 1.87 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
import ast
from docbuild.cli.cmd_config.application import app
def test_config_app(context, runner):
context.appconfigfiles = ["/tmp/app1.toml", "/tmp/app2.toml"]
context.appconfig = {"foo": "bar", "baz": [1, 2, 3]}
# Run the command with the fake context
result = runner.invoke(app, obj=context)
assert result.exit_code == 0
assert (
"# Application config files '/tmp/app1.toml, /tmp/app2.toml'" in result.output
)
lines = result.output.splitlines()
pretty_dict_str = "\n".join(lines[1:]).strip()
# Convert to dict
output_dict = ast.literal_eval(pretty_dict_str)
assert output_dict == {"foo": "bar", "baz": [1, 2, 3]}
def test_config_app_no_config_files(context, runner):
"""Test the app command when no config files are provided."""
context.appconfigfiles = [] # Empty list
context.appconfig = {"default": "config"}
# Run the command with the fake context
result = runner.invoke(app, obj=context)
assert result.exit_code == 0
assert "# No application config files provided" in result.output
lines = result.output.splitlines()
pretty_dict_str = "\n".join(lines[1:]).strip()
# Convert to dict
output_dict = ast.literal_eval(pretty_dict_str)
assert output_dict == {"default": "config"}
def test_config_app_none_config_files(context, runner):
"""Test the app command when appconfigfiles is None."""
context.appconfigfiles = None # None value
context.appconfig = {"empty": "state"}
# Run the command with the fake context
result = runner.invoke(app, obj=context)
assert result.exit_code == 0
assert "# No application config files provided" in result.output
lines = result.output.splitlines()
pretty_dict_str = "\n".join(lines[1:]).strip()
# Convert to dict
output_dict = ast.literal_eval(pretty_dict_str)
assert output_dict == {"empty": "state"}