Skip to content

Commit 7c92e16

Browse files
committed
Tests: Add software tests for "Magics.selfcheck" and "Magics.main"
1 parent 838c82c commit 7c92e16

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Magics/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def main(argv=None):
3838
)
3939

4040

41-
if __name__ == "__main__":
41+
if __name__ == "__main__": # pragma: nocover
4242
main()

tests/test_main.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import re
2+
import sys
3+
4+
import pytest
5+
6+
from Magics.__main__ import main, selfcheck
7+
8+
9+
def test_selfcheck(capsys):
10+
selfcheck()
11+
12+
stdout, stderr = capsys.readouterr()
13+
14+
assert "Found:" in stdout
15+
assert "Library:" in stdout
16+
assert "Magics home:" in stdout
17+
assert "Your system is ready." in stdout
18+
19+
assert "You are using an old version of magics" not in stdout
20+
21+
22+
def test_main_success(capsys):
23+
sys.argv = ["program", "selfcheck"]
24+
main()
25+
stdout, stderr = capsys.readouterr()
26+
assert "Your system is ready." in stdout
27+
28+
29+
def test_main_failure_no_command(capsys):
30+
sys.argv = ["program"]
31+
with pytest.raises(SystemExit) as ex:
32+
main()
33+
ex.match("2")
34+
stdout, stderr = capsys.readouterr()
35+
assert "program: error: the following arguments are required: command" in stderr
36+
37+
38+
def test_main_failure_unknown_command(capsys):
39+
sys.argv = ["program", "foobar"]
40+
with pytest.raises(RuntimeError) as ex:
41+
main()
42+
ex.match(re.escape("Command not recognised 'foobar'. See usage with --help."))

0 commit comments

Comments
 (0)