|
4 | 4 |
|
5 | 5 | from __future__ import annotations
|
6 | 6 |
|
| 7 | +import re |
7 | 8 | import os
|
| 9 | +import timeit |
8 | 10 | from pathlib import Path
|
9 | 11 |
|
10 | 12 | import pytest
|
@@ -111,6 +113,41 @@ def test_unknown_py_version(capsys: CaptureFixture) -> None:
|
111 | 113 | assert "the-newest has an invalid format, should be a version string." in output.err
|
112 | 114 |
|
113 | 115 |
|
| 116 | +CSV_REGEX_COMMA_CASES = [ |
| 117 | + ("foo", ["foo"]), |
| 118 | + ("foo,bar", ["foo", "bar"]), |
| 119 | + ("foo, bar", ["foo", "bar"]), |
| 120 | + ("foo, bar{1,3}", ["foo", "bar{1,3}"]), |
| 121 | +] |
| 122 | + |
| 123 | +@pytest.mark.parametrize("input,expected", CSV_REGEX_COMMA_CASES) |
| 124 | +def test_csv_regex_comma_in_quantifier(input, expected) -> None: |
| 125 | + """Check that we correctly parse a comma-separated regex when there are one |
| 126 | + or more commas within quantifier expressions. |
| 127 | + """ |
| 128 | + def _template_run(input): |
| 129 | + r = Run( |
| 130 | + [str(EMPTY_MODULE), rf"--bad-names-rgx={input}"], |
| 131 | + exit=False, |
| 132 | + ) |
| 133 | + return r.linter.config.bad_names_rgxs |
| 134 | + assert _template_run(input) == [re.compile(regex) for regex in expected] |
| 135 | + |
| 136 | + # Catch trivially nonlinear performance |
| 137 | + small_input_time = timeit.timeit( |
| 138 | + "_template_run(input*100)", |
| 139 | + globals=locals(), |
| 140 | + number=10, |
| 141 | + ) |
| 142 | + large_input_time = timeit.timeit( |
| 143 | + "_template_run(input*1000)", |
| 144 | + globals=locals(), |
| 145 | + number=10, |
| 146 | + ) |
| 147 | + fudge_factor = 3 |
| 148 | + assert large_input_time < small_input_time * 10 * fudge_factor |
| 149 | + |
| 150 | + |
114 | 151 | def test_short_verbose(capsys: CaptureFixture) -> None:
|
115 | 152 | """Check that we correctly handle the -v flag."""
|
116 | 153 | Run([str(EMPTY_MODULE), "-v"], exit=False)
|
|
0 commit comments