Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Magics/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def main(argv=None):
)


if __name__ == "__main__":
if __name__ == "__main__": # pragma: nocover
main()
42 changes: 42 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import re
import sys

import pytest

from Magics.__main__ import main, selfcheck


def test_selfcheck(capsys):
selfcheck()

stdout, stderr = capsys.readouterr()

assert "Found:" in stdout
assert "Library:" in stdout
assert "Magics home:" in stdout
assert "Your system is ready." in stdout

assert "You are using an old version of magics" not in stdout


def test_main_success(capsys):
sys.argv = ["program", "selfcheck"]
main()
stdout, stderr = capsys.readouterr()
assert "Your system is ready." in stdout


def test_main_failure_no_command(capsys):
sys.argv = ["program"]
with pytest.raises(SystemExit) as ex:
main()
ex.match("2")
stdout, stderr = capsys.readouterr()
assert "program: error: the following arguments are required: command" in stderr


def test_main_failure_unknown_command(capsys):
sys.argv = ["program", "foobar"]
with pytest.raises(RuntimeError) as ex:
main()
ex.match(re.escape("Command not recognised 'foobar'. See usage with --help."))