-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_defaults.py
92 lines (70 loc) · 2.24 KB
/
test_defaults.py
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
#!/usr/bin/env python3
import filecmp
import os
import pathlib
from typer.testing import CliRunner
from aar_doc.cli import app
ROLES_DIR = pathlib.Path("./tests/fixtures/roles")
DEFAULT_ROLE = "minimum"
runner = CliRunner()
def test_generate_defaults(tmp_path):
"""
This test ensures that the default use case of generating
defaults for an argument_spec is handled as expected.
"""
role_path = ROLES_DIR / "generate_defaults"
output_dir = tmp_path
output_file = output_dir / "defaults.yml"
# Default case without extra options
expected_defaults_file = str(role_path / "defaults" / "main.yml")
result = runner.invoke(
app,
[
"--output-file",
output_file,
str(role_path),
"defaults",
],
)
assert result.exit_code == 0
assert filecmp.cmp(expected_defaults_file, output_file)
# Using --overwrite-duplicates option
expected_defaults_file = str(role_path / "defaults" / "overwrite.yml")
result = runner.invoke(
app,
[
"--output-file",
output_file,
str(role_path),
"defaults",
"--overwrite-duplicates",
],
)
assert result.exit_code == 0
assert filecmp.cmp(expected_defaults_file, output_file)
def test_generate_defaults_no_defaults():
"""
This test ensures that generating defaults for an argument_spec
without any configured defaults is handled as expected.
"""
role_path = ROLES_DIR / "generate_defaults_no_defaults"
role_path = str(role_path)
result = runner.invoke(app, [role_path, "defaults"])
assert result.exit_code == 0
assert (
result.output
== "No defaults configured in argument_specs. Nothing to do." + os.linesep
)
def test_generate_defaults_no_options():
"""
This test ensures that generating defaults for an argument_spec
without any options is handled as expected.
"""
role_path = ROLES_DIR / "no_options"
role_path = str(role_path)
result = runner.invoke(app, [role_path, "defaults"])
assert result.exit_code == 0
assert (
result.output
== "No defaults configured in argument_specs. Nothing to do." + os.linesep
)