|
6 | 6 | from backports import tempfile
|
7 | 7 | from pythonforandroid.build import Context
|
8 | 8 | 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 |
9 | 12 |
|
10 | 13 |
|
11 | 14 | def patch_logger(level):
|
@@ -122,3 +125,55 @@ def test_download(self):
|
122 | 125 | 'Downloading test_recipe from '
|
123 | 126 | 'https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz')]
|
124 | 127 | assert m_touch.call_count == 1
|
| 128 | + |
| 129 | + |
| 130 | +class TestLibraryRecipe(BaseClassSetupBootstrap, unittest.TestCase): |
| 131 | + def setUp(self): |
| 132 | + """ |
| 133 | + Initialize a Context with a Bootstrap and a Distribution to properly |
| 134 | + test an library recipe, to do so we reuse `BaseClassSetupBootstrap` |
| 135 | + """ |
| 136 | + super(TestLibraryRecipe, self).setUp() |
| 137 | + self.ctx.bootstrap = Bootstrap().get_bootstrap('sdl2', self.ctx) |
| 138 | + self.setUp_distribution_with_bootstrap(self.ctx.bootstrap) |
| 139 | + |
| 140 | + def test_built_libraries(self): |
| 141 | + """The openssl recipe is a library recipe, so it should have set the |
| 142 | + attribute `built_libraries`, but not the case of `pyopenssl` recipe. |
| 143 | + """ |
| 144 | + recipe = Recipe.get_recipe('openssl', self.ctx) |
| 145 | + self.assertTrue(recipe.built_libraries) |
| 146 | + |
| 147 | + recipe = Recipe.get_recipe('pyopenssl', self.ctx) |
| 148 | + self.assertFalse(recipe.built_libraries) |
| 149 | + |
| 150 | + @mock.patch('pythonforandroid.recipe.exists') |
| 151 | + def test_should_build(self, mock_exists): |
| 152 | + arch = ArchAarch_64(self.ctx) |
| 153 | + recipe = Recipe.get_recipe('openssl', self.ctx) |
| 154 | + recipe.ctx = self.ctx |
| 155 | + self.assertFalse(recipe.should_build(arch)) |
| 156 | + |
| 157 | + mock_exists.return_value = False |
| 158 | + self.assertTrue(recipe.should_build(arch)) |
| 159 | + |
| 160 | + @mock.patch('pythonforandroid.recipe.Recipe.get_libraries') |
| 161 | + @mock.patch('pythonforandroid.recipe.Recipe.install_libs') |
| 162 | + def test_do_install_libs(self, mock_install_libs, mock_get_libraries): |
| 163 | + mock_get_libraries.return_value = { |
| 164 | + '/build_lib/libsample1.so', |
| 165 | + '/build_lib/libsample2.so', |
| 166 | + } |
| 167 | + self.ctx.recipe_build_order = [ |
| 168 | + "hostpython3", |
| 169 | + "openssl", |
| 170 | + "python3", |
| 171 | + "sdl2", |
| 172 | + "kivy", |
| 173 | + ] |
| 174 | + arch = ArchAarch_64(self.ctx) |
| 175 | + recipe = Recipe.get_recipe('openssl', self.ctx) |
| 176 | + recipe.do_install_libs(arch) |
| 177 | + mock_install_libs.assert_called_once_with( |
| 178 | + arch, *mock_get_libraries.return_value |
| 179 | + ) |
0 commit comments