/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: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

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
666
678
        # Test that URLs are converted to nice unicode strings for display
667
679
        def test(expected, url, encoding='utf-8'):
668
680
            disp_url = urlutils.unescape_for_display(url, encoding=encoding)
669
 
            self.assertIsInstance(disp_url, str)
 
681
            self.assertIsInstance(disp_url, text_type)
670
682
            self.assertEqual(expected, disp_url)
671
683
 
672
684
        test('http://foo', 'http://foo')
715
727
        self.assertEqual('%', urlutils.unescape('%25'))
716
728
        self.assertEqual(u'\xe5', urlutils.unescape('%C3%A5'))
717
729
 
 
730
        if not PY3:
 
731
            self.assertRaises(urlutils.InvalidURL, urlutils.unescape, u'\xe5')
718
732
        self.assertRaises((TypeError, urlutils.InvalidURL),
719
733
                          urlutils.unescape, b'\xe5')
720
 
        self.assertEqual('\xe5', urlutils.unescape('%C3%A5'))
 
734
        if not PY3:
 
735
            self.assertRaises(urlutils.InvalidURL, urlutils.unescape, '%E5')
 
736
        else:
 
737
            self.assertEqual('\xe5', urlutils.unescape('%C3%A5'))
721
738
 
722
739
    def test_escape_unescape(self):
723
740
        self.assertEqual(u'\xe5', urlutils.unescape(urlutils.escape(u'\xe5')))
1123
1140
 
1124
1141
    def test_unquote(self):
1125
1142
        self.assertEqual('%', urlutils.unquote('%25'))
1126
 
        self.assertEqual('\xe5', urlutils.unquote('%C3%A5'))
 
1143
        if PY3:
 
1144
            self.assertEqual('\xe5', urlutils.unquote('%C3%A5'))
 
1145
        else:
 
1146
            self.assertEqual('\xc3\xa5', urlutils.unquote('%C3%A5'))
1127
1147
        self.assertEqual(u"\xe5", urlutils.unquote(u'\xe5'))
1128
1148
 
1129
1149
    def test_unquote_to_bytes(self):