Skip to content

Commit

Permalink
🐛 (test_format_directory_path.py): update parameter name from 'path' …
Browse files Browse the repository at this point in the history
…to 'input_path' for clarity and consistency

📝 (test_format_directory_path.py): improve test case descriptions and handle newline characters in paths correctly
  • Loading branch information
Cristhianzl authored and ogabrielluiz committed Oct 14, 2024
1 parent 7915fa5 commit 21b1a42
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/backend/tests/unit/utils/test_format_directory_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,40 @@


@pytest.mark.parametrize(
"path, expected",
"input_path, expected",
[
# Test case 1: Standard path with forward slashes
# Test case 1: Standard path with no newlines (no change expected)
("/home/user/documents/file.txt", "/home/user/documents/file.txt"),
# Test case 2: Path with backslashes (Windows-style)
("C:\\Users\\Documents\\file.txt", "C:/Users/Documents/file.txt"),
# Test case 3: Mixed separators
("C:/Users\\Documents/file.txt", "C:/Users/Documents/file.txt"),
# Test case 4: Path with only forward slashes
("/home/user/documents/", "/home/user/documents/"),
# Test case 5: Path with only backslashes
("\\\\server\\share\\file.txt", "//server/share/file.txt"),
# Test case 6: Path with no separators
("file.txt", "file.txt"),
# Test case 7: Empty path
# Test case 2: Path with newline character (replace \n with \\n)
("/home/user/docu\nments/file.txt", "/home/user/docu\\nments/file.txt"),
# Test case 3: Path with multiple newline characters
("/home/user/\ndocu\nments/file.txt", "/home/user/\\ndocu\\nments/file.txt"),
# Test case 4: Path with only newline characters
("\n\n\n", "\\n\\n\\n"),
# Test case 5: Empty path (as per the original function, this remains an empty string)
("", ""),
# Test case 8: Path with special characters
("/home/user/my-docs/special_file!.pdf", "/home/user/my-docs/special_file!.pdf"),
# Test case 9: Path with dots
("/home/user/../documents/./file.txt", "/home/user/../documents/./file.txt"),
# Test case 6: Path with mixed newlines and other special characters
("/home/user/my-\ndocs/special_file!.pdf", "/home/user/my-\\ndocs/special_file!.pdf"),
# Test case 7: Windows-style path with newline
("C:\\Users\\\nDocuments\\file.txt", "C:\\Users\\\\nDocuments\\file.txt"), # No conversion of backslashes
# Test case 8: Path with trailing newline
("/home/user/documents/\n", "/home/user/documents/\\n"),
# Test case 9: Path with leading newline
("\n/home/user/documents/", "\\n/home/user/documents/"),
# Test case 10: Path with multiple consecutive newlines
("/home/user/docu\n\nments/file.txt", "/home/user/docu\\n\\nments/file.txt"),
# Test case 11: Windows-style path (backslashes remain unchanged)
("C:\\Users\\Documents\\file.txt", "C:\\Users\\Documents\\file.txt"),
# Test case 12: Windows path with trailing backslash
("C:\\Users\\Documents\\", "C:\\Users\\Documents\\"),
# Test case 13: Mixed separators (leave as is)
("C:/Users\\Documents/file.txt", "C:/Users\\Documents/file.txt"),
# Test case 14: Network path (UNC) (leave backslashes as is)
("\\\\server\\share\\file.txt", "\\\\server\\share\\file.txt"),
],
)
def test_format_directory_path(path, expected):
result = format_directory_path(path)
def test_format_directory_path(input_path, expected):
result = format_directory_path(input_path)
assert result == expected


Expand Down

0 comments on commit 21b1a42

Please sign in to comment.