|
7 | 7 | from backports import tempfile
|
8 | 8 | from pythonforandroid.build import Context
|
9 | 9 | 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 |
10 | 13 |
|
11 | 14 |
|
12 | 15 | def patch_logger(level):
|
@@ -176,3 +179,55 @@ def test_download_file_scheme_https_oserror(self):
|
176 | 179 | assert m_urlretrieve.call_args_list == expected_call_args_list
|
177 | 180 | expected_call_args_list = [mock.call(1)] * (retry - 1)
|
178 | 181 | 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