8000 Merge pull request #1383 from AndreMiras/feature/ticket1380_unit_test… · bb33bb/python-for-android@9724ebe · GitHub
[go: up one dir, main page]

Skip to content

Commit 9724ebe

Browse files
authored
Merge pull request kivy#1383 from AndreMiras/feature/ticket1380_unit_test_reportlab_recipe
ReportLabRecipe fixes and unit tests, fixes kivy#1380
2 parents 99475fc + dd39888 commit 9724ebe

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

pythonforandroid/recipes/reportlab/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ def prebuild_arch(self, arch):
2626
info('reportlab recipe: ft_lib_dir={}'.format(ft_lib_dir))
2727
info('reportlab recipe: ft_inc_dir={}'.format(ft_inc_dir))
2828
with current_directory(recipe_dir):
29-
sh.ls('-lathr')
3029
ensure_dir(tmp_dir)
3130
pfbfile = os.path.join(tmp_dir, "pfbfer-20070710.zip")
3231
if not os.path.isfile(pfbfile):
3332
sh.wget("http://www.reportlab.com/ftp/pfbfer-20070710.zip", "-O", pfbfile)
3433
sh.unzip("-u", "-d", os.path.join(recipe_dir, "src", "reportlab", "fonts"), pfbfile)
3534
if os.path.isfile("setup.py"):
36-
with open('setup.py', 'rb') as f:
35+
with open('setup.py', 'r') as f:
3736
text = f.read().replace('_FT_LIB_', ft_lib_dir).replace('_FT_INC_', ft_inc_dir)
38-
with open('setup.py', 'wb') as f:
37+
with open('setup.py', 'w') as f:
3938
f.write(text)
4039

4140

tests/recipes/test_reportlab.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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'))

tox.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
envlist = pep8,py27,py3
33

44
[testenv]
5-
deps = pytest
6-
commands = pytest tests/
5+
deps =
6+
mock
7+
pytest
8+
# makes it possible to override pytest args, e.g.
9+
# tox -- tests/test_graph.py
10+
commands = pytest {posargs:tests/}
711

812
[testenv:pep8]
913
deps = flake8

0 commit comments

Comments
 (0)
0