Commit 4ae4faeb authored by Jason R. Coombs's avatar Jason R. Coombs

Moved imports to the top, made them compatible with Python 2, and added a docstring.

parent a87729f8
...@@ -27,7 +27,7 @@ if sys.version_info[0] < 3: ...@@ -27,7 +27,7 @@ if sys.version_info[0] < 3:
unichr = unichr unichr = unichr
unicode = unicode unicode = unicode
bytes = str bytes = str
from urllib import url2pathname, splittag from urllib import url2pathname, splittag, pathname2url
import urllib2 import urllib2
from urllib2 import urlopen, HTTPError, URLError, unquote, splituser from urllib2 import urlopen, HTTPError, URLError, unquote, splituser
from urlparse import urlparse, urlunparse, urljoin, urlsplit, urlunsplit from urlparse import urlparse, urlunparse, urljoin, urlsplit, urlunsplit
...@@ -73,7 +73,7 @@ else: ...@@ -73,7 +73,7 @@ else:
bytes = bytes bytes = bytes
from urllib.error import HTTPError, URLError from urllib.error import HTTPError, URLError
import urllib.request as urllib2 import urllib.request as urllib2
from urllib.request import urlopen, url2pathname from urllib.request import urlopen, url2pathname, pathname2url
from urllib.parse import ( from urllib.parse import (
urlparse, urlunparse, unquote, splituser, urljoin, urlsplit, urlparse, urlunparse, unquote, splituser, urljoin, urlsplit,
urlunsplit, splittag, urlunsplit, splittag,
......
"""Package Index Tests """Package Index Tests
""" """
import sys import sys
import os
import unittest import unittest
import pkg_resources import pkg_resources
from setuptools.compat import urllib2, httplib, HTTPError, unicode from setuptools.compat import urllib2, httplib, HTTPError, unicode, pathname2url
import distutils.errors import distutils.errors
import setuptools.package_index import setuptools.package_index
from setuptools.tests.server import IndexServer from setuptools.tests.server import IndexServer
...@@ -152,13 +153,14 @@ class TestPackageIndex(unittest.TestCase): ...@@ -152,13 +153,14 @@ class TestPackageIndex(unittest.TestCase):
self.assertEqual(rev, '2995') self.assertEqual(rev, '2995')
def test_local_index(self): def test_local_index(self):
"""
local_open should be able to read an index from the file system.
"""
f = open('index.html', 'w') f = open('index.html', 'w')
f.write('<div>content</div>') f.write('<div>content</div>')
f.close() f.close()
try: try:
import urllib.request url = 'file:' + pathname2url(os.getcwd()) + '/'
import os
url = 'file:' + urllib.request.pathname2url(os.getcwd()) + '/'
res = setuptools.package_index.local_open(url) res = setuptools.package_index.local_open(url)
finally: finally:
os.remove('index.html') os.remove('index.html')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment