Skip to content

Commit 9580cae

Browse files
committed
[tests] Add tests for pyicu recipe
1 parent dee8600 commit 9580cae

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tests/recipes/test_pyicu.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
3+
import unittest
4+
5+
try:
6+
from unittest import mock
7+
except ImportError:
8+
# `Python 2` or lower than `Python 3.3` does not
9+
# have the `unittest.mock` module built-in
10+
import mock
11+
from pythonforandroid.bootstrap import Bootstrap
12+
from pythonforandroid.distribution import Distribution
13+
from pythonforandroid.recipe import Recipe
14+
from pythonforandroid.build import Context
15+
from pythonforandroid.archs import ArchARMv7_a
16+
17+
18+
class TestPyIcuRecipe(unittest.TestCase):
19+
"""
20+
An unittest for recipe :mod:`~pythonforandroid.recipes.pyicu`
21+
"""
22+
23+
ctx = None
24+
25+
def setUp(self):
26+
self.ctx = Context()
27+
self.ctx.ndk_api = 21
28+
self.ctx.android_api = 27
29+
self.ctx._sdk_dir = "/opt/android/android-sdk"
30+
self.ctx._ndk_dir = "/opt/android/android-ndk"
31+
self.ctx.setup_dirs(os.getcwd())
32+
self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
33+
self.ctx.bootstrap.distribution = Distribution.get_distribution(
34+
self.ctx, name="sdl2", recipes=["python3", "kivy", "pyicu"]
35+
)
36+
self.ctx.recipe_build_order = [
37+
"hostpython3",
38+
"icu",
39+
"python3",
40+
"sdl2",
41+
"pyicu",
42+
"kivy",
43+
]
44+
self.ctx.python_recipe = Recipe.get_recipe("python3", self.ctx)
45+
46+
@mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices")
47+
@mock.patch("pythonforandroid.build.ensure_dir")
48+
@mock.patch("pythonforandroid.archs.find_executable")
49+
def test_get_recipe_env(
50+
self,
51+
mock_find_executable,
52+
mock_ensure_dir,
53+
mock_check_recipe_choices,
54+
):
55+
"""
56+
Test that method
57+
:meth:`~pythonforandroid.recipes.pyicu.PyICURecipe.get_recipe_env`
58+
returns the expected flags
59+
"""
60+
arch = ArchARMv7_a(self.ctx)
61+
recipe = Recipe.get_recipe("pyicu", self.ctx)
62+
63+
icu_recipe = Recipe.get_recipe("icu", self.ctx)
64+
65+
mock_find_executable.return_value = 'aarch64-linux-android-gcc'
66+
mock_check_recipe_choices.return_value = sorted(
67+
self.ctx.recipe_build_order
68+
)
69+
70+
expected_pyicu_libs = [
71+
lib[3:-3] for lib in icu_recipe.built_libraries.keys()
72+
]
73+
env = recipe.get_recipe_env(arch)
74+
self.assertEqual(":".join(expected_pyicu_libs), env["PYICU_LIBRARIES"])
75+
self.assertIn("include/icu", env["CPPFLAGS"])
76+
self.assertIn("icu4c/icu_build/lib", env["LDFLAGS"])
77+
78+
# make sure that the mocked methods are actually called
79+
mock_ensure_dir.assert_called()
80+
mock_find_executable.assert_called()
81+
mock_check_recipe_choices.assert_called()

0 commit comments

Comments
 (0)