Skip to content

Commit f5fb04e

Browse files
committed
[tests] Add tests for library recipe
1 parent 7553beb commit f5fb04e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/test_recipe.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from backports import tempfile
88
from pythonforandroid.build import Context
99
from pythonforandroid.recipe import Recipe, import_recipe
10+
from pythonforandroid.archs import ArchAarch_64
11+
from pythonforandroid.bootstrap import Bootstrap
12+
from test_bootstrap import BaseClassSetupBootstrap
1013

1114

1215
def patch_logger(level):
@@ -176,3 +179,55 @@ def test_download_file_scheme_https_oserror(self):
176179
assert m_urlretrieve.call_args_list == expected_call_args_list
177180
expected_call_args_list = [mock.call(1)] * (retry - 1)
178181
assert m_sleep.call_args_list == expected_call_args_list
182+
183+
184+
class TestLibraryRecipe(BaseClassSetupBootstrap, unittest.TestCase):
185+
def setUp(self):
186+
"""
187+
Initialize a Context with a Bootstrap and a Distribution to properly
188+
test an library recipe, to do so we reuse `BaseClassSetupBootstrap`
189+
"""
190+
super(TestLibraryRecipe, self).setUp()
191+
self.ctx.bootstrap = Bootstrap().get_bootstrap('sdl2', self.ctx)
192+
self.setUp_distribution_with_bootstrap(self.ctx.bootstrap)
193+
194+
def test_built_libraries(self):
195+
"""The openssl recipe is a library recipe, so it should have set the
196+
attribute `built_libraries`, but not the case of `pyopenssl` recipe.
197+
"""
198+
recipe = Recipe.get_recipe('openssl', self.ctx)
199+
self.assertTrue(recipe.built_libraries)
200+
201+
recipe = Recipe.get_recipe('pyopenssl', self.ctx)
202+
self.assertFalse(recipe.built_libraries)
203+
204+
@mock.patch('pythonforandroid.recipe.exists')
205+
def test_should_build(self, mock_exists):
206+
arch = ArchAarch_64(self.ctx)
207+
recipe = Recipe.get_recipe('openssl', self.ctx)
208+
recipe.ctx = self.ctx
209+
self.assertFalse(recipe.should_build(arch))
210+
211+
mock_exists.return_value = False
212+
self.assertTrue(recipe.should_build(arch))
213+
214+
@mock.patch('pythonforandroid.recipe.Recipe.get_libraries')
215+
@mock.patch('pythonforandroid.recipe.Recipe.install_libs')
216+
def test_install_libraries(self, mock_install_libs, mock_get_libraries):
217+
mock_get_libraries.return_value = {
218+
'/build_lib/libsample1.so',
219+
'/build_lib/libsample2.so',
220+
}
221+
self.ctx.recipe_build_order = [
222+
"hostpython3",
223+
"openssl",
224+
"python3",
225+
"sdl2",
226+
"kivy",
227+
]
228+
arch = ArchAarch_64(self.ctx)
229+
recipe = Recipe.get_recipe('openssl', self.ctx)
230+
recipe.install_libraries(arch)
231+
mock_install_libs.assert_called_once_with(
232+
arch, *mock_get_libraries.return_value
233+
)

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