Skip to content

Commit 98255f7

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 daa7189 commit 98255f7

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

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

6060

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

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

0 commit comments

Comments
 (0)