/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_urlutils.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from ..errors import (
24
24
    PathNotChild,
25
25
    )
 
26
from ..sixish import (
 
27
    text_type,
 
28
    PY3,
 
29
    )
26
30
from . import features, TestCaseInTempDir, TestCase, TestSkipped
27
31
 
28
32
 
125
129
        eq('http://host/~bob%2525-._',
126
130
           normalize_url(u'http://host/%7Ebob%2525%2D%2E%5F'))
127
131
 
 
132
        if not PY3:
 
133
            # On Python 2, normalize verifies URLs when they are not unicode
 
134
            # (indicating they did not come from the user)
 
135
            self.assertRaises(urlutils.InvalidURL, normalize_url,
 
136
                              b'http://host/\xb5')
 
137
            self.assertRaises(urlutils.InvalidURL,
 
138
                              normalize_url, b'http://host/ ')
 
139
 
128
140
    def test_url_scheme_re(self):
129
141
        # Test paths that may be URLs
130
142
        def test_one(url, scheme_and_path):
437
449
 
438
450
        self.assertEqual(
439
451
            'file://HOST/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s', result)
440
 
        self.assertFalse(isinstance(result, str))
 
452
        self.assertFalse(isinstance(result, text_type))
441
453
 
442
454
    def test_win32_local_path_from_url(self):
443
455
        from_url = urlutils._win32_local_path_from_url
527
539
        self.assertEqual(('path/..', 'foo'), split('path/../foo'))
528
540
        self.assertEqual(('../path', 'foo'), split('../path/foo'))
529
541
 
530
 
    def test_strip_segment_parameters(self):
531
 
        strip_segment_parameters = urlutils.strip_segment_parameters
532
 
        # Check relative references with absolute paths
533
 
        self.assertEqual("/some/path",
534
 
                         strip_segment_parameters("/some/path"))
535
 
        self.assertEqual("/some/path",
536
 
                         strip_segment_parameters("/some/path,tip"))
537
 
        self.assertEqual("/some,dir/path",
538
 
                         strip_segment_parameters("/some,dir/path,tip"))
539
 
        self.assertEqual(
540
 
            "/somedir/path",
541
 
            strip_segment_parameters("/somedir/path,heads%2Ftip"))
542
 
        self.assertEqual(
543
 
            "/somedir/path",
544
 
            strip_segment_parameters("/somedir/path,heads%2Ftip,bar"))
545
 
        # Check relative references with relative paths
546
 
        self.assertEqual("", strip_segment_parameters(",key1=val1"))
547
 
        self.assertEqual("foo/", strip_segment_parameters("foo/,key1=val1"))
548
 
        self.assertEqual("foo", strip_segment_parameters("foo,key1=val1"))
549
 
        self.assertEqual(
550
 
            "foo/base,la=bla/other/elements",
551
 
            strip_segment_parameters("foo/base,la=bla/other/elements"))
552
 
        self.assertEqual(
553
 
            "foo/base,la=bla/other/elements",
554
 
            strip_segment_parameters("foo/base,la=bla/other/elements,a=b"))
555
 
        # TODO: Check full URLs as well as relative references
556
 
 
557
542
    def test_split_segment_parameters_raw(self):
558
543
        split_segment_parameters_raw = urlutils.split_segment_parameters_raw
559
544
        # Check relative references with absolute paths
666
651
        # Test that URLs are converted to nice unicode strings for display
667
652
        def test(expected, url, encoding='utf-8'):
668
653
            disp_url = urlutils.unescape_for_display(url, encoding=encoding)
669
 
            self.assertIsInstance(disp_url, str)
 
654
            self.assertIsInstance(disp_url, text_type)
670
655
            self.assertEqual(expected, disp_url)
671
656
 
672
657
        test('http://foo', 'http://foo')
715
700
        self.assertEqual('%', urlutils.unescape('%25'))
716
701
        self.assertEqual(u'\xe5', urlutils.unescape('%C3%A5'))
717
702
 
 
703
        if not PY3:
 
704
            self.assertRaises(urlutils.InvalidURL, urlutils.unescape, u'\xe5')
718
705
        self.assertRaises((TypeError, urlutils.InvalidURL),
719
706
                          urlutils.unescape, b'\xe5')
720
 
        self.assertEqual('\xe5', urlutils.unescape('%C3%A5'))
 
707
        if not PY3:
 
708
            self.assertRaises(urlutils.InvalidURL, urlutils.unescape, '%E5')
 
709
        else:
 
710
            self.assertEqual('\xe5', urlutils.unescape('%C3%A5'))
721
711
 
722
712
    def test_escape_unescape(self):
723
713
        self.assertEqual(u'\xe5', urlutils.unescape(urlutils.escape(u'\xe5')))
1123
1113
 
1124
1114
    def test_unquote(self):
1125
1115
        self.assertEqual('%', urlutils.unquote('%25'))
1126
 
        self.assertEqual('\xe5', urlutils.unquote('%C3%A5'))
 
1116
        if PY3:
 
1117
            self.assertEqual('\xe5', urlutils.unquote('%C3%A5'))
 
1118
        else:
 
1119
            self.assertEqual('\xc3\xa5', urlutils.unquote('%C3%A5'))
1127
1120
        self.assertEqual(u"\xe5", urlutils.unquote(u'\xe5'))
1128
1121
 
1129
1122
    def test_unquote_to_bytes(self):