test_normalize_path.py 1012 B

12345678910111213141516171819202122232425262728293031323334
  1. import pytest
  2. from yarl import URL
  3. PATHS = [
  4. # No dots
  5. ("", ""),
  6. ("/", "/"),
  7. ("//", "//"),
  8. ("///", "///"),
  9. # Single-dot
  10. ("path/to", "path/to"),
  11. ("././path/to", "path/to"),
  12. ("path/./to", "path/to"),
  13. ("path/././to", "path/to"),
  14. ("path/to/.", "path/to/"),
  15. ("path/to/./.", "path/to/"),
  16. # Double-dots
  17. ("../path/to", "path/to"),
  18. ("path/../to", "to"),
  19. ("path/../../to", "to"),
  20. # absolute path root / is maintained; tests based on two
  21. # tests from web-platform-tests project's urltestdata.json
  22. ("/foo/../../../ton", "/ton"),
  23. ("/foo/../../../..bar", "/..bar"),
  24. # Non-ASCII characters
  25. ("μονοπάτι/../../να/ᴜɴɪ/ᴄᴏᴅᴇ", "να/ᴜɴɪ/ᴄᴏᴅᴇ"),
  26. ("μονοπάτι/../../να/𝕦𝕟𝕚/𝕔𝕠𝕕𝕖/.", "να/𝕦𝕟𝕚/𝕔𝕠𝕕𝕖/"),
  27. ]
  28. @pytest.mark.parametrize("original,expected", PATHS)
  29. def test__normalize_path(original, expected):
  30. assert URL._normalize_path(original) == expected