Skip to content

Commit

Permalink
🚑 Fix test_should_build (#2193)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
opacam authored May 13, 2020
1 parent 535b39d commit eb11081
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from multiprocessing import cpu_count
from os import environ
from os.path import dirname, exists, join, isfile
from os.path import dirname, exists, join
from pathlib import Path
from shutil import copy2

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

def should_build(self, arch):
return not isfile(join(self.link_root(arch.arch), self._libpython))
return not Path(self.link_root(arch.arch), self._libpython).is_file()

def prebuild_arch(self, arch):
super().prebuild_arch(arch)
Expand Down
14 changes: 7 additions & 7 deletions tests/recipes/test_python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def test_property__libpython(self):
f'libpython{self.recipe.major_minor_version_string}m.so'
)

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

def test_include_root(self):
expected_include_dir = join(
Expand Down

0 comments on commit eb11081

Please sign in to comment.