Skip to content

Commit 19da3c2

Browse files
committed
[test] Add BaseTestForCmakeRecipe
1 parent e8e7c24 commit 19da3c2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/recipes/recipe_lib_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,44 @@ def test_build_arch(
108108
mock_sh_command.mock_calls,
109109
)
110110
mock_make.assert_called()
111+
112+
113+
class BaseTestForCmakeRecipe(BaseTestForMakeRecipe):
114+
"""
115+
An unittest for testing any recipe using `cmake`. It inherits from
116+
`BaseTestForMakeRecipe` but we override the build method to match the cmake
117+
build method.
118+
119+
.. note:: Note that Some cmake recipe may need some more specific testing
120+
...but this should cover the basics.
121+
"""
122+
123+
@mock.patch("pythonforandroid.util.chdir")
124+
@mock.patch("pythonforandroid.build.ensure_dir")
125+
@mock.patch("pythonforandroid.archs.glob")
126+
@mock.patch("pythonforandroid.archs.find_executable")
127+
def test_build_arch(
128+
self,
129+
mock_find_executable,
130+
mock_glob,
131+
mock_ensure_dir,
132+
mock_current_directory,
133+
):
134+
mock_find_executable.return_value = self.expected_compiler.format(
135+
android_ndk=self.ctx._ndk_dir
136+
)
137+
mock_glob.return_value = ["llvm"]
138+
with mock.patch(
139+
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
140+
) as mock_make, mock.patch(
141+
f"pythonforandroid.recipes.{self.recipe_name}.sh.cmake"
142+
) as mock_cmake:
143+
self.recipe.build_arch(self.arch)
144+
145+
# make sure that the mocked methods are actually called
146+
mock_glob.assert_called()
147+
mock_ensure_dir.assert_called()
148+
mock_current_directory.assert_called()
149+
mock_find_executable.assert_called()
150+
mock_cmake.assert_called()
151+
mock_make.assert_called()

0 commit comments

Comments
 (0)