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