Skip to content

Commit 4f54abc

Browse files
committed
[test] Move mock tests outside context manager...
Because there is no need to do it there. Also rewrote the inline comments.
1 parent 4b1ed62 commit 4f54abc

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tests/recipes/recipe_lib_test.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,29 @@ def test_build_arch(
9090
android_ndk=self.ctx._ndk_dir
9191
)
9292
mock_glob.return_value = ["llvm"]
93+
94+
# Since the following mocks are dynamic,
95+
# we mock/test it inside a Context Manager
9396
with mock.patch(
9497
f"pythonforandroid.recipes.{self.recipe_name}.sh.Command"
9598
) as mock_sh_command, mock.patch(
9699
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
97100
) as mock_make:
98101
self.recipe.build_arch(self.arch)
99102

100-
# make sure that the mocked methods are actually called
101-
mock_glob.assert_called()
102-
mock_ensure_dir.assert_called()
103-
mock_current_directory.assert_called()
104-
mock_find_executable.assert_called()
105103
for command in self.sh_command_calls:
106104
self.assertIn(
107105
mock.call(command),
108106
mock_sh_command.mock_calls,
109107
)
110108
mock_make.assert_called()
111109

110+
# make sure that the mocked methods are actually called
111+
mock_glob.assert_called()
112+
mock_ensure_dir.assert_called()
113+
mock_current_directory.assert_called()
114+
mock_find_executable.assert_called()
115+
112116

113117
class BaseTestForCmakeRecipe(BaseTestForMakeRecipe):
114118
"""
@@ -135,17 +139,21 @@ def test_build_arch(
135139
android_ndk=self.ctx._ndk_dir
136140
)
137141
mock_glob.return_value = ["llvm"]
142+
143+
# Since the following mocks are dynamic,
144+
# we mock/test it inside a Context Manager
138145
with mock.patch(
139146
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
140147
) as mock_make, mock.patch(
141148
f"pythonforandroid.recipes.{self.recipe_name}.sh.cmake"
142149
) as mock_cmake:
143150
self.recipe.build_arch(self.arch)
144151

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()
150152
mock_cmake.assert_called()
151153
mock_make.assert_called()
154+
155+
# make sure that the mocked methods are actually called
156+
mock_glob.assert_called()
157+
mock_ensure_dir.assert_called()
158+
mock_current_directory.assert_called()
159+
mock_find_executable.assert_called()

0 commit comments

Comments
 (0)