awesome

Finished
1
2import sys, pytest, collections, collections.abc, urllib3.exceptions, _pytest.pytester, numpy;
3collections.Mapping = collections.abc.Mapping;
4collections.MutableMapping = collections.abc.MutableMapping;
5collections.MutableSet = collections.abc.MutableSet;
6collections.Sequence = collections.abc.Sequence;
7collections.Callable = collections.abc.Callable;
8collections.Iterable = collections.abc.Iterable;
9collections.Iterator = collections.abc.Iterator;
10urllib3.exceptions.SNIMissingWarning = urllib3.exceptions.DependencyWarning;
11pytest.RemovedInPytest4Warning = DeprecationWarning;
12_pytest.pytester.Testdir = _pytest.pytester.Pytester;
13numpy.PINF = numpy.inf;
14numpy.unicode_ = numpy.str_;
15numpy.bytes_ = numpy.bytes_;
16numpy.float_ = numpy.float64;
17numpy.string_ = numpy.bytes_;
18numpy.NaN = numpy.nan;
19
20
21import re
22import argparse
23from typing import Sequence, Pattern
24
25# Replicate the fixed _regexp_csv_transfomer function
26def _regex_transformer(value: str) -> Pattern[str]:
27 """Return `re.compile(value)`."""
28 try:
29 return re.compile(value)
30 except re.error as e:
31 msg = f"Error in provided regular expression: {value} beginning at index {e.pos}: {e.msg}"
32 raise argparse.ArgumentTypeError(msg) from e
33
34def _splitstrip(string: str, sep: str = ",") -> list[str]:
35 """Return a list of stripped string by splitting the string given as
36 argument on `sep` (',' by default), empty strings are discarded.
37 """
38 return [word.strip() for word in string.split(sep) if word.strip()]
39
40def _check_csv(value) -> Sequence[str]:
41 if isinstance(value, (list, tuple)):
42 return value
43 return _splitstrip(value)
44
45def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
46 """Transforms a comma separated list of regular expressions."""
47 # First, try to split on commas and compile each part
48 # If any part fails to compile, treat the entire value as a single pattern
49 split_patterns = _check_csv(value)
50 patterns: list[Pattern[str]] = []
51
52 # Try to compile each split part
53 split_compilation_errors = []
54 for pattern in split_patterns:
55 try:
56 patterns.append(_regex_transformer(pattern))
57 except argparse.ArgumentTypeError as e:
58 split_compilation_errors.append(e)
59 break
60
61 # If all split parts compiled successfully, return them
62 if not split_compilation_errors:
63 return patterns
64
65 # If any split part failed to compile, treat the entire value as a single pattern
66 return [_regex_transformer(value)]
67
68# Test cases
69test_cases = [
70 # Original problematic case
71 {
72 "input": "(foo{1,3})",
73 "expected_count": 1,
74 "expected_patterns": ["(foo{1,3})"],
75 "description": "Single regex with quantifier containing comma"
76 },
77 # Multiple valid patterns
78 {
79 "input": "foo,bar",
80 "expected_count": 2,
81 "expected_patterns": ["foo", "bar"],
82 "description": "Two simple patterns"
83 },
84 # Multiple valid patterns with wildcards
85 {
86 "input": "explicit.*,disallowed.*",
87 "expected_count": 2,
88 "expected_patterns": ["explicit.*", "disallowed.*"],
89 "description": "Two patterns with wildcards"
90 },
91 # Single pattern that could be interpreted as multiple but should be one
92 {
93 "input": "a,b,c",
94 "expected_count": 3,
95 "expected_patterns": ["a", "b", "c"],
96 "description": "Three simple patterns"
97 },
98 # Complex regex with multiple commas
99 {
100 "input": "(a{1,2}|b{3,4}),c{5,6}",
101 "expected_count": 1,
102 "expected_patterns": ["(a{1,2}|b{3,4}),c{5,6}"],
103 "description": "Complex regex that would be mangled by splitting"
104 }
105]
106
107print("Testing _regexp_csv_transfomer function with various inputs:")
108print("=" * 60)
109
110all_passed = True
111
112for i, test_case in enumerate(test_cases, 1):
113 print(f"\nTest {i}: {test_case['description']}")
114 print(f"Input: {test_case['input']}")
115
116 try:
117 result = _regexp_csv_transfomer(test_case['input'])
118
119 # Check count
120 if len(result) != test_case['expected_count']:
121 print(f"❌ FAIL: Expected {test_case['expected_count']} patterns, got {len(result)}")
122 all_passed = False
123 continue
124
125 # Check patterns
126 actual_patterns = [p.pattern for p in result]
127 if actual_patterns != test_case['expected_patterns']:
128 print(f"❌ FAIL: Expected patterns {test_case['expected_patterns']}, got {actual_patterns}")
129 all_passed = False
130 continue
131
132 print(f"✅ PASS: Got {len(result)} pattern(s) as expected")
133 for j, pattern in enumerate(actual_patterns):
134 print(f" Pattern {j}: {pattern}")
135 except Exception as e:
136 print(f"❌ FAIL: Exception occurred: {e}")
137 all_passed = False
138
139print("\n" + "=" * 60)
140if all_passed:
141 print("🎉 All tests passed! The fix works correctly.")
142else:
143 print("❌ Some tests failed. The fix needs more work.")
Test NameStatus
tests/config/test_config.py::test_csv_regex_error
Fail
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,
Fail
tests/config/test_config.py::test_can_read_toml_env_variable
Pass
tests/config/test_config.py::test_unknown_message_id
Pass
tests/config/test_config.py::test_unknown_option_name
Pass
tests/config/test_config.py::test_unknown_short_option_name
Pass
tests/config/test_config.py::test_unknown_confidence
Pass
tests/config/test_config.py::test_empty_confidence
Pass
tests/config/test_config.py::test_unknown_yes_no
Pass
tests/config/test_config.py::test_unknown_py_version
Pass
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo-expected0]
Pass
tests/config/test_config.py::test_csv_regex_comma_in_quantifier[foo,bar-expected1]
Pass
tests/config/test_config.py::test_regex_error
Pass
tests/config/test_config.py::test_short_verbose
Pass
tests/config/test_config.py::test_argument_separator
Pass
tests/config/test_config.py::test_clear_cache_post_run
Pass
tests/config/test_config.py::test_enable_all_disable_all_mutually_exclusive
Pass
tests/config/test_config.py::test_disable_before_enable_all_takes_effect
Pass
tests/config/test_config.py::test_enable_before_disable_all_takes_effect
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.