|
| 1 | +import pytest |
| 2 | + |
1 | 3 | from humanloop import path_utils |
2 | 4 |
|
3 | 5 |
|
4 | | -def test_normalize_path(): |
5 | | - """Test path normalization functionality.""" |
6 | | - # GIVEN various file paths with different formats |
7 | | - test_cases = [ |
8 | | - # Input path, expected with strip_extension=False, expected with strip_extension=True |
| 6 | +@pytest.mark.parametrize( |
| 7 | + "input_path, expected_with_extension, expected_without_extension", |
| 8 | + [ |
| 9 | + # Basic cases |
9 | 10 | ("path/to/file.prompt", "path/to/file.prompt", "path/to/file"), |
10 | 11 | ("path\\to\\file.agent", "path/to/file.agent", "path/to/file"), |
11 | 12 | ("/leading/slashes/file.prompt", "leading/slashes/file.prompt", "leading/slashes/file"), |
12 | 13 | ("trailing/slashes/file.agent/", "trailing/slashes/file.agent", "trailing/slashes/file"), |
13 | 14 | ("multiple//slashes//file.prompt", "multiple/slashes/file.prompt", "multiple/slashes/file"), |
14 | | - ] |
15 | | - |
16 | | - # Test with strip_extension=False (default) |
17 | | - for input_path, expected_with_ext, _ in test_cases: |
18 | | - # WHEN they are normalized without stripping extension |
19 | | - normalized = path_utils.normalize_path(input_path, strip_extension=False) |
20 | | - # THEN they should be converted to the expected format with extension |
21 | | - assert normalized == expected_with_ext |
| 15 | + # Edge cases |
| 16 | + ("path/to/file with spaces.prompt", "path/to/file with spaces.prompt", "path/to/file with spaces"), |
| 17 | + ( |
| 18 | + "path/to/file\\with\\backslashes.prompt", |
| 19 | + "path/to/file/with/backslashes.prompt", |
| 20 | + "path/to/file/with/backslashes", |
| 21 | + ), |
| 22 | + ("path/to/unicode/文件.prompt", "path/to/unicode/文件.prompt", "path/to/unicode/文件"), |
| 23 | + ( |
| 24 | + "path/to/special/chars/!@#$%^&*().prompt", |
| 25 | + "path/to/special/chars/!@#$%^&*().prompt", |
| 26 | + "path/to/special/chars/!@#$%^&*()", |
| 27 | + ), |
| 28 | + ], |
| 29 | +) |
| 30 | +def test_normalize_path(input_path, expected_with_extension, expected_without_extension): |
| 31 | + """Test path normalization with various path formats.""" |
| 32 | + # Test without stripping extension |
| 33 | + normalized = path_utils.normalize_path(input_path, strip_extension=False) |
| 34 | + assert normalized == expected_with_extension, f"Failed with strip_extension=False for '{input_path}'" |
22 | 35 |
|
23 | | - # Test with strip_extension=True |
24 | | - for input_path, _, expected_without_ext in test_cases: |
25 | | - # WHEN they are normalized with extension stripping |
26 | | - normalized = path_utils.normalize_path(input_path, strip_extension=True) |
27 | | - # THEN they should be converted to the expected format without extension |
28 | | - assert normalized == expected_without_ext |
| 36 | + # Test with extension stripping |
| 37 | + normalized = path_utils.normalize_path(input_path, strip_extension=True) |
| 38 | + assert normalized == expected_without_extension, f"Failed with strip_extension=True for '{input_path}'" |
0 commit comments