Skip to content

Commit

Permalink
✅ improve sh mocking reliability
Browse files Browse the repository at this point in the history
Make sure the mocking also works on setup without cmake or make.
Build dependencies should not be required to run uni tests.
The error was:
```
AttributeError: <module 'sh' from 'venv/lib/python3.11/site-packages/sh.py'> does not have the attribute 'cmake'
```
  • Loading branch information
AndreMiras committed Mar 7, 2024
1 parent 0047b4f commit 9ef3f9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/recipes/recipe_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_build_arch(
with mock.patch(
f"pythonforandroid.recipes.{self.recipe_name}.sh.Command"
) as mock_sh_command, mock.patch(
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
f"pythonforandroid.recipes.{self.recipe_name}.sh.make", create=True
) as mock_make:
self.recipe.build_arch(self.arch)

Expand Down Expand Up @@ -130,9 +130,9 @@ def test_build_arch(
# Since the following mocks are dynamic,
# we mock it inside a Context Manager
with mock.patch(
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
f"pythonforandroid.recipes.{self.recipe_name}.sh.make", create=True
) as mock_make, mock.patch(
f"pythonforandroid.recipes.{self.recipe_name}.sh.cmake"
f"pythonforandroid.recipes.{self.recipe_name}.sh.cmake", create=True
) as mock_cmake:
self.recipe.build_arch(self.arch)

Expand Down
4 changes: 2 additions & 2 deletions tests/recipes/test_openal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class TestOpenalRecipe(BaseTestForCmakeRecipe, unittest.TestCase):
"""
recipe_name = "openal"

@mock.patch("pythonforandroid.recipes.openal.sh.cmake")
@mock.patch("pythonforandroid.recipes.openal.sh.make")
@mock.patch("pythonforandroid.recipes.openal.sh.cmake", create=True)
@mock.patch("pythonforandroid.recipes.openal.sh.make", create=True)
@mock.patch("pythonforandroid.recipes.openal.sh.cp")
@mock.patch("pythonforandroid.util.chdir")
@mock.patch("pythonforandroid.build.ensure_dir")
Expand Down

0 comments on commit 9ef3f9f

Please sign in to comment.