505
517
split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
506
518
self.assertEquals(("/somedir/path", ["heads%2Ftip", "bar"]),
507
519
split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
508
self.assertEquals(("/", ["key1=val1"]),
520
# Check relative references with relative paths
521
self.assertEquals(("", ["key1=val1"]),
509
522
split_segment_parameters_raw(",key1=val1"))
510
523
self.assertEquals(("foo/", ["key1=val1"]),
511
524
split_segment_parameters_raw("foo/,key1=val1"))
512
self.assertEquals(("/foo", ["key1=val1"]),
525
self.assertEquals(("foo", ["key1=val1"]),
513
526
split_segment_parameters_raw("foo,key1=val1"))
514
527
self.assertEquals(("foo/base,la=bla/other/elements", []),
515
528
split_segment_parameters_raw("foo/base,la=bla/other/elements"))
516
529
self.assertEquals(("foo/base,la=bla/other/elements", ["a=b"]),
517
530
split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
531
# TODO: Check full URLs as well as relative references
519
533
def test_split_segment_parameters(self):
520
534
split_segment_parameters = urlutils.split_segment_parameters
535
# Check relative references with absolute paths
521
536
self.assertEquals(("/some/path", {}),
522
537
split_segment_parameters("/some/path"))
523
538
self.assertEquals(("/some/path", {"branch": "tip"}),
905
922
url3 = url.clone()
906
923
self.assertIsNot(url, url3)
907
924
self.assertEquals(url, url3)
927
class TestFileRelpath(TestCase):
929
# GZ 2011-11-18: A way to override all path handling functions to one
930
# platform or another for testing would be nice.
932
def _with_posix_paths(self):
933
self.overrideAttr(urlutils, "local_path_from_url",
934
urlutils._posix_local_path_from_url)
935
self.overrideAttr(urlutils, "MIN_ABS_FILEURL_LENGTH", len("file:///"))
936
self.overrideAttr(osutils, "normpath", osutils._posix_normpath)
937
self.overrideAttr(osutils, "abspath", osutils._posix_abspath)
938
self.overrideAttr(osutils, "normpath", osutils._posix_normpath)
939
self.overrideAttr(osutils, "pathjoin", osutils.posixpath.join)
940
self.overrideAttr(osutils, "split", osutils.posixpath.split)
941
self.overrideAttr(osutils, "MIN_ABS_PATHLENGTH", 1)
943
def _with_win32_paths(self):
944
self.overrideAttr(urlutils, "local_path_from_url",
945
urlutils._win32_local_path_from_url)
946
self.overrideAttr(urlutils, "MIN_ABS_FILEURL_LENGTH",
947
urlutils.WIN32_MIN_ABS_FILEURL_LENGTH)
948
self.overrideAttr(osutils, "abspath", osutils._win32_abspath)
949
self.overrideAttr(osutils, "normpath", osutils._win32_normpath)
950
self.overrideAttr(osutils, "pathjoin", osutils._win32_pathjoin)
951
self.overrideAttr(osutils, "split", osutils.ntpath.split)
952
self.overrideAttr(osutils, "MIN_ABS_PATHLENGTH", 3)
954
def test_same_url_posix(self):
955
self._with_posix_paths()
956
self.assertEquals("",
957
urlutils.file_relpath("file:///a", "file:///a"))
958
self.assertEquals("",
959
urlutils.file_relpath("file:///a", "file:///a/"))
960
self.assertEquals("",
961
urlutils.file_relpath("file:///a/", "file:///a"))
963
def test_same_url_win32(self):
964
self._with_win32_paths()
965
self.assertEquals("",
966
urlutils.file_relpath("file:///A:/", "file:///A:/"))
967
self.assertEquals("",
968
urlutils.file_relpath("file:///A|/", "file:///A:/"))
969
self.assertEquals("",
970
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
971
self.assertEquals("",
972
urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
973
self.assertEquals("",
974
urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
976
def test_child_posix(self):
977
self._with_posix_paths()
978
self.assertEquals("b",
979
urlutils.file_relpath("file:///a", "file:///a/b"))
980
self.assertEquals("b",
981
urlutils.file_relpath("file:///a/", "file:///a/b"))
982
self.assertEquals("b/c",
983
urlutils.file_relpath("file:///a", "file:///a/b/c"))
985
def test_child_win32(self):
986
self._with_win32_paths()
987
self.assertEquals("b",
988
urlutils.file_relpath("file:///A:/", "file:///A:/b"))
989
self.assertEquals("b",
990
urlutils.file_relpath("file:///A|/", "file:///A:/b"))
991
self.assertEquals("c",
992
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
993
self.assertEquals("c",
994
urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
995
self.assertEquals("c/d",
996
urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
998
def test_sibling_posix(self):
999
self._with_posix_paths()
1000
self.assertRaises(PathNotChild,
1001
urlutils.file_relpath, "file:///a/b", "file:///a/c")
1002
self.assertRaises(PathNotChild,
1003
urlutils.file_relpath, "file:///a/b/", "file:///a/c")
1004
self.assertRaises(PathNotChild,
1005
urlutils.file_relpath, "file:///a/b/", "file:///a/c/")
1007
def test_sibling_win32(self):
1008
self._with_win32_paths()
1009
self.assertRaises(PathNotChild,
1010
urlutils.file_relpath, "file:///A:/b", "file:///A:/c")
1011
self.assertRaises(PathNotChild,
1012
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c")
1013
self.assertRaises(PathNotChild,
1014
urlutils.file_relpath, "file:///A:/b/", "file:///A:/c/")
1016
def test_parent_posix(self):
1017
self._with_posix_paths()
1018
self.assertRaises(PathNotChild,
1019
urlutils.file_relpath, "file:///a/b", "file:///a")
1020
self.assertRaises(PathNotChild,
1021
urlutils.file_relpath, "file:///a/b", "file:///a/")
1023
def test_parent_win32(self):
1024
self._with_win32_paths()
1025
self.assertRaises(PathNotChild,
1026
urlutils.file_relpath, "file:///A:/b", "file:///A:/")
1027
self.assertRaises(PathNotChild,
1028
urlutils.file_relpath, "file:///A:/b/c", "file:///A:/b")
1031
class QuoteTests(TestCase):
1033
def test_quote(self):
1034
self.assertEqual('abc%20def', urlutils.quote('abc def'))
1035
self.assertEqual('abc%2Fdef', urlutils.quote('abc/def', safe=''))
1036
self.assertEqual('abc/def', urlutils.quote('abc/def', safe='/'))
1038
def test_quote_tildes(self):
1039
self.assertEqual('%7Efoo', urlutils.quote('~foo'))
1040
self.assertEqual('~foo', urlutils.quote('~foo', safe='/~'))
1042
def test_unquote(self):
1043
self.assertEqual('%', urlutils.unquote('%25'))
1044
self.assertEqual('\xc3\xa5', urlutils.unquote('%C3%A5'))
1045
self.assertEqual(u"\xe5", urlutils.unquote(u'\xe5'))