图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9 KiB

  1. import sys
  2. from unittest import TestCase
  3. import pytest
  4. from kazoo.protocol import paths
  5. if sys.version_info > (3,): # pragma: nocover
  6. def u(s):
  7. return s
  8. else: # pragma: nocover
  9. def u(s):
  10. return unicode(s, "unicode_escape") # noqa
  11. class NormPathTestCase(TestCase):
  12. def test_normpath(self):
  13. assert paths.normpath("/a/b") == "/a/b"
  14. def test_normpath_empty(self):
  15. assert paths.normpath("") == ""
  16. def test_normpath_unicode(self):
  17. assert paths.normpath(u("/\xe4/b")) == u("/\xe4/b")
  18. def test_normpath_dots(self):
  19. assert paths.normpath("/a./b../c") == "/a./b../c"
  20. def test_normpath_slash(self):
  21. assert paths.normpath("/") == "/"
  22. def test_normpath_multiple_slashes(self):
  23. assert paths.normpath("//") == "/"
  24. assert paths.normpath("//a/b") == "/a/b"
  25. assert paths.normpath("/a//b//") == "/a/b"
  26. assert paths.normpath("//a////b///c/") == "/a/b/c"
  27. def test_normpath_relative(self):
  28. with pytest.raises(ValueError):
  29. paths.normpath("./a/b")
  30. with pytest.raises(ValueError):
  31. paths.normpath("/a/../b")
  32. def test_normpath_trailing(self):
  33. assert paths.normpath("/", trailing=True) == "/"
  34. class JoinTestCase(TestCase):
  35. def test_join(self):
  36. assert paths.join("/a") == "/a"
  37. assert paths.join("/a", "b/") == "/a/b/"
  38. assert paths.join("/a", "b", "c") == "/a/b/c"
  39. def test_join_empty(self):
  40. assert paths.join("") == ""
  41. assert paths.join("", "a", "b") == "a/b"
  42. assert paths.join("/a", "", "b/", "c") == "/a/b/c"
  43. def test_join_absolute(self):
  44. assert paths.join("/a/b", "/c") == "/c"
  45. class IsAbsTestCase(TestCase):
  46. def test_isabs(self):
  47. assert paths.isabs("/") is True
  48. assert paths.isabs("/a") is True
  49. assert paths.isabs("/a//b/c") is True
  50. assert paths.isabs("//a/b") is True
  51. def test_isabs_false(self):
  52. assert paths.isabs("") is False
  53. assert paths.isabs("a/") is False
  54. assert paths.isabs("a/../") is False
  55. class BaseNameTestCase(TestCase):
  56. def test_basename(self):
  57. assert paths.basename("") == ""
  58. assert paths.basename("/") == ""
  59. assert paths.basename("//a") == "a"
  60. assert paths.basename("//a/") == ""
  61. assert paths.basename("/a/b.//c..") == "c.."
  62. class PrefixRootTestCase(TestCase):
  63. def test_prefix_root(self):
  64. assert paths._prefix_root("/a/", "b/c") == "/a/b/c"
  65. assert paths._prefix_root("/a/b", "c/d") == "/a/b/c/d"
  66. assert paths._prefix_root("/a", "/b/c") == "/a/b/c"
  67. assert paths._prefix_root("/a", "//b/c.") == "/a/b/c."
  68. class NormRootTestCase(TestCase):
  69. def test_norm_root(self):
  70. assert paths._norm_root("") == "/"
  71. assert paths._norm_root("/") == "/"
  72. assert paths._norm_root("//a") == "/a"
  73. assert paths._norm_root("//a./b") == "/a./b"