~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_urlutils.py

  • Committer: Vincent Ladeuil
  • Date: 2016-02-01 18:06:32 UTC
  • mto: (6614.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6615.
  • Revision ID: v.ladeuil+lp@free.fr-20160201180632-xgp7k7z5bda9ap1w
Fix assertEquals being deprecated by using assertEqual.

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
 
297
297
    def test_join_segment_parameters_raw(self):
298
298
        join_segment_parameters_raw = urlutils.join_segment_parameters_raw
299
 
        self.assertEquals("/somedir/path", 
 
299
        self.assertEqual("/somedir/path", 
300
300
            join_segment_parameters_raw("/somedir/path"))
301
 
        self.assertEquals("/somedir/path,rawdata", 
 
301
        self.assertEqual("/somedir/path,rawdata", 
302
302
            join_segment_parameters_raw("/somedir/path", "rawdata"))
303
303
        self.assertRaises(InvalidURLJoin,
304
304
            join_segment_parameters_raw, "/somedir/path",
305
305
                "rawdata1,rawdata2,rawdata3")
306
 
        self.assertEquals("/somedir/path,bla,bar",
 
306
        self.assertEqual("/somedir/path,bla,bar",
307
307
            join_segment_parameters_raw("/somedir/path", "bla", "bar"))
308
 
        self.assertEquals("/somedir,exist=some/path,bla,bar",
 
308
        self.assertEqual("/somedir,exist=some/path,bla,bar",
309
309
            join_segment_parameters_raw("/somedir,exist=some/path",
310
310
                "bla", "bar"))
311
311
        self.assertRaises(TypeError, join_segment_parameters_raw, 
313
313
 
314
314
    def test_join_segment_parameters(self):
315
315
        join_segment_parameters = urlutils.join_segment_parameters
316
 
        self.assertEquals("/somedir/path", 
 
316
        self.assertEqual("/somedir/path", 
317
317
            join_segment_parameters("/somedir/path", {}))
318
 
        self.assertEquals("/somedir/path,key1=val1", 
 
318
        self.assertEqual("/somedir/path,key1=val1", 
319
319
            join_segment_parameters("/somedir/path", {"key1": "val1"}))
320
320
        self.assertRaises(InvalidURLJoin,
321
321
            join_segment_parameters, "/somedir/path",
322
322
            {"branch": "brr,brr,brr"})
323
323
        self.assertRaises(InvalidURLJoin,
324
324
            join_segment_parameters, "/somedir/path", {"key1=val1": "val2"})
325
 
        self.assertEquals("/somedir/path,key1=val1,key2=val2",
 
325
        self.assertEqual("/somedir/path,key1=val1,key2=val2",
326
326
            join_segment_parameters("/somedir/path", {
327
327
                "key1": "val1", "key2": "val2"}))
328
 
        self.assertEquals("/somedir/path,key1=val1,key2=val2",
 
328
        self.assertEqual("/somedir/path,key1=val1,key2=val2",
329
329
            join_segment_parameters("/somedir/path,key1=val1", {
330
330
                "key2": "val2"}))
331
 
        self.assertEquals("/somedir/path,key1=val2",
 
331
        self.assertEqual("/somedir/path,key1=val2",
332
332
            join_segment_parameters("/somedir/path,key1=val1", {
333
333
                "key1": "val2"}))
334
 
        self.assertEquals("/somedir,exist=some/path,key1=val1",
 
334
        self.assertEqual("/somedir,exist=some/path,key1=val1",
335
335
            join_segment_parameters("/somedir,exist=some/path",
336
336
                {"key1": "val1"}))
337
 
        self.assertEquals("/,key1=val1,key2=val2",
 
337
        self.assertEqual("/,key1=val1,key2=val2",
338
338
            join_segment_parameters("/,key1=val1", {"key2": "val2"}))
339
339
        self.assertRaises(TypeError,
340
340
            join_segment_parameters, "/,key1=val1", {"foo": 42})
508
508
    def test_split_segment_parameters_raw(self):
509
509
        split_segment_parameters_raw = urlutils.split_segment_parameters_raw
510
510
        # Check relative references with absolute paths
511
 
        self.assertEquals(("/some/path", []),
 
511
        self.assertEqual(("/some/path", []),
512
512
            split_segment_parameters_raw("/some/path"))
513
 
        self.assertEquals(("/some/path", ["tip"]),
 
513
        self.assertEqual(("/some/path", ["tip"]),
514
514
            split_segment_parameters_raw("/some/path,tip"))
515
 
        self.assertEquals(("/some,dir/path", ["tip"]),
 
515
        self.assertEqual(("/some,dir/path", ["tip"]),
516
516
            split_segment_parameters_raw("/some,dir/path,tip"))
517
 
        self.assertEquals(("/somedir/path", ["heads%2Ftip"]),
 
517
        self.assertEqual(("/somedir/path", ["heads%2Ftip"]),
518
518
            split_segment_parameters_raw("/somedir/path,heads%2Ftip"))
519
 
        self.assertEquals(("/somedir/path", ["heads%2Ftip", "bar"]),
 
519
        self.assertEqual(("/somedir/path", ["heads%2Ftip", "bar"]),
520
520
            split_segment_parameters_raw("/somedir/path,heads%2Ftip,bar"))
521
521
        # Check relative references with relative paths
522
 
        self.assertEquals(("", ["key1=val1"]),
 
522
        self.assertEqual(("", ["key1=val1"]),
523
523
            split_segment_parameters_raw(",key1=val1"))
524
 
        self.assertEquals(("foo/", ["key1=val1"]),
 
524
        self.assertEqual(("foo/", ["key1=val1"]),
525
525
            split_segment_parameters_raw("foo/,key1=val1"))
526
 
        self.assertEquals(("foo", ["key1=val1"]),
 
526
        self.assertEqual(("foo", ["key1=val1"]),
527
527
            split_segment_parameters_raw("foo,key1=val1"))
528
 
        self.assertEquals(("foo/base,la=bla/other/elements", []),
 
528
        self.assertEqual(("foo/base,la=bla/other/elements", []),
529
529
            split_segment_parameters_raw("foo/base,la=bla/other/elements"))
530
 
        self.assertEquals(("foo/base,la=bla/other/elements", ["a=b"]),
 
530
        self.assertEqual(("foo/base,la=bla/other/elements", ["a=b"]),
531
531
            split_segment_parameters_raw("foo/base,la=bla/other/elements,a=b"))
532
532
        # TODO: Check full URLs as well as relative references
533
533
 
534
534
    def test_split_segment_parameters(self):
535
535
        split_segment_parameters = urlutils.split_segment_parameters
536
536
        # Check relative references with absolute paths
537
 
        self.assertEquals(("/some/path", {}),
 
537
        self.assertEqual(("/some/path", {}),
538
538
            split_segment_parameters("/some/path"))
539
 
        self.assertEquals(("/some/path", {"branch": "tip"}),
 
539
        self.assertEqual(("/some/path", {"branch": "tip"}),
540
540
            split_segment_parameters("/some/path,branch=tip"))
541
 
        self.assertEquals(("/some,dir/path", {"branch": "tip"}),
 
541
        self.assertEqual(("/some,dir/path", {"branch": "tip"}),
542
542
            split_segment_parameters("/some,dir/path,branch=tip"))
543
 
        self.assertEquals(("/somedir/path", {"ref": "heads%2Ftip"}),
 
543
        self.assertEqual(("/somedir/path", {"ref": "heads%2Ftip"}),
544
544
            split_segment_parameters("/somedir/path,ref=heads%2Ftip"))
545
 
        self.assertEquals(("/somedir/path",
 
545
        self.assertEqual(("/somedir/path",
546
546
            {"ref": "heads%2Ftip", "key1": "val1"}),
547
547
            split_segment_parameters(
548
548
                "/somedir/path,ref=heads%2Ftip,key1=val1"))
549
 
        self.assertEquals(("/somedir/path", {"ref": "heads%2F=tip"}),
 
549
        self.assertEqual(("/somedir/path", {"ref": "heads%2F=tip"}),
550
550
            split_segment_parameters("/somedir/path,ref=heads%2F=tip"))
551
551
        # Check relative references with relative paths
552
 
        self.assertEquals(("", {"key1": "val1"}),
 
552
        self.assertEqual(("", {"key1": "val1"}),
553
553
            split_segment_parameters(",key1=val1"))
554
 
        self.assertEquals(("foo/", {"key1": "val1"}),
 
554
        self.assertEqual(("foo/", {"key1": "val1"}),
555
555
            split_segment_parameters("foo/,key1=val1"))
556
 
        self.assertEquals(("foo/base,key1=val1/other/elements", {}),
 
556
        self.assertEqual(("foo/base,key1=val1/other/elements", {}),
557
557
            split_segment_parameters("foo/base,key1=val1/other/elements"))
558
 
        self.assertEquals(("foo/base,key1=val1/other/elements",
 
558
        self.assertEqual(("foo/base,key1=val1/other/elements",
559
559
            {"key2": "val2"}), split_segment_parameters(
560
560
                "foo/base,key1=val1/other/elements,key2=val2"))
561
561
        # TODO: Check full URLs as well as relative references
830
830
 
831
831
    def test_parse_simple(self):
832
832
        parsed = urlutils.parse_url('http://example.com:80/one')
833
 
        self.assertEquals(('http', None, None, 'example.com', 80, '/one'),
 
833
        self.assertEqual(('http', None, None, 'example.com', 80, '/one'),
834
834
            parsed)
835
835
 
836
836
    def test_ipv6(self):
837
837
        parsed = urlutils.parse_url('http://[1:2:3::40]/one')
838
 
        self.assertEquals(('http', None, None, '1:2:3::40', None, '/one'),
 
838
        self.assertEqual(('http', None, None, '1:2:3::40', None, '/one'),
839
839
            parsed)
840
840
 
841
841
    def test_ipv6_port(self):
842
842
        parsed = urlutils.parse_url('http://[1:2:3::40]:80/one')
843
 
        self.assertEquals(('http', None, None, '1:2:3::40', 80, '/one'),
 
843
        self.assertEqual(('http', None, None, '1:2:3::40', 80, '/one'),
844
844
            parsed)
845
845
 
846
846
 
848
848
 
849
849
    def test_parse_simple(self):
850
850
        parsed = urlutils.URL.from_string('http://example.com:80/one')
851
 
        self.assertEquals('http', parsed.scheme)
 
851
        self.assertEqual('http', parsed.scheme)
852
852
        self.assertIs(None, parsed.user)
853
853
        self.assertIs(None, parsed.password)
854
 
        self.assertEquals('example.com', parsed.host)
855
 
        self.assertEquals(80, parsed.port)
856
 
        self.assertEquals('/one', parsed.path)
 
854
        self.assertEqual('example.com', parsed.host)
 
855
        self.assertEqual(80, parsed.port)
 
856
        self.assertEqual('/one', parsed.path)
857
857
 
858
858
    def test_ipv6(self):
859
859
        parsed = urlutils.URL.from_string('http://[1:2:3::40]/one')
860
 
        self.assertEquals('http', parsed.scheme)
 
860
        self.assertEqual('http', parsed.scheme)
861
861
        self.assertIs(None, parsed.port)
862
862
        self.assertIs(None, parsed.user)
863
863
        self.assertIs(None, parsed.password)
864
 
        self.assertEquals('1:2:3::40', parsed.host)
865
 
        self.assertEquals('/one', parsed.path)
 
864
        self.assertEqual('1:2:3::40', parsed.host)
 
865
        self.assertEqual('/one', parsed.path)
866
866
 
867
867
    def test_ipv6_port(self):
868
868
        parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
869
 
        self.assertEquals('http', parsed.scheme)
870
 
        self.assertEquals('1:2:3::40', parsed.host)
 
869
        self.assertEqual('http', parsed.scheme)
 
870
        self.assertEqual('1:2:3::40', parsed.host)
871
871
        self.assertIs(None, parsed.user)
872
872
        self.assertIs(None, parsed.password)
873
 
        self.assertEquals(80, parsed.port)
874
 
        self.assertEquals('/one', parsed.path)
 
873
        self.assertEqual(80, parsed.port)
 
874
        self.assertEqual('/one', parsed.path)
875
875
 
876
876
    def test_quoted(self):
877
877
        parsed = urlutils.URL.from_string(
878
878
            'http://ro%62ey:h%40t@ex%41mple.com:2222/path')
879
 
        self.assertEquals(parsed.quoted_host, 'ex%41mple.com')
880
 
        self.assertEquals(parsed.host, 'exAmple.com')
881
 
        self.assertEquals(parsed.port, 2222)
882
 
        self.assertEquals(parsed.quoted_user, 'ro%62ey')
883
 
        self.assertEquals(parsed.user, 'robey')
884
 
        self.assertEquals(parsed.quoted_password, 'h%40t')
885
 
        self.assertEquals(parsed.password, 'h@t')
886
 
        self.assertEquals(parsed.path, '/path')
 
879
        self.assertEqual(parsed.quoted_host, 'ex%41mple.com')
 
880
        self.assertEqual(parsed.host, 'exAmple.com')
 
881
        self.assertEqual(parsed.port, 2222)
 
882
        self.assertEqual(parsed.quoted_user, 'ro%62ey')
 
883
        self.assertEqual(parsed.user, 'robey')
 
884
        self.assertEqual(parsed.quoted_password, 'h%40t')
 
885
        self.assertEqual(parsed.password, 'h@t')
 
886
        self.assertEqual(parsed.path, '/path')
887
887
 
888
888
    def test_eq(self):
889
889
        parsed1 = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
890
890
        parsed2 = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
891
 
        self.assertEquals(parsed1, parsed2)
892
 
        self.assertEquals(parsed1, parsed1)
 
891
        self.assertEqual(parsed1, parsed2)
 
892
        self.assertEqual(parsed1, parsed1)
893
893
        parsed2.path = '/two'
894
894
        self.assertNotEqual(parsed1, parsed2)
895
895
 
896
896
    def test_repr(self):
897
897
        parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
898
 
        self.assertEquals(
 
898
        self.assertEqual(
899
899
            "<URL('http', None, None, '1:2:3::40', 80, '/one')>",
900
900
            repr(parsed))
901
901
 
902
902
    def test_str(self):
903
903
        parsed = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
904
 
        self.assertEquals('http://[1:2:3::40]:80/one', str(parsed))
 
904
        self.assertEqual('http://[1:2:3::40]:80/one', str(parsed))
905
905
 
906
906
    def test__combine_paths(self):
907
907
        combine = urlutils.URL._combine_paths
917
917
    def test_clone(self):
918
918
        url = urlutils.URL.from_string('http://[1:2:3::40]:80/one')
919
919
        url1 = url.clone("two")
920
 
        self.assertEquals("/one/two", url1.path)
 
920
        self.assertEqual("/one/two", url1.path)
921
921
        url2 = url.clone("/two")
922
 
        self.assertEquals("/two", url2.path)
 
922
        self.assertEqual("/two", url2.path)
923
923
        url3 = url.clone()
924
924
        self.assertIsNot(url, url3)
925
 
        self.assertEquals(url, url3)
 
925
        self.assertEqual(url, url3)
926
926
 
927
927
 
928
928
class TestFileRelpath(TestCase):
954
954
 
955
955
    def test_same_url_posix(self):
956
956
        self._with_posix_paths()
957
 
        self.assertEquals("",
 
957
        self.assertEqual("",
958
958
            urlutils.file_relpath("file:///a", "file:///a"))
959
 
        self.assertEquals("",
 
959
        self.assertEqual("",
960
960
            urlutils.file_relpath("file:///a", "file:///a/"))
961
 
        self.assertEquals("",
 
961
        self.assertEqual("",
962
962
            urlutils.file_relpath("file:///a/", "file:///a"))
963
963
 
964
964
    def test_same_url_win32(self):
965
965
        self._with_win32_paths()
966
 
        self.assertEquals("",
 
966
        self.assertEqual("",
967
967
            urlutils.file_relpath("file:///A:/", "file:///A:/"))
968
 
        self.assertEquals("",
 
968
        self.assertEqual("",
969
969
            urlutils.file_relpath("file:///A|/", "file:///A:/"))
970
 
        self.assertEquals("",
 
970
        self.assertEqual("",
971
971
            urlutils.file_relpath("file:///A:/b/", "file:///A:/b/"))
972
 
        self.assertEquals("",
 
972
        self.assertEqual("",
973
973
            urlutils.file_relpath("file:///A:/b", "file:///A:/b/"))
974
 
        self.assertEquals("",
 
974
        self.assertEqual("",
975
975
            urlutils.file_relpath("file:///A:/b/", "file:///A:/b"))
976
976
 
977
977
    def test_child_posix(self):
978
978
        self._with_posix_paths()
979
 
        self.assertEquals("b",
 
979
        self.assertEqual("b",
980
980
            urlutils.file_relpath("file:///a", "file:///a/b"))
981
 
        self.assertEquals("b",
 
981
        self.assertEqual("b",
982
982
            urlutils.file_relpath("file:///a/", "file:///a/b"))
983
 
        self.assertEquals("b/c",
 
983
        self.assertEqual("b/c",
984
984
            urlutils.file_relpath("file:///a", "file:///a/b/c"))
985
985
 
986
986
    def test_child_win32(self):
987
987
        self._with_win32_paths()
988
 
        self.assertEquals("b",
 
988
        self.assertEqual("b",
989
989
            urlutils.file_relpath("file:///A:/", "file:///A:/b"))
990
 
        self.assertEquals("b",
 
990
        self.assertEqual("b",
991
991
            urlutils.file_relpath("file:///A|/", "file:///A:/b"))
992
 
        self.assertEquals("c",
 
992
        self.assertEqual("c",
993
993
            urlutils.file_relpath("file:///A:/b", "file:///A:/b/c"))
994
 
        self.assertEquals("c",
 
994
        self.assertEqual("c",
995
995
            urlutils.file_relpath("file:///A:/b/", "file:///A:/b/c"))
996
 
        self.assertEquals("c/d",
 
996
        self.assertEqual("c/d",
997
997
            urlutils.file_relpath("file:///A:/b", "file:///A:/b/c/d"))
998
998
 
999
999
    def test_sibling_posix(self):