Skip to content

Commit eb11081

Browse files
authored
🚑 Fix test_should_build (kivy#2193)
Because, I forgot to implement it when I first wrote the test at 535b39d **Note:** I replaced `os.path.isfile` by `pathlib.Path(<any-path>).is_file()` because: - It seems that when trying to mock `isfile` function, doesn't work as expected (is completely ignored, unless we import the whole `os.path` module) - Given the above situation, we must modify the import, so better use the `pathlib` implementation, wich it has several advantages (it handles any kind of path automatically, no matter the platform)
1 parent 535b39d commit eb11081

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pythonforandroid/recipes/python3/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from multiprocessing import cpu_count
66
from os import environ
7-
from os.path import dirname, exists, join, isfile
7+
from os.path import dirname, exists, join
8+
from pathlib import Path
89
from shutil import copy2
910

1011
from pythonforandroid.logger import info, warning, shprint
@@ -165,7 +166,7 @@ def link_root(self, arch_name):
165166
return join(self.get_build_dir(arch_name), 'android-build')
166167

167168
def should_build(self, arch):
168-
return not isfile(join(self.link_root(arch.arch), self._libpython))
169+
return not Path(self.link_root(arch.arch), self._libpython).is_file()
169170

170171
def prebuild_arch(self, arch):
171172
super().prebuild_arch(arch)

tests/recipes/test_python3.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def test_property__libpython(self):
2222
f'libpython{self.recipe.major_minor_version_string}m.so'
2323
)
2424

25-
def test_should_build(self):
26-
expected_include_dir = join(
27-
self.recipe.get_build_dir(self.arch.arch), 'Include',
28-
)
29-
self.assertEqual(
30-
expected_include_dir, self.recipe.include_root(self.arch.arch)
31-
)
25+
@mock.patch('pythonforandroid.recipes.python3.Path.is_file')
26+
def test_should_build(self, mock_is_file):
27+
# in case that python lib exists, we shouldn't trigger the build
28+
self.assertFalse(self.recipe.should_build(self.arch))
29+
# in case that python lib doesn't exist, we should trigger the build
30+
mock_is_file.return_value = False
31+
self.assertTrue(self.recipe.should_build(self.arch))
3232

3333
def test_include_root(self):
3434
expected_include_dir = join(

0 commit comments

Comments
 (0)