Skip to content

Commit 82ee799

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 814fda3 commit 82ee799

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
@@ -28,7 +28,7 @@ def _gen_file_data(idx=0):
2828
file_data = (
2929
"--test-file_data-name-%d--" % idx,
3030
filepath,
31-
"--test-file_data-modname--",
31+
"--test-file_data-modname-%d--" % idx,
3232
)
3333
return file_data
3434

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

6161

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+
6276
class TestCheckParallelFramework:
6377
""" Tests the check_parallel() function's framework """
6478

@@ -259,3 +273,114 @@ def test_invoke_single_job(self):
259273
"warning": 0,
260274
} == linter.stats
261275
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

Comments
 (0)