95
class TestUrlToPath(TestCase):
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)
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)
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'))
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'))
121
self.assertRaises(InvalidURL, from_url, '/path/to/foo')
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'))
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'))
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')
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'))
151
eq('/foo/path', disp('file:///foo/path'))
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'))
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'))
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'))
165
94
class TestWin32Funcs(TestCase):
166
95
"""Test that the _win32 versions of os utilities return appropriate paths."""