Skip to content

Commit 20fd895

Browse files
committed
check_parallel| Adds paramterised test against #jobs, #files and #checker
These regression tests target future optimisation work for the check_parallel() system.
1 parent 54550d7 commit 20fd895

File tree

1 file changed

+126
-1
lines changed

1 file changed

+126
-1
lines changed

tests/test_check_parallel.py

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _gen_file_data(idx=0):
2929
file_data = (
3030
"--test-file_data-name-%d--" % idx,
3131
filepath,
32-
"--test-file_data-modname--",
32+
"--test-file_data-modname-%d--" % idx,
3333
)
3434
return file_data
3535

@@ -60,6 +60,20 @@ def process_module(self, _astroid):
6060
self.data.append(record)
6161

6262

63+
class ExtraSequentialTestChecker(SequentialTestChecker):
64+
""" A checker that does not need to consolidate data across run invocations """
65+
66+
name = "extra-sequential-checker"
67+
test_data = "extra-sequential"
68+
69+
70+
class ThirdSequentialTestChecker(SequentialTestChecker):
71+
""" A checker that does not need to consolidate data across run invocations """
72+
73+
name = "third-sequential-checker"
74+
test_data = "third-sequential"
75+
76+
6377
class TestCheckParallelFramework:
6478
""" Tests the check_parallel() function's framework """
6579

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

0 commit comments

Comments
 (0)