Skip to content

Commit 20e845c

Browse files
committed
test(cli): cover local version in splash and --version flag
1 parent ea8d6c4 commit 20e845c

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎tests/unit/CodeEntropy/config/argparse/test_argparse_build_parser.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
3+
from CodeEntropy import __version__
14
from CodeEntropy.config.argparse import ConfigResolver
25

36

@@ -37,3 +40,13 @@ def test_build_parser_nargs_plus_parses_top_traj_file_list():
3740
args = parser.parse_args(["--top_traj_file", "a.tpr", "b.trr"])
3841

3942
assert args.top_traj_file == ["a.tpr", "b.trr"]
43+
44+
45+
def test_version_flag_prints_installed_version_and_exits(capsys):
46+
parser = ConfigResolver().build_parser()
47+
48+
with pytest.raises(SystemExit) as exc:
49+
parser.parse_args(["--version"])
50+
51+
assert exc.value.code == 0
52+
assert f"CodeEntropy {__version__}" in capsys.readouterr().out

‎tests/unit/CodeEntropy/config/runtime/test_show_splash.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from rich.console import Console
55

6+
from CodeEntropy import __version__
7+
68

79
def test_show_splash_with_citation(runner):
810
citation = {
@@ -26,8 +28,8 @@ def test_show_splash_with_citation(runner):
2628
out = buf.getvalue()
2729

2830
assert "Welcome to CodeEntropy" in out
29-
assert "Version 1.0" in out
30-
assert "2025-01-01" in out
31+
assert f"Version {__version__}" in out
32+
assert "Version 1.0" not in out
3133
assert "https://example.com" in out
3234
assert "This is a test abstract." in out
3335
assert "Alice Smith" in out
@@ -43,4 +45,7 @@ def test_show_splash_without_citation(runner):
4345
):
4446
runner.show_splash()
4547

46-
assert "Welcome to CodeEntropy" in buf.getvalue()
48+
out = buf.getvalue()
49+
50+
assert "Welcome to CodeEntropy" in out
51+
assert f"Version {__version__}" in out

0 commit comments

Comments
 (0)