Skip to content

Commit d90a271

Browse files
committed
tests for help command, listing examples, and copying examples
1 parent 012a45e commit d90a271

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_cli.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
from diffpy.cmi.cli import main
4+
5+
6+
def test_cli_help(capsys):
7+
"""Test that the CLI help message is displayed correctly."""
8+
with pytest.raises(SystemExit) as exc:
9+
main(["--help", "-h"])
10+
assert exc.value.code == 0
11+
out, _ = capsys.readouterr()
12+
assert "Welcome to diffpy.cmi" in out
13+
14+
15+
def test_example_list(capsys):
16+
"""Test that the example listing works."""
17+
rc = main(["example", "list"])
18+
assert rc == 0
19+
out, _ = capsys.readouterr()
20+
# test specific known pack and example
21+
assert "ch03NiModelling" in out
22+
assert "pdf" in out
23+
24+
25+
def test_example_copy(monkeypatch, tmp_path):
26+
"""Test that an example can be copied to the current directory."""
27+
# create a fake example
28+
fake_examples = tmp_path / "docs" / "examples"
29+
src = fake_examples / "pack1" / "ex1"
30+
src.mkdir(parents=True)
31+
monkeypatch.setattr(
32+
"diffpy.cmi.cli._installed_examples_dir",
33+
lambda: fake_examples,
34+
)
35+
cwd = tmp_path
36+
monkeypatch.chdir(cwd)
37+
rc = main(["example", "copy", "pdf/ch03NiModelling"])
38+
assert rc == 0
39+
assert (cwd / "ch03NiModelling").exists()

0 commit comments

Comments
 (0)