@@ -90,24 +90,27 @@ def test_build_arch(
90
90
android_ndk = self .ctx ._ndk_dir
91
91
)
92
92
mock_glob .return_value = ["llvm" ]
93
+
94
+ # Since the following mocks are dynamic,
95
+ # we mock it inside a Context Manager
93
96
with mock .patch (
94
97
f"pythonforandroid.recipes.{ self .recipe_name } .sh.Command"
95
98
) as mock_sh_command , mock .patch (
96
99
f"pythonforandroid.recipes.{ self .recipe_name } .sh.make"
97
100
) as mock_make :
98
101
self .recipe .build_arch (self .arch )
99
102
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 ()
111
114
112
115
113
116
class BaseTestForCmakeRecipe (BaseTestForMakeRecipe ):
@@ -135,17 +138,20 @@ def test_build_arch(
135
138
android_ndk = self .ctx ._ndk_dir
136
139
)
137
140
mock_glob .return_value = ["llvm" ]
141
+
142
+ # Since the following mocks are dynamic,
143
+ # we mock it inside a Context Manager
138
144
with mock .patch (
139
145
f"pythonforandroid.recipes.{ self .recipe_name } .sh.make"
140
146
) as mock_make , mock .patch (
141
147
f"pythonforandroid.recipes.{ self .recipe_name } .sh.cmake"
142
148
) as mock_cmake :
143
149
self .recipe .build_arch (self .arch )
144
150
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