8
8
9
9
import pytest
10
10
11
- from pylint .checkers import similar
11
+ from pylint .checkers import symilar
12
12
from pylint .constants import IS_PYPY , PY39_PLUS
13
13
from pylint .lint import PyLinter
14
14
from pylint .testutils import GenericTestReporter as Reporter
31
31
def test_ignore_comments () -> None :
32
32
output = StringIO ()
33
33
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
34
- similar .Run (["--ignore-comments" , SIMILAR1 , SIMILAR2 ])
34
+ symilar .Run (["--ignore-comments" , SIMILAR1 , SIMILAR2 ])
35
35
assert ex .value .code == 0
36
36
assert (
37
37
output .getvalue ().strip ()
@@ -60,7 +60,7 @@ def test_ignore_comments() -> None:
60
60
def test_ignore_docstrings () -> None :
61
61
output = StringIO ()
62
62
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
63
- similar .Run (["--ignore-docstrings" , SIMILAR1 , SIMILAR2 ])
63
+ symilar .Run (["--ignore-docstrings" , SIMILAR1 , SIMILAR2 ])
64
64
assert ex .value .code == 0
65
65
assert (
66
66
output .getvalue ().strip ()
@@ -95,7 +95,7 @@ def test_ignore_docstrings() -> None:
95
95
def test_ignore_imports () -> None :
96
96
output = StringIO ()
97
97
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
98
- similar .Run (["--ignore-imports" , SIMILAR1 , SIMILAR2 ])
98
+ symilar .Run (["--ignore-imports" , SIMILAR1 , SIMILAR2 ])
99
99
assert ex .value .code == 0
100
100
assert (
101
101
output .getvalue ().strip ()
@@ -108,7 +108,7 @@ def test_ignore_imports() -> None:
108
108
def test_multiline_imports () -> None :
109
109
output = StringIO ()
110
110
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
111
- similar .Run ([MULTILINE , MULTILINE ])
111
+ symilar .Run ([MULTILINE , MULTILINE ])
112
112
assert ex .value .code == 0
113
113
assert (
114
114
output .getvalue ().strip ()
@@ -138,7 +138,7 @@ def test_multiline_imports() -> None:
138
138
def test_ignore_multiline_imports () -> None :
139
139
output = StringIO ()
140
140
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
141
- similar .Run (["--ignore-imports" , MULTILINE , MULTILINE ])
141
+ symilar .Run (["--ignore-imports" , MULTILINE , MULTILINE ])
142
142
assert ex .value .code == 0
143
143
assert (
144
144
output .getvalue ().strip ()
@@ -151,7 +151,7 @@ def test_ignore_multiline_imports() -> None:
151
151
def test_ignore_signatures_fail () -> None :
152
152
output = StringIO ()
153
153
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
154
- similar .Run ([SIMILAR5 , SIMILAR6 ])
154
+ symilar .Run ([SIMILAR5 , SIMILAR6 ])
155
155
assert ex .value .code == 0
156
156
assert (
157
157
output .getvalue ().strip ()
@@ -189,7 +189,7 @@ def example():
189
189
def test_ignore_signatures_pass () -> None :
190
190
output = StringIO ()
191
191
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
192
- similar .Run (["--ignore-signatures" , SIMILAR5 , SIMILAR6 ])
192
+ symilar .Run (["--ignore-signatures" , SIMILAR5 , SIMILAR6 ])
193
193
assert ex .value .code == 0
194
194
assert (
195
195
output .getvalue ().strip ()
@@ -202,7 +202,7 @@ def test_ignore_signatures_pass() -> None:
202
202
def test_ignore_signatures_class_methods_fail () -> None :
203
203
output = StringIO ()
204
204
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
205
- similar .Run ([SIMILAR_CLS_B , SIMILAR_CLS_A ])
205
+ symilar .Run ([SIMILAR_CLS_B , SIMILAR_CLS_A ])
206
206
assert ex .value .code == 0
207
207
assert (
208
208
output .getvalue ().strip ()
@@ -248,7 +248,7 @@ def _internal_func(
248
248
def test_ignore_signatures_class_methods_pass () -> None :
249
249
output = StringIO ()
250
250
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
251
- similar .Run (["--ignore-signatures" , SIMILAR_CLS_B , SIMILAR_CLS_A ])
251
+ symilar .Run (["--ignore-signatures" , SIMILAR_CLS_B , SIMILAR_CLS_A ])
252
252
assert ex .value .code == 0
253
253
assert (
254
254
output .getvalue ().strip ()
@@ -261,7 +261,7 @@ def test_ignore_signatures_class_methods_pass() -> None:
261
261
def test_ignore_signatures_empty_functions_fail () -> None :
262
262
output = StringIO ()
263
263
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
264
- similar .Run ([EMPTY_FUNCTION_1 , EMPTY_FUNCTION_2 ])
264
+ symilar .Run ([EMPTY_FUNCTION_1 , EMPTY_FUNCTION_2 ])
265
265
assert ex .value .code == 0
266
266
assert (
267
267
output .getvalue ().strip ()
@@ -285,7 +285,7 @@ def test_ignore_signatures_empty_functions_fail() -> None:
285
285
def test_ignore_signatures_empty_functions_pass () -> None :
286
286
output = StringIO ()
287
287
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
288
- similar .Run (["--ignore-signatures" , EMPTY_FUNCTION_1 , EMPTY_FUNCTION_2 ])
288
+ symilar .Run (["--ignore-signatures" , EMPTY_FUNCTION_1 , EMPTY_FUNCTION_2 ])
289
289
assert ex .value .code == 0
290
290
assert (
291
291
output .getvalue ().strip ()
@@ -298,15 +298,15 @@ def test_ignore_signatures_empty_functions_pass() -> None:
298
298
def test_no_hide_code_with_imports () -> None :
299
299
output = StringIO ()
300
300
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
301
- similar .Run (["--ignore-imports" ] + 2 * [HIDE_CODE_WITH_IMPORTS ])
301
+ symilar .Run (["--ignore-imports" ] + 2 * [HIDE_CODE_WITH_IMPORTS ])
302
302
assert ex .value .code == 0
303
303
assert "TOTAL lines=32 duplicates=0 percent=0.00" in output .getvalue ()
304
304
305
305
306
306
def test_ignore_nothing () -> None :
307
307
output = StringIO ()
308
308
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
309
- similar .Run ([SIMILAR1 , SIMILAR2 ])
309
+ symilar .Run ([SIMILAR1 , SIMILAR2 ])
310
310
assert ex .value .code == 0
311
311
assert (
312
312
output .getvalue ().strip ()
@@ -329,7 +329,7 @@ def test_ignore_nothing() -> None:
329
329
def test_lines_without_meaningful_content_do_not_trigger_similarity () -> None :
330
330
output = StringIO ()
331
331
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
332
- similar .Run ([SIMILAR3 , SIMILAR4 ])
332
+ symilar .Run ([SIMILAR3 , SIMILAR4 ])
333
333
assert ex .value .code == 0
334
334
assert (
335
335
output .getvalue ().strip ()
@@ -362,7 +362,7 @@ def test_help() -> None:
362
362
output = StringIO ()
363
363
with redirect_stdout (output ):
364
364
try :
365
- similar .Run (["--help" ])
365
+ symilar .Run (["--help" ])
366
366
except SystemExit as ex :
367
367
assert ex .code == 0
368
368
else :
@@ -373,18 +373,18 @@ def test_no_args() -> None:
373
373
output = StringIO ()
374
374
with redirect_stdout (output ):
375
375
try :
376
- similar .Run ([])
376
+ symilar .Run ([])
377
377
except SystemExit as ex :
378
378
assert ex .code == 1
379
379
else :
380
380
pytest .fail ("not system exit" )
381
381
382
382
383
383
def test_get_map_data () -> None :
384
- """Tests that a SimilarChecker can return and reduce mapped data."""
384
+ """Tests that a SymilarChecker can return and reduce mapped data."""
385
385
linter = PyLinter (reporter = Reporter ())
386
386
# Add a parallel checker to ensure it can map and reduce
387
- linter .register_checker (similar . SimilarChecker (linter ))
387
+ linter .register_checker (symilar . SimilaritiesChecker (linter ))
388
388
source_streams = (
389
389
str (INPUT / "similar_lines_a.py" ),
390
390
str (INPUT / "similar_lines_b.py" ),
@@ -473,7 +473,7 @@ def test_get_map_data() -> None:
473
473
474
474
# Manually perform a 'map' type function
475
475
for source_fname in source_streams :
476
- sim = similar . SimilarChecker (PyLinter ())
476
+ sim = symilar . SimilaritiesChecker (PyLinter ())
477
477
sim .linter .set_option ("ignore-imports" , False )
478
478
sim .linter .set_option ("ignore-signatures" , False )
479
479
with open (source_fname , encoding = "utf-8" ) as stream :
@@ -494,7 +494,7 @@ def test_get_map_data() -> None:
494
494
def test_set_duplicate_lines_to_zero () -> None :
495
495
output = StringIO ()
496
496
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
497
- similar .Run (["--duplicates=0" , SIMILAR1 , SIMILAR2 ])
497
+ symilar .Run (["--duplicates=0" , SIMILAR1 , SIMILAR2 ])
498
498
assert ex .value .code == 0
499
499
assert output .getvalue () == ""
500
500
@@ -504,7 +504,7 @@ def test_bad_equal_short_form_option(v: str) -> None:
504
504
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
505
505
output = StringIO ()
506
506
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
507
- similar .Run ([f"-{ v } =0" , SIMILAR1 , SIMILAR2 ])
507
+ symilar .Run ([f"-{ v } =0" , SIMILAR1 , SIMILAR2 ])
508
508
assert ex .value .code == 2
509
509
assert "invalid literal for int() with base 10: '=0'" in output .getvalue ()
510
510
@@ -514,7 +514,7 @@ def test_space_short_form_option(v: str) -> None:
514
514
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
515
515
output = StringIO ()
516
516
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
517
- similar .Run ([f"-{ v } 2" , SIMILAR1 , SIMILAR2 ])
517
+ symilar .Run ([f"-{ v } 2" , SIMILAR1 , SIMILAR2 ])
518
518
assert ex .value .code == 0
519
519
assert "similar lines in" in output .getvalue ()
520
520
@@ -523,6 +523,6 @@ def test_bad_short_form_option() -> None:
523
523
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
524
524
output = StringIO ()
525
525
with redirect_stdout (output ), pytest .raises (SystemExit ) as ex :
526
- similar .Run (["-j=0" , SIMILAR1 , SIMILAR2 ])
526
+ symilar .Run (["-j=0" , SIMILAR1 , SIMILAR2 ])
527
527
assert ex .value .code == 2
528
528
assert "option -j not recognized" in output .getvalue ()
0 commit comments