Skip to content

Commit b5d9b0d

Browse files
committed
[tests] Add tests for pyicu recipe
1 parent a4ea0d1 commit b5d9b0d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

tests/recipes/test_pyicu.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.glob")
49+
@mock.patch("pythonforandroid.archs.find_executable")
50+
def test_get_recipe_env(
51+
self,
52+
mock_find_executable,
53+
mock_glob,
54+
mock_ensure_dir,
55+
mock_check_recipe_choices,
56+
):
57+
"""
58+
Test that method
59+
:meth:`~pythonforandroid.recipes.pyicu.PyICURecipe.get_recipe_env`
60+
returns the expected flags
61+
"""
62+
arch = ArchARMv7_a(self.ctx)
63+
recipe = Recipe.get_recipe("pyicu", self.ctx)
64+
65+
icu_recipe = Recipe.get_recipe("icu", self.ctx)
66+
67+
mock_find_executable.return_value = (
68+
"/opt/android/android-ndk/toolchains/"
69+
"llvm/prebuilt/linux-x86_64/bin/clang"
70+
)
71+
mock_glob.return_value = ["llvm"]
72+
mock_check_recipe_choices.return_value = sorted(
73+
self.ctx.recipe_build_order
74+
)
75+
76+
expected_pyicu_libs = [
77+
lib[3:-3] for lib in icu_recipe.built_libraries.keys()
78+
]
79+
env = recipe.get_recipe_env(arch)
80+
self.assertEqual(":".join(expected_pyicu_libs), env["PYICU_LIBRARIES"])
81+
self.assertIn("include/icu", env["CPPFLAGS"])
82+
self.assertIn("icu4c/icu_build/lib", env["LDFLAGS"])
83+
84+
# make sure that the mocked methods are actually called
85+
mock_glob.assert_called()
86+
mock_ensure_dir.assert_called()
87+
mock_find_executable.assert_called()
88+
mock_check_recipe_choices.assert_called()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy