Skip to content

Commit 80104c4

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 fcc71f2 commit 80104c4

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

tests/recipes/recipe_lib_test.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,27 @@ 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 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()
105-
for command in self.sh_command_calls:
106-
self.assertIn(
107-
mock.call(command),
108-
mock_sh_command.mock_calls,
109-
)
110-
mock_make.assert_called()
103+
# make sure that the mocked methods are actually called
104+
for command in self.sh_command_calls:
105+
self.assertIn(
106+
mock.call(command),
107+
mock_sh_command.mock_calls,
108+
)
109+
mock_make.assert_called()
110+
mock_glob.assert_called()
111+
mock_ensure_dir.assert_called()
112+
mock_current_directory.assert_called()
113+
mock_find_executable.assert_called()
111114

112115

113116
class BaseTestForCmakeRecipe(BaseTestForMakeRecipe):
@@ -135,17 +138,20 @@ def test_build_arch(
135138
android_ndk=self.ctx._ndk_dir
136139
)
137140
mock_glob.return_value = ["llvm"]
141+
142+
# Since the following mocks are dynamic,
143+
# we mock it inside a Context Manager
138144
with mock.patch(
139145
f"pythonforandroid.recipes.{self.recipe_name}.sh.make"
140146
) as mock_make, mock.patch(
141147
f"pythonforandroid.recipes.{self.recipe_name}.sh.cmake"
142148
) as mock_cmake:
143149
self.recipe.build_arch(self.arch)
144150

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

0 commit comments

Comments
 (0)