|
| 1 | +import os |
| 2 | +import tempfile |
| 3 | +import unittest |
| 4 | +from mock import patch |
| 5 | +from pythonforandroid.archs import ArchARMv7_a |
| 6 | +from pythonforandroid.build import Context |
| 7 | +from pythonforandroid.graph import get_recipe_order_and_bootstrap |
| 8 | +from pythonforandroid.recipe import Recipe |
| 9 | +from pythonforandroid.util import ensure_dir |
| 10 | + |
| 11 | + |
| 12 | +class TestReportLabRecipe(unittest.TestCase): |
| 13 | + |
| 14 | + def setUp(self): |
| 15 | + """ |
| 16 | + Setups recipe and context. |
| 17 | + """ |
| 18 | + self.context = Context() |
| 19 | + self.arch = ArchARMv7_a(self.context) |
| 20 | + self.recipe = Recipe.get_recipe('reportlab', self.context) |
| 21 | + self.recipe.ctx = self.context |
| 22 | + self.bootstrap = None |
| 23 | + recipe_build_order, python_modules, bootstrap = \ |
| 24 | + get_recipe_order_and_bootstrap( |
| 25 | + self.context, [self.recipe.name], self.bootstrap) |
| 26 | + self.context.recipe_build_order = recipe_build_order |
| 27 | + self.context.python_modules = python_modules |
| 28 | + self.context.setup_dirs(tempfile.gettempdir()) |
| 29 | + self.bootstrap = bootstrap |
| 30 | + self.recipe_dir = self.recipe.get_build_dir(self.arch.arch) |
| 31 | + ensure_dir(self.recipe_dir) |
| 32 | + |
| 33 | + def test_prebuild_arch(self): |
| 34 | + """ |
| 35 | + Makes sure `prebuild_arch()` runs without error and patches `setup.py` |
| 36 | + as expected. |
| 37 | + """ |
| 38 | + # `prebuild_arch()` dynamically replaces strings in the `setup.py` file |
| 39 | + setup_path = os.path.join(self.recipe_dir, 'setup.py') |
| 40 | + with open(setup_path, 'w') as setup_file: |
| 41 | + setup_file.write('_FT_LIB_\n') |
| 42 | + setup_file.write('_FT_INC_\n') |
| 43 | + |
| 44 | + # these sh commands are not relevant for the test and need to be mocked |
| 45 | + with \ |
| 46 | <
8000
span class="diff-text-marker">+ patch('sh.patch'), \ |
| 47 | + patch('sh.touch'), \ |
| 48 | + patch('sh.unzip'), \ |
| 49 | + patch('os.path.isfile'): |
| 50 | + self.recipe.prebuild_arch(self.arch) |
| 51 | + # makes sure placeholder got replaced with library and include paths |
| 52 | + with open(setup_path, 'r') as setup_file: |
| 53 | + lines = setup_file.readlines() |
| 54 | + self.assertTrue(lines[0].endswith('freetype/objs/.libs\n')) |
| 55 | + self.assertTrue(lines[1].endswith('freetype/include\n')) |
0 commit comments