@@ -28,7 +28,7 @@ def _gen_file_data(idx=0):
28
28
file_data = (
29
29
"--test-file_data-name-%d--" % idx ,
30
30
filepath ,
31
- "--test-file_data-modname--" ,
31
+ "--test-file_data-modname-%d--" % idx ,
32
32
)
33
33
return file_data
34
34
@@ -59,6 +59,20 @@ def process_module(self, _astroid):
59
59
self .data .append (record )
60
60
61
61
62
+ class ExtraSequentialTestChecker (SequentialTestChecker ):
63
+ """ A checker that does not need to consolidate data across run invocations """
64
+
65
+ name = "extra-sequential-checker"
66
+ test_data = "extra-sequential"
67
+
68
+
69
+ class ThirdSequentialTestChecker (SequentialTestChecker ):
70
+ """ A checker that does not need to consolidate data across run invocations """
71
+
72
+ name = "third-sequential-checker"
73
+ test_data = "third-sequential"
74
+
75
+
62
76
class TestCheckParallelFramework :
63
77
""" Tests the check_parallel() function's framework """
64
78
@@ -259,3 +273,114 @@ def test_invoke_single_job(self):
259
273
"warning" : 0 ,
260
274
} == linter .stats
261
275
assert linter .msg_status == 0 , "We expect a single-file check to exit cleanly"
276
+
277
+ @pytest .mark .parametrize (
278
+ "num_files,num_jobs,num_checkers" ,
279
+ [
280
+ (1 , 2 , 1 ),
281
+ (1 , 2 , 2 ),
282
+ (1 , 2 , 3 ),
283
+ (2 , 2 , 1 ),
284
+ (2 , 2 , 2 ),
285
+ (2 , 2 , 3 ),
286
+ (3 , 2 , 1 ),
287
+ (3 , 2 , 2 ),
288
+ (3 , 2 , 3 ),
289
+ (3 , 1 , 1 ),
290
+ (3 , 1 , 2 ),
291
+ (3 , 1 , 3 ),
292
+ (3 , 5 , 1 ),
293
+ (3 , 5 , 2 ),
294
+ (3 , 5 , 3 ),
295
+ (10 , 2 , 1 ),
296
+ (10 , 2 , 2 ),
297
+ (10 , 2 , 3 ),
298
+ (2 , 10 , 1 ),
299
+ (2 , 10 , 2 ),
300
+ (2 , 10 , 3 ),
301
+ ],
302
+ )
303
+ def test_compare_workers_to_single_proc (self , num_files , num_jobs , num_checkers ):
304
+ """ Compares the 3 key parameters for check_parallel() produces the same results
305
+
306
+ The intent here is to ensure that the check_parallel() operates on each file,
307
+ without ordering issues, irespective of the number of workers used and the
308
+ number of checkers applied.
309
+
310
+ This test becomes mre important if we want to change how we paraterise the
311
+ checkers, for example if we aim to batch the files across jobs. """
312
+ print (
313
+ (
314
+ "{buff} {num_files} files, {num_jobs} jobs, {num_checkers} checkers "
315
+ "{buff}"
316
+ ).format (
317
+ buff = "_" * 4 ,
318
+ num_files = num_files ,
319
+ num_jobs = num_jobs ,
320
+ num_checkers = num_checkers ,
321
+ )
322
+ )
323
+
324
+ # define the stats we expect to get back from the runs, these should only vary
325
+ # with the number of files.
326
+ expected_stats = {
327
+ "by_module" : {
328
+ "--test-file_data-name-%d--"
329
+ % idx : {
330
+ "convention" : 0 ,
331
+ "error" : 0 ,
332
+ "fatal" : 0 ,
333
+ "info" : 0 ,
334
+ "refactor" : 0 ,
335
+ "statement" : 18 ,
336
+ "warning" : 0 ,
337
+ }
338
+ for idx in range (num_files )
339
+ },
340
+ "by_msg" : {},
341
+ "convention" : 0 ,
342
+ "error" : 0 ,
343
+ "fatal" : 0 ,
344
+ "info" : 0 ,
345
+ "refactor" : 0 ,
346
+ "statement" : 18 * num_files ,
347
+ "warning" : 0 ,
348
+ }
349
+
350
+ file_infos = _gen_file_datas (num_files )
351
+
352
+ # Loop for single-proc and mult-proc so we can ensure the same linter-config
353
+ for do_single_proc in range (2 ):
354
+ linter = PyLinter (reporter = Reporter ())
355
+
356
+ # Assign between 1 and 3 checkers to the linter, they should not change the
357
+ # results of the lint
358
+ linter .register_checker (SequentialTestChecker (linter ))
359
+ if num_checkers > 1 :
360
+ linter .register_checker (ExtraSequentialTestChecker (linter ))
361
+ if num_checkers > 2 :
362
+ linter .register_checker (ThirdSequentialTestChecker (linter ))
363
+
364
+ if do_single_proc :
365
+ # establish the baseline
366
+ print ("single proc, via linter._check_files" )
367
+ assert (
368
+ linter .config .jobs == 1
369
+ ), "jobs>1 are ignored when calling _check_files"
370
+ linter ._check_files (linter .get_ast , file_infos )
371
+ assert linter .msg_status == 0 , "We should not fail the lint"
372
+ stats_single_proc = linter .stats
373
+ else :
374
+ print ("check_parallel" )
375
+ check_parallel (
376
+ linter , jobs = num_jobs , files = file_infos , arguments = None ,
377
+ )
378
+ stats_check_parallel = linter .stats
379
+ assert linter .msg_status == 0 , "We should not fail the lint"
380
+
381
+ assert (
382
+ stats_single_proc == stats_check_parallel
383
+ ), "Single-proc and check_parallel() should return the same thing"
384
+ assert (
385
+ stats_check_parallel == expected_stats
386
+ ), "The lint is returning unexpected results, has something changed?"
0 commit comments