forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_entrypoints.py
More file actions
63 lines (49 loc) · 2.32 KB
/
test_entrypoints.py
File metadata and controls
63 lines (49 loc) · 2.32 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
from unittest import mock
from pythonforandroid.entrypoints import main
from pythonforandroid.util import BuildInterruptingException
class TestMain:
"""Test the main entry point function."""
@mock.patch('pythonforandroid.toolchain.ToolchainCL')
@mock.patch('pythonforandroid.entrypoints.check_python_version')
def test_main_success(self, mock_check_version, mock_toolchain):
"""Test main() executes successfully with valid Python version."""
main()
mock_check_version.assert_called_once()
mock_toolchain.assert_called_once()
@mock.patch('pythonforandroid.entrypoints.handle_build_exception')
@mock.patch('pythonforandroid.toolchain.ToolchainCL')
@mock.patch('pythonforandroid.entrypoints.check_python_version')
def test_main_build_interrupting_exception(
self, mock_check_version, mock_toolchain, mock_handler
):
"""Test main() catches BuildInterruptingException and handles it."""
exc = BuildInterruptingException("Build failed", "Try reinstalling")
mock_toolchain.side_effect = exc
main()
mock_check_version.assert_called_once()
mock_toolchain.assert_called_once()
mock_handler.assert_called_once_with(exc)
@mock.patch('pythonforandroid.toolchain.ToolchainCL')
@mock.patch('pythonforandroid.entrypoints.check_python_version')
def test_main_other_exception_propagates(
self, mock_check_version, mock_toolchain
):
"""Test main() allows non-BuildInterruptingException to propagate."""
mock_toolchain.side_effect = RuntimeError("Unexpected error")
try:
main()
assert False, "Expected RuntimeError to be raised"
except RuntimeError as e:
assert str(e) == "Unexpected error"
mock_check_version.assert_called_once()
mock_toolchain.assert_called_once()
@mock.patch('pythonforandroid.entrypoints.check_python_version')
def test_main_python_version_check_fails(self, mock_check_version):
"""Test main() allows Python version check failure to propagate."""
mock_check_version.side_effect = SystemExit(1)
try:
main()
assert False, "Expected SystemExit to be raised"
except SystemExit as e:
assert e.code == 1
mock_check_version.assert_called_once()