Skip to content

Commit b000d5b

Browse files
committed
Added test for Python 2 running long enough to exit nicely
1 parent 8637a20 commit b000d5b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_entrypoints_python2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
# This test is a special case that we expect to run under Python 2, so
3+
# include the necessary compatibility imports:
4+
try: # Python 3
5+
from unittest import mock
6+
except ImportError: # Python 2
7+
import mock
8+
9+
from pythonforandroid.recommendations import PY2_ERROR_TEXT
10+
from pythonforandroid import entrypoints
11+
12+
13+
def test_main_python2():
14+
"""Test that running under Python 2 leads to the build failing, while
15+
running under a suitable version works fine.
16+
17+
Note that this test must be run *using* Python 2 to truly test
18+
that p4a can reach the Python version check before importing some
19+
Python-3-only syntax and crashing.
20+
"""
21+
22+
# Under Python 2, we should get a normal control flow exception
23+
# that is handled properly, not any other type of crash
24+
with mock.patch('sys.version_info') as fake_version_info, \
25+
mock.patch('pythonforandroid.entrypoints.handle_build_exception') as handle_build_exception:
26+
27+
fake_version_info.major = 2
28+
fake_version_info.minor = 7
29+
30+
def check_python2_exception(exc):
31+
"""Check that the exception message is Python 2 specific."""
32+
assert exc.message == PY2_ERROR_TEXT
33+
handle_build_exception.side_effect = check_python2_exception
34+
35+
entrypoints.main()
36+
37+
handle_build_exception.assert_called_once()

0 commit comments

Comments
 (0)