1107
1105
result = http.unhtml_roughly(fake_html)
1108
1106
self.assertEqual(len(result), 1000)
1109
1107
self.assertStartsWith(result, " something!")
1112
class SomeDirectory(object):
1114
def look_up(self, name, url):
1118
class TestLocationToUrl(tests.TestCase):
1120
def get_base_location(self):
1121
path = osutils.abspath('/foo/bar')
1122
if path.startswith('/'):
1123
url = 'file://%s' % (path,)
1125
# On Windows, abspaths start with the drive letter, so we have to
1126
# add in the extra '/'
1127
url = 'file:///%s' % (path,)
1130
def test_regular_url(self):
1131
self.assertEqual("file://foo", location_to_url("file://foo"))
1133
def test_directory(self):
1134
directories.register("bar:", SomeDirectory, "Dummy directory")
1135
self.addCleanup(directories.remove, "bar:")
1136
self.assertEqual("http://bar", location_to_url("bar:"))
1138
def test_unicode_url(self):
1139
self.assertRaises(urlutils.InvalidURL, location_to_url,
1140
b"http://fo/\xc3\xaf".decode("utf-8"))
1142
def test_unicode_path(self):
1143
path, url = self.get_base_location()
1144
location = path + b"\xc3\xaf".decode("utf-8")
1146
self.assertEqual(url, location_to_url(location))
1148
def test_path(self):
1149
path, url = self.get_base_location()
1150
self.assertEqual(url, location_to_url(path))
1152
def test_relative_file_url(self):
1153
self.assertEqual(urlutils.local_path_to_url(".") + "/bar",
1154
location_to_url("file:bar"))
1156
def test_absolute_file_url(self):
1157
self.assertEqual("file:///bar", location_to_url("file:/bar"))