| 1 | import re | |
| 2 | ||
| 3 | # Test the patterns from our function | |
| 4 | print("Testing pattern matching directly:") | |
| 5 | ||
| 6 | # Test 1: Simple pattern | |
| 7 | pattern1 = re.compile("explicit.*") | |
| 8 | result1 = pattern1.search("explicit_something") | |
| 9 | print(f"Pattern 'explicit.*' searching 'explicit_something': {result1}") | |
| 10 | ||
| 11 | # Test 2: Our compiled pattern from the function | |
| 12 | def _regex_transformer(value: str): | |
| 13 | return re.compile(value) | |
| 14 | ||
| 15 | def _csv_transformer_with_escaped_commas(value: str): | |
| 16 | if not value: | |
| 17 | return [] | |
| 18 | ||
| 19 | result = [] | |
| 20 | current = "" | |
| 21 | i = 0 | |
| 22 | while i < len(value): | |
| 23 | if value[i] == "\\" and i + 1 < len(value) and value[i + 1] == ",": | |
| 24 | current += "," | |
| 25 | i += 2 | |
| 26 | elif value[i] == ",": | |
| 27 | result.append(current.strip()) | |
| 28 | current = "" | |
| 29 | i += 1 | |
| 30 | else: | |
| 31 | current += value[i] | |
| 32 | i += 1 | |
| 33 | ||
| 34 | if current or value.endswith(","): | |
| 35 | result.append(current.strip()) | |
| 36 | ||
| 37 | return [item for item in result if item] | |
| 38 | ||
| 39 | def _regexp_csv_transfomer(value: str): | |
| 40 | patterns = [] | |
| 41 | for pattern in _csv_transformer_with_escaped_commas(value): | |
| 42 | unescaped_pattern = pattern.replace(r"\\,", ",").replace(r"\,", ",") | |
| 43 | patterns.append(_regex_transformer(unescaped_pattern)) | |
| 44 | return patterns | |
| 45 | ||
| 46 | # Test our function | |
| 47 | print("\nTesting our function:") | |
| 48 | patterns = _regexp_csv_transfomer("explicit.*,disallowed.*") | |
| 49 | print(f"Compiled patterns: {[p.pattern for p in patterns]}") | |
| 50 | ||
| 51 | # Test each pattern | |
| 52 | for i, pattern in enumerate(patterns): | |
| 53 | result = pattern.search("explicit_something") | |
| 54 | print(f"Pattern {i} ('{pattern.pattern}') searching 'explicit_something': {result}") | |
| 55 | ||
| 56 | result2 = pattern.search("disallowed_something") | |
| 57 | print(f"Pattern {i} ('{pattern.pattern}') searching 'disallowed_something': {result2}") |
| Test Name | Status |
|---|---|
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.