kale

Finished
1import re
2import pathlib
3from typing import Sequence, Pattern
4
5def _csv_transformer(value: str) -> Sequence[str]:
6 """Simulate the original csv transformer that splits on commas."""
7 return [word.strip() for word in value.split(",") if word.strip()]
8
9def _regex_transformer(value: str) -> Pattern[str]:
10 """Return `re.compile(value)`."""
11 return re.compile(value)
12
13def _regexp_csv_transfomer_fixed(value: str) -> Sequence[Pattern[str]]:
14 """Transforms a comma separated list of regular expressions - FIXED VERSION."""
15 # Handle escaped commas in regex patterns
16 # Replace escaped commas with a placeholder, split, then restore
17 placeholder = "__COMMA_PLACEHOLDER__"
18 value = value.replace("\\,", placeholder)
19 patterns: list[Pattern[str]] = []
20 for pattern in _csv_transformer(value):
21 # Restore escaped commas
22 pattern = pattern.replace(placeholder, ",")
23 patterns.append(_regex_transformer(pattern))
24 return patterns
25
26def _regexp_paths_csv_transfomer_fixed(value: str) -> Sequence[Pattern[str]]:
27 """Transforms a comma separated list of regular expressions paths - FIXED VERSION."""
28 # Handle escaped commas in regex patterns
29 # Replace escaped commas with a placeholder, split, then restore
30 placeholder = "__COMMA_PLACEHOLDER__"
31 value = value.replace("\\,", placeholder)
32 patterns: list[Pattern[str]] = []
33 for pattern in _csv_transformer(value):
34 # Restore escaped commas
35 pattern = pattern.replace(placeholder, ",")
36 patterns.append(
37 re.compile(
38 str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
39 + "|"
40 + pathlib.PureWindowsPath(pattern).as_posix()
41 )
42 )
43 return patterns
44
45print("=== Testing _regexp_csv_transfomer ===")
46# Test cases for regular expressions
47test_cases = [
48 "(foo{1,3})", # Original problematic case - should fail without escaping
49 "(foo{1\\,3})", # Escaped version - should work
50 "foo,bar", # Normal comma-separated case
51 "foo\\,bar", # Escaped comma case
52 "(foo),(bar)", # Multiple patterns
53 "(foo\\,1),(bar\\,2)", # Multiple patterns with escaped commas
54]
55
56for test_case in test_cases:
57 print(f"\nTesting: {test_case}")
58 try:
59 result = _regexp_csv_transfomer_fixed(test_case)
60 print(f" SUCCESS: {[p.pattern for p in result]}")
61 except re.error as e:
62 print(f" re.error: {e}")
63 except Exception as e:
64 print(f" Other error: {type(e).__name__}: {e}")
65
66print("\n\n=== Testing _regexp_paths_csv_transfomer ===")
67# Test cases for path expressions (simpler since they don't need to be valid regex)
68test_path_cases = [
69 "path/to/file",
70 "path/to/file,another/path",
71 "path\\,with\\,commas", # Escaped commas
72 "path1\\,with\\,commas,path2\\,with\\,commas", # Multiple with escaped commas
73]
74
75for test_case in test_path_cases:
76 print(f"\nTesting: {test_case}")
77 try:
78 result = _regexp_paths_csv_transfomer_fixed(test_case)
79 print(f" SUCCESS: {len(result)} patterns created")
80 except Exception as e:
81 print(f" Error: {type(e).__name__}: {e}")
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.