@@ -164,20 +164,27 @@ def test_resolve_build_directory(tmp_path, dir_list, build_dir_tree, ref_path):
164164 assert cmake .build_dir == tmp_path / cmake .DEFAULT_BUILD_DIR if dir_list is None else dir_list [0 ]
165165
166166
167- @pytest .mark .parametrize ('system' , ['Linux' , 'Darwin' , 'Windows' ])
168- @pytest .mark .parametrize ('no_cmake_configure' , [False , True ])
169- def test_setup_cmake_args ( # noqa: PLR0912, PLR0915, C901
170- mocker , system , no_cmake_configure
171- ):
172- original_system = platform .system ()
173-
174- def system_stub ():
175- return system
176-
177- mocker .patch ('platform.system' , system_stub )
178-
179- cmake = CMakeCommand ()
180-
167+ def _assert_args_in_cmake_args (cmake_args , items , format_str = '{}' ):
168+ """Helper to verify items are present in cmake_args."""
169+ for item in items :
170+ expected = format_str .format (item )
171+ assert any (expected in arg for arg in cmake_args ), f'Expected { expected } in cmake_args'
172+
173+
174+ def _assert_platform_args (cmake_args , args ):
175+ """Helper to verify platform-specific args."""
176+ platform_config = {
177+ 'Linux' : args .linux ,
178+ 'Darwin' : args .mac ,
179+ 'Windows' : args .win ,
180+ }
181+ current_platform = platform .system ()
182+ if current_platform in platform_config :
183+ _assert_args_in_cmake_args (cmake_args , platform_config [current_platform ])
184+
185+
186+ def _create_test_args (original_system , no_cmake_configure ):
187+ """Create test arguments namespace."""
181188 args = argparse .Namespace ()
182189 args .detect_configured_files = True
183190 args .no_cmake_configure = no_cmake_configure
@@ -202,6 +209,17 @@ def system_stub():
202209 args .linux = ['LNX_A' , 'LNX_B' ]
203210 args .mac = ['MAC_A' , 'MAC_B' ]
204211 args .win = ['WIN_A' , 'WIN_B' ]
212+ return args
213+
214+
215+ @pytest .mark .parametrize ('system' , ['Linux' , 'Darwin' , 'Windows' ])
216+ @pytest .mark .parametrize ('no_cmake_configure' , [False , True ])
217+ def test_setup_cmake_args (mocker , system , no_cmake_configure ):
218+ original_system = platform .system ()
219+ mocker .patch ('platform.system' , lambda : system )
220+
221+ cmake = CMakeCommand ()
222+ args = _create_test_args (original_system , no_cmake_configure )
205223
206224 assert cmake .source_dir is None
207225 assert cmake .build_dir is None
@@ -220,32 +238,18 @@ def system_stub():
220238 assert '-GNinja' in cmake .cmake_args
221239 assert '-A64' in cmake .cmake_args
222240 assert '-Tclang-toolset' in cmake .cmake_args
223-
224241 assert '-Wdev' in cmake .cmake_args
225242 assert '-Wno_dev' in cmake .cmake_args
226243
227244 # The arguments are not added to cmake.cmake_args since we only want to add them during a CMake configure call
228245 assert '--trace-expand' not in cmake .cmake_args
229246 assert '--trace-format=json-v1' not in cmake .cmake_args
230247
231- for define in args .defines :
232- assert any (define in arg for arg in cmake .cmake_args )
233- for undefine in args .undefines :
234- assert any (undefine in arg for arg in cmake .cmake_args )
235- for error in args .errors :
236- assert any (f'-Werror={ error } ' in arg for arg in cmake .cmake_args )
237- for no_error in args .no_errors :
238- assert any (f'-Wno-error={ no_error } ' in arg for arg in cmake .cmake_args )
239-
240- if platform .system () == 'Linux' :
241- for linux in args .linux :
242- assert any (linux in arg for arg in cmake .cmake_args )
243- elif platform .system () == 'Darwin' :
244- for mac in args .mac :
245- assert any (mac in arg for arg in cmake .cmake_args )
246- elif platform .system () == 'Windows' :
247- for win in args .win :
248- assert any (win in arg for arg in cmake .cmake_args )
248+ _assert_args_in_cmake_args (cmake .cmake_args , args .defines )
249+ _assert_args_in_cmake_args (cmake .cmake_args , args .undefines )
250+ _assert_args_in_cmake_args (cmake .cmake_args , args .errors , '-Werror={}' )
251+ _assert_args_in_cmake_args (cmake .cmake_args , args .no_errors , '-Wno-error={}' )
252+ _assert_platform_args (cmake .cmake_args , args )
249253
250254
251255@pytest .mark .parametrize ('detect_configured_files' , [False , True ], ids = ['no_trace' , 'w_trace' ])
@@ -261,12 +265,10 @@ def test_configure_cmake( # noqa: PLR0917
261265 detect_configured_files ,
262266):
263267 sys_exit = mocker .patch ('sys.exit' )
264- FileLock = mocker .MagicMock (filelock .FileLock ) # noqa: N806
265- mocker .patch (filelock_module_name , FileLock )
266- InterProcessReaderWriterLock = mocker .MagicMock ( # noqa: N806
267- fasteners .InterProcessReaderWriterLock
268- )
269- mocker .patch (interprocess_rw_lock_module_name , InterProcessReaderWriterLock )
268+ mock_file_lock = mocker .MagicMock (filelock .FileLock )
269+ mocker .patch (filelock_module_name , mock_file_lock )
270+ mock_rw_lock = mocker .MagicMock (fasteners .InterProcessReaderWriterLock )
271+ mocker .patch (interprocess_rw_lock_module_name , mock_rw_lock )
270272 configure = mocker .Mock (return_value = returncode )
271273 mocker .patch (internal_cmake_configure_name , configure )
272274 parse_log = mocker .patch ('cmake_pc_hooks._cmake.CMakeCommand._parse_cmake_trace_log' )
@@ -289,17 +291,17 @@ def test_configure_cmake( # noqa: PLR0917
289291 # ----------------------------------
290292
291293 if no_cmake_configure :
292- FileLock .assert_not_called ()
293- InterProcessReaderWriterLock .assert_not_called ()
294+ mock_file_lock .assert_not_called ()
295+ mock_rw_lock .assert_not_called ()
294296 configure .assert_not_called ()
295297 return
296298
297- FileLock .assert_called_once_with (build_dir / '_cmake_configure_try_lock' )
298- InterProcessReaderWriterLock .assert_called_once_with (build_dir / '_cmake_configure_lock' )
299+ mock_file_lock .assert_called_once_with (build_dir / '_cmake_configure_try_lock' )
300+ mock_rw_lock .assert_called_once_with (build_dir / '_cmake_configure_lock' )
299301 configure .assert_called_once_with (
300302 lock_files = (
301- InterProcessReaderWriterLock .call_args [0 ][0 ],
302- FileLock .call_args [0 ][0 ],
303+ mock_rw_lock .call_args [0 ][0 ],
304+ mock_file_lock .call_args [0 ][0 ],
303305 ),
304306 clean_build = clean_build ,
305307 )
@@ -324,14 +326,12 @@ def timeout(blocking): # noqa: ARG001
324326
325327 args = {'acquire.side_effect' : timeout }
326328 file_lock = mocker .MagicMock (filelock .FileLock , ** args )
327- FileLock = mocker .MagicMock (filelock .FileLock , return_value = file_lock ) # noqa: N806
328- mocker .patch (filelock_module_name , FileLock )
329+ mock_file_lock = mocker .MagicMock (filelock .FileLock , return_value = file_lock )
330+ mocker .patch (filelock_module_name , mock_file_lock )
329331
330332 interprocess_lock = mocker .MagicMock ()
331- InterProcessReaderWriterLock = mocker .MagicMock ( # noqa: N806
332- return_value = interprocess_lock
333- )
334- mocker .patch (interprocess_rw_lock_module_name , InterProcessReaderWriterLock )
333+ mock_rw_lock = mocker .MagicMock (return_value = interprocess_lock )
334+ mocker .patch (interprocess_rw_lock_module_name , mock_rw_lock )
335335 configure = mocker .Mock (return_value = 0 )
336336 mocker .patch (internal_cmake_configure_name , configure )
337337
@@ -349,21 +349,19 @@ def timeout(blocking): # noqa: ARG001
349349
350350 # ----------------------------------
351351
352- FileLock .assert_called_once ()
353- InterProcessReaderWriterLock .assert_called_once ()
352+ mock_file_lock .assert_called_once ()
353+ mock_rw_lock .assert_called_once ()
354354 interprocess_lock .read_lock .assert_called_once ()
355355 configure .assert_not_called ()
356356
357357
358358def test_configure_invalid (mocker ):
359359 mocker .patch ('sys.exit' , side_effect = ExitError )
360360
361- FileLock = mocker .MagicMock (filelock .FileLock ) # noqa: N806
362- mocker .patch (filelock_module_name , FileLock )
363- InterProcessReaderWriterLock = mocker .MagicMock ( # noqa: N806
364- fasteners .InterProcessReaderWriterLock
365- )
366- mocker .patch (interprocess_rw_lock_module_name , InterProcessReaderWriterLock )
361+ mock_file_lock = mocker .MagicMock (filelock .FileLock )
362+ mocker .patch (filelock_module_name , mock_file_lock )
363+ mock_rw_lock = mocker .MagicMock (fasteners .InterProcessReaderWriterLock )
364+ mocker .patch (interprocess_rw_lock_module_name , mock_rw_lock )
367365 configure = mocker .Mock (return_value = 1 )
368366 mocker .patch (internal_cmake_configure_name , configure )
369367
0 commit comments