Skip to content

Commit 2a9dab1

Browse files
committed
test some cli > config > defaults priority
not full coverage, but covers some important cases
1 parent 98724fb commit 2a9dab1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/unit/test_args.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,36 @@ def test_invalid_image_name():
9595
"""
9696
with pytest.raises(SystemExit):
9797
make_r2d(["--image-name", "_invalid", "."])
98+
99+
100+
def test_build_config_priority(tmp_path):
101+
config_file = str(tmp_path.joinpath("repo2docker_config.py"))
102+
with open(config_file, "w") as f:
103+
f.write("c.Repo2Docker.dry_run = True")
104+
r2d = make_r2d(["--config", config_file, "."])
105+
assert r2d.dry_run
106+
r2d = make_r2d(["--config", config_file, "--build", "."])
107+
assert not r2d.dry_run
108+
with open(config_file, "w") as f:
109+
f.write("c.Repo2Docker.dry_run = False")
110+
r2d = make_r2d(["--config", config_file, "--no-build", "."])
111+
assert r2d.dry_run
112+
113+
114+
@pytest.mark.parametrize(
115+
"trait, arg, default",
116+
[
117+
("output_image_spec", "--image-name", ""),
118+
("ref", "--ref", None),
119+
],
120+
)
121+
def test_config_priority(tmp_path, trait, arg, default):
122+
config_file = str(tmp_path.joinpath("repo2docker_config.py"))
123+
r2d = make_r2d(["."])
124+
assert getattr(r2d, trait) == default
125+
with open(config_file, "w") as f:
126+
f.write(f"c.Repo2Docker.{trait} = 'config'")
127+
r2d = make_r2d(["--config", config_file, "."])
128+
assert getattr(r2d, trait) == "config"
129+
r2d = make_r2d(["--config", config_file, arg, "cli", "."])
130+
assert getattr(r2d, trait) == "cli"

0 commit comments

Comments
 (0)