-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_main.py
More file actions
executable file
·71 lines (52 loc) · 1.68 KB
/
test_main.py
File metadata and controls
executable file
·71 lines (52 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""
Test main.py module
"""
import subprocess
import sys
from pathlib import Path
from unittest.mock import patch
import pytest
@pytest.mark.unit
def test_main_import():
"""Test that main.py can be imported without executing"""
import main # noqa: F401
@pytest.mark.unit
def test_main_function():
"""Test that main() raises NotImplementedError"""
from main import main
with patch("sys.argv", ["main"]):
with pytest.raises(NotImplementedError):
main()
@pytest.mark.unit
def test_main_version():
"""Test that --version prints the version and exits"""
from main import main
with patch("sys.argv", ["main", "--version"]):
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 0
@pytest.mark.unit
def test_main_as_script():
"""Test that main.py raises NotImplementedError when run as a script"""
main_path = Path(__file__).parent.parent / "src" / "main.py"
result = subprocess.run(
[sys.executable, str(main_path)],
capture_output=True,
text=True,
)
# Should exit with code 1 due to NotImplementedError
assert result.returncode == 1
assert "NotImplementedError" in result.stderr
@pytest.mark.unit
def test_main_as_script_version():
"""Test that --version works when run as a script"""
main_path = Path(__file__).parent.parent / "src" / "main.py"
result = subprocess.run(
[sys.executable, str(main_path), "--version"],
capture_output=True,
text=True,
)
from {{ cookiecutter.project_slug }} import __version__
assert result.returncode == 0
assert __version__ in result.stdout