|
1 |
| -from langflow.graph.utils import rewrite_file_path |
| 1 | +from langflow.base.data.utils import format_directory_path |
2 | 2 | import pytest
|
3 | 3 |
|
4 | 4 |
|
5 | 5 | @pytest.mark.parametrize(
|
6 |
| - "file_path, expected", |
| 6 | + "input_path, expected", |
7 | 7 | [
|
8 |
| - # Test case 1: Standard path with multiple directories |
9 |
| - ("/home/user/documents/file.txt", ["documents/file.txt"]), |
10 |
| - # Test case 2: Path with only one directory |
11 |
| - ("/documents/file.txt", ["documents/file.txt"]), |
12 |
| - # Test case 3: Path with no directories (just filename) |
13 |
| - ("file.txt", ["file.txt"]), |
14 |
| - # Test case 4: Path with multiple levels and special characters |
15 |
| - ("/home/user/my-docs/special_file!.pdf", ["my-docs/special_file!.pdf"]), |
16 |
| - # Test case 5: Path with trailing slash |
17 |
| - ("/home/user/documents/", ["user/documents"]), |
18 |
| - # Test case 6: Empty path |
19 |
| - ("", [""]), |
20 |
| - # Test case 7: Path with only slashes |
21 |
| - ("///", [""]), |
22 |
| - # Test case 8: Path with dots |
23 |
| - ("/home/user/../documents/./file.txt", ["./file.txt"]), |
24 |
| - # Test case 9: Windows-style path |
25 |
| - ("C:\\Users\\Documents\\file.txt", ["Documents/file.txt"]), |
26 |
| - # Test case 10: Windows path with trailing backslash |
27 |
| - ("C:\\Users\\Documents\\", ["Users/Documents"]), |
28 |
| - # Test case 11: Mixed separators |
29 |
| - ("C:/Users\\Documents/file.txt", ["Documents/file.txt"]), |
30 |
| - # Test case 12: Network path (UNC) |
31 |
| - ("\\\\server\\share\\file.txt", ["share/file.txt"]), |
| 8 | + # Test case 1: Standard path with no newlines |
| 9 | + ("/home/user/documents/file.txt", "/home/user/documents/file.txt"), |
| 10 | + # Test case 2: Path with newline character |
| 11 | + ("/home/user/docu\nments/file.txt", "/home/user/docu\\nments/file.txt"), |
| 12 | + # Test case 3: Path with multiple newline characters |
| 13 | + ("/home/user/\ndocu\nments/file.txt", "/home/user/\\ndocu\\nments/file.txt"), |
| 14 | + # Test case 4: Path with only newline characters |
| 15 | + ("\n\n\n", "\\n\\n\\n"), |
| 16 | + # Test case 5: Empty path |
| 17 | + ("", ""), |
| 18 | + # Test case 6: Path with mixed newlines and other special characters |
| 19 | + ("/home/user/my-\ndocs/special_file!.pdf", "/home/user/my-\\ndocs/special_file!.pdf"), |
| 20 | + # Test case 7: Windows-style path with newline |
| 21 | + ("C:\\Users\\\nDocuments\\file.txt", "C:\\Users\\\\nDocuments\\file.txt"), |
| 22 | + # Test case 8: Path with trailing newline |
| 23 | + ("/home/user/documents/\n", "/home/user/documents/\\n"), |
| 24 | + # Test case 9: Path with leading newline |
| 25 | + ("\n/home/user/documents/", "\\n/home/user/documents/"), |
| 26 | + # Test case 10: Path with multiple consecutive newlines |
| 27 | + ("/home/user/docu\n\nments/file.txt", "/home/user/docu\\n\\nments/file.txt"), |
32 | 28 | ],
|
33 | 29 | )
|
34 |
| -def test_rewrite_file_path(file_path, expected): |
35 |
| - result = rewrite_file_path(file_path) |
| 30 | +def test_format_directory_path(input_path, expected): |
| 31 | + result = format_directory_path(input_path) |
36 | 32 | assert result == expected
|
37 | 33 |
|
38 | 34 |
|
39 | 35 | # Additional test for type checking
|
40 |
| -def test_rewrite_file_path_type(): |
41 |
| - result = rewrite_file_path("/home/user/file.txt") |
42 |
| - assert isinstance(result, list) |
43 |
| - assert all(isinstance(item, str) for item in result) |
| 36 | +def test_format_directory_path_type(): |
| 37 | + result = format_directory_path("/home/user/file.txt") |
| 38 | + assert isinstance(result, str) |
0 commit comments