/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 bzrlib/tests/test_osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-05-02 20:46:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060502204611-02caa5c20fb84ef8
Moved url functions into bzrlib.urlutils

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
"""Tests for the osutils wrapper.
18
 
"""
 
17
"""Tests for the osutils wrapper."""
19
18
 
20
19
import os
21
20
import sys
92
91
                          '\xbb\xbb')
93
92
 
94
93
 
95
 
class TestUrlToPath(TestCase):
96
 
    
97
 
    def test_function_type(self):
98
 
        if sys.platform == 'win32':
99
 
            self.assertEqual(osutils._win32_local_path_to_url, osutils.local_path_to_url)
100
 
            self.assertEqual(osutils._win32_local_path_from_url, osutils.local_path_from_url)
101
 
        else:
102
 
            self.assertEqual(osutils._posix_local_path_to_url, osutils.local_path_to_url)
103
 
            self.assertEqual(osutils._posix_local_path_from_url, osutils.local_path_from_url)
104
 
 
105
 
    def test_posix_local_path_to_url(self):
106
 
        to_url = osutils._posix_local_path_to_url
107
 
        self.assertEqual('file:///path/to/foo',
108
 
            to_url('/path/to/foo'))
109
 
        self.assertEqual('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s',
110
 
            to_url(u'/path/to/r\xe4ksm\xf6rg\xe5s'))
111
 
 
112
 
    def test_posix_local_path_from_url(self):
113
 
        from_url = osutils._posix_local_path_from_url
114
 
        self.assertEqual('/path/to/foo',
115
 
            from_url('file:///path/to/foo'))
116
 
        self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
117
 
            from_url('file:///path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
118
 
        self.assertEqual(u'/path/to/r\xe4ksm\xf6rg\xe5s',
119
 
            from_url('file:///path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
120
 
 
121
 
        self.assertRaises(InvalidURL, from_url, '/path/to/foo')
122
 
 
123
 
    def test_win32_local_path_to_url(self):
124
 
        to_url = osutils._win32_local_path_to_url
125
 
        self.assertEqual('file:///C|/path/to/foo',
126
 
            to_url('C:/path/to/foo'))
127
 
        self.assertEqual('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s',
128
 
            to_url(u'd:/path/to/r\xe4ksm\xf6rg\xe5s'))
129
 
 
130
 
    def test_win32_local_path_from_url(self):
131
 
        from_url = osutils._win32_local_path_from_url
132
 
        self.assertEqual('C:/path/to/foo',
133
 
            from_url('file:///C|/path/to/foo'))
134
 
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
135
 
            from_url('file:///d|/path/to/r%C3%A4ksm%C3%B6rg%C3%A5s'))
136
 
        self.assertEqual(u'd:/path/to/r\xe4ksm\xf6rg\xe5s',
137
 
            from_url('file:///d|/path/to/r%c3%a4ksm%c3%b6rg%c3%a5s'))
138
 
 
139
 
        self.assertRaises(InvalidURL, from_url, '/path/to/foo')
140
 
        # Not a valid _win32 url, no drive letter
141
 
        self.assertRaises(InvalidURL, from_url, 'file:///path/to/foo')
142
 
 
143
 
    def test_urlfordisplay(self):
144
 
        # Test that URLs are converted to nice unicode strings for display
145
 
        disp = osutils.urlfordisplay
146
 
        eq = self.assertEqual
147
 
        eq('http://foo', disp('http://foo'))
148
 
        if sys.platform == 'win32':
149
 
            eq('C:/foo/path', disp('file:///C|foo/path'))
150
 
        else:
151
 
            eq('/foo/path', disp('file:///foo/path'))
152
 
 
153
 
        eq('http://foo/%2Fbaz', disp('http://foo/%2Fbaz'))
154
 
        eq(u'http://host/r\xe4ksm\xf6rg\xe5s', disp('http://host/r%C3%A4ksm%C3%B6rg%C3%A5s'))
155
 
 
156
 
        # Make sure special escaped characters stay escaped
157
 
        eq(u'http://host/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23',
158
 
            disp('http://host/%3B%2F%3F%3A%40%26%3D%2B%24%2C%23'))
159
 
 
160
 
        # Can we handle sections that don't have utf-8 encoding?
161
 
        eq(u'http://host/%EE%EE%EE/r\xe4ksm\xf6rg\xe5s',
162
 
            disp('http://host/%EE%EE%EE/r%C3%A4ksm%C3%B6rg%C3%A5s'))
163
 
 
164
 
 
165
94
class TestWin32Funcs(TestCase):
166
95
    """Test that the _win32 versions of os utilities return appropriate paths."""
167
96