Skip to content

Commit 6e5d7c6

Browse files
committed
[tests] Add tests for library recipe
1 parent 8b93b7b commit 6e5d7c6

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/test_recipe.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
from backports import tempfile
77
from pythonforandroid.build import Context
88
from pythonforandroid.recipe import Recipe, import_recipe
9+
from pythonforandroid.archs import ArchAarch_64
10+
from pythonforandroid.bootstrap import Bootstrap
11+
from test_bootstrap import BaseClassSetupBootstrap
12+
13+
try:
14+
from unittest import mock
15+
except ImportError:
16+
# `Python 2` or lower than `Python 3.3` does not
17+
# have the `unittest.mock` module built-in
18+
import mock
919

1020

1121
def patch_logger(level):
@@ -122,3 +132,55 @@ def test_download(self):
122132
'Downloading test_recipe from '
123133
'https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz')]
124134
assert m_touch.call_count == 1
135+
136+
137+
class TestLibraryRecipe(BaseClassSetupBootstrap, unittest.TestCase):
138+
def setUp(self):
139+
"""
140+
Initialize a Context with a Bootstrap and a Distribution to properly
141+
test an library recipe, to do so we reuse `BaseClassSetupBootstrap`
142+
"""
143+
super(TestLibraryRecipe, self).setUp()
144+
self.ctx.bootstrap = Bootstrap().get_bootstrap('sdl2', self.ctx)
145+
self.setUp_distribution_with_bootstrap(self.ctx.bootstrap)
146+
147+
def test_built_libraries(self):
148+
"""The openssl recipe is a library recipe, so it should have set the
149+
attribute `built_libraries`, but not the case of `pyopenssl` recipe.
150+
"""
151+
recipe = Recipe.get_recipe('openssl', self.ctx)
152+
self.assertTrue(recipe.built_libraries)
153+
154+
recipe = Recipe.get_recipe('pyopenssl', self.ctx)
155+
self.assertFalse(recipe.built_libraries)
156+
157+
@mock.patch('pythonforandroid.recipe.exists')
158+
def test_should_build(self, mock_exists):
159+
arch = ArchAarch_64(self.ctx)
160+
recipe = Recipe.get_recipe('openssl', self.ctx)
161+
recipe.ctx = self.ctx
162+
self.assertFalse(recipe.should_build(arch))
163+
164+
mock_exists.return_value = False
165+
self.assertTrue(recipe.should_build(arch))
166+
167+
@mock.patch('pythonforandroid.recipe.Recipe.get_libraries')
168+
@mock.patch('pythonforandroid.recipe.Recipe.install_libs')
169+
def test_do_install_libs(self, mock_install_libs, mock_get_libraries):
170+
mock_get_libraries.return_value = {
171+
'/build_lib/libsample1.so',
172+
'/build_lib/libsample2.so',
173+
}
174+
self.ctx.recipe_build_order = [
175+
"hostpython3",
176+
"openssl",
177+
"python3",
178+
"sdl2",
179+
"kivy",
180+
]
181+
arch = ArchAarch_64(self.ctx)
182+
recipe = Recipe.get_recipe('openssl', self.ctx)
183+
recipe.do_install_libs(arch)
184+
mock_install_libs.assert_called_once_with(
185+
arch, *mock_get_libraries.return_value
186+
)

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