aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-07-05 15:06:51 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-07-05 15:06:51 -0400
commitb49435397a5094f94678adf3549cc8941aa469b7 (patch)
treeb123bdd63482393ba1e2859364920f40a3d9f71d /setuptools/tests
parent5b865b1b6e23379d23aa80e74adb38db8b14b6ca (diff)
downloadexternal_python_setuptools-b49435397a5094f94678adf3549cc8941aa469b7.tar.gz
external_python_setuptools-b49435397a5094f94678adf3549cc8941aa469b7.tar.bz2
external_python_setuptools-b49435397a5094f94678adf3549cc8941aa469b7.zip
Use six for Python 2 compatibility
--HG-- branch : feature/issue-229 extra : source : 7b1997ececc5772798ce33a0f8e77387cb55a977
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py6
-rw-r--r--setuptools/tests/server.py25
-rw-r--r--setuptools/tests/test_bdist_egg.py6
-rw-r--r--setuptools/tests/test_easy_install.py18
-rw-r--r--setuptools/tests/test_packageindex.py17
-rw-r--r--setuptools/tests/test_resources.py11
-rw-r--r--setuptools/tests/test_sdist.py29
-rw-r--r--setuptools/tests/test_svn.py13
-rw-r--r--setuptools/tests/test_test.py9
9 files changed, 70 insertions, 64 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index d6a4542e..823cf937 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -9,9 +9,9 @@ from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.errors import DistutilsSetupError
from distutils.core import Extension
from distutils.version import LooseVersion
-from setuptools.compat import func_code
-from setuptools.compat import func_code
+import six
+
import setuptools.dist
import setuptools.depends as dep
from setuptools import Feature
@@ -54,7 +54,7 @@ class DependsTests(unittest.TestCase):
x = "test"
y = z
- fc = func_code(f1)
+ fc = six.get_function_code(f1)
# unrecognized name
self.assertEqual(dep.extract_constant(fc,'q', -1), None)
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py
index ae2381e3..099e8b19 100644
--- a/setuptools/tests/server.py
+++ b/setuptools/tests/server.py
@@ -3,11 +3,10 @@
import sys
import time
import threading
-from setuptools.compat import BaseHTTPRequestHandler
-from setuptools.compat import (urllib2, URLError, HTTPServer,
- SimpleHTTPRequestHandler)
-class IndexServer(HTTPServer):
+from six.moves import BaseHTTPServer, SimpleHTTPServer, urllib
+
+class IndexServer(BaseHTTPServer.HTTPServer):
"""Basic single-threaded http server simulating a package index
You can use this server in unittest like this::
@@ -19,8 +18,9 @@ class IndexServer(HTTPServer):
s.stop()
"""
def __init__(self, server_address=('', 0),
- RequestHandlerClass=SimpleHTTPRequestHandler):
- HTTPServer.__init__(self, server_address, RequestHandlerClass)
+ RequestHandlerClass=SimpleHTTPServer.SimpleHTTPRequestHandler):
+ BaseHTTPServer.HTTPServer.__init__(self, server_address,
+ RequestHandlerClass)
self._run = True
def serve(self):
@@ -44,10 +44,10 @@ class IndexServer(HTTPServer):
url = 'http://127.0.0.1:%(server_port)s/' % vars(self)
try:
if sys.version_info >= (2, 6):
- urllib2.urlopen(url, timeout=5)
+ urllib.request.urlopen(url, timeout=5)
else:
- urllib2.urlopen(url)
- except URLError:
+ urllib.request.urlopen(url)
+ except urllib.error.URLError:
# ignore any errors; all that's important is the request
pass
self.thread.join()
@@ -57,19 +57,20 @@ class IndexServer(HTTPServer):
port = self.server_port
return 'http://127.0.0.1:%s/setuptools/tests/indexes/' % port
-class RequestRecorder(BaseHTTPRequestHandler):
+class RequestRecorder(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
requests = vars(self.server).setdefault('requests', [])
requests.append(self)
self.send_response(200, 'OK')
-class MockServer(HTTPServer, threading.Thread):
+class MockServer(BaseHTTPServer.HTTPServer, threading.Thread):
"""
A simple HTTP Server that records the requests made to it.
"""
def __init__(self, server_address=('', 0),
RequestHandlerClass=RequestRecorder):
- HTTPServer.__init__(self, server_address, RequestHandlerClass)
+ BaseHTTPServer.HTTPServer.__init__(self, server_address,
+ RequestHandlerClass)
threading.Thread.__init__(self)
self.setDaemon(True)
self.requests = []
diff --git a/setuptools/tests/test_bdist_egg.py b/setuptools/tests/test_bdist_egg.py
index cf4bcd11..937e0ed0 100644
--- a/setuptools/tests/test_bdist_egg.py
+++ b/setuptools/tests/test_bdist_egg.py
@@ -8,8 +8,9 @@ import sys
import tempfile
import unittest
+import six
+
from distutils.errors import DistutilsError
-from setuptools.compat import StringIO
from setuptools.command.bdist_egg import bdist_egg
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
@@ -56,7 +57,7 @@ class TestDevelopTest(unittest.TestCase):
))
os.makedirs(os.path.join('build', 'src'))
old_stdout = sys.stdout
- sys.stdout = o = StringIO()
+ sys.stdout = o = six.StringIO()
try:
dist.parse_command_line()
dist.run_commands()
@@ -69,4 +70,3 @@ class TestDevelopTest(unittest.TestCase):
def test_suite():
return unittest.makeSuite(TestDevelopTest)
-
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index a4430953..8dfe234e 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -11,8 +11,11 @@ import textwrap
import tarfile
import logging
import distutils.core
+import io
+
+import six
+from six.moves import urllib
-from setuptools.compat import StringIO, BytesIO, urlparse
from setuptools.sandbox import run_setup, SandboxViolation
from setuptools.command.easy_install import (
easy_install, fix_jython_executable, get_script_args, nt_quote_arg)
@@ -261,7 +264,7 @@ class TestSetupRequires(unittest.TestCase):
p_index = setuptools.tests.server.MockServer()
p_index.start()
netloc = 1
- p_index_loc = urlparse(p_index.url)[netloc]
+ p_index_loc = urllib.parse.urlparse(p_index.url)[netloc]
if p_index_loc.endswith(':0'):
# Some platforms (Jython) don't find a port to which to bind,
# so skip this test for them.
@@ -385,12 +388,7 @@ def make_trivial_sdist(dist_path, setup_py):
"""
setup_py_file = tarfile.TarInfo(name='setup.py')
- try:
- # Python 3 (StringIO gets converted to io module)
- MemFile = BytesIO
- except AttributeError:
- MemFile = StringIO
- setup_py_bytes = MemFile(setup_py.encode('utf-8'))
+ setup_py_bytes = io.BytesIO(setup_py.encode('utf-8'))
setup_py_file.size = len(setup_py_bytes.getvalue())
dist = tarfile.open(dist_path, 'w:gz')
try:
@@ -451,8 +449,8 @@ def quiet_context():
old_stdout = sys.stdout
old_stderr = sys.stderr
- new_stdout = sys.stdout = StringIO()
- new_stderr = sys.stderr = StringIO()
+ new_stdout = sys.stdout = six.StringIO()
+ new_stderr = sys.stderr = six.StringIO()
try:
yield new_stdout, new_stderr
finally:
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index 664566a3..40ae0af3 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -3,9 +3,12 @@
import sys
import os
import unittest
-import pkg_resources
-from setuptools.compat import urllib2, httplib, HTTPError, unicode, pathname2url
import distutils.errors
+
+import six
+from six.moves import urllib, http_client
+
+import pkg_resources
import setuptools.package_index
from setuptools.tests.server import IndexServer
@@ -20,7 +23,7 @@ class TestPackageIndex(unittest.TestCase):
v = sys.exc_info()[1]
self.assertTrue(url in str(v))
else:
- self.assertTrue(isinstance(v, HTTPError))
+ self.assertTrue(isinstance(v, urllib.error.HTTPError))
def test_bad_url_typo(self):
# issue 16
@@ -37,7 +40,7 @@ class TestPackageIndex(unittest.TestCase):
v = sys.exc_info()[1]
self.assertTrue(url in str(v))
else:
- self.assertTrue(isinstance(v, HTTPError))
+ self.assertTrue(isinstance(v, urllib.error.HTTPError))
def test_bad_url_bad_status_line(self):
index = setuptools.package_index.PackageIndex(
@@ -45,7 +48,7 @@ class TestPackageIndex(unittest.TestCase):
)
def _urlopen(*args):
- raise httplib.BadStatusLine('line')
+ raise http_client.BadStatusLine('line')
index.opener = _urlopen
url = 'http://example.com'
@@ -71,7 +74,7 @@ class TestPackageIndex(unittest.TestCase):
index.open_url(url)
except distutils.errors.DistutilsError:
error = sys.exc_info()[1]
- msg = unicode(error)
+ msg = six.text_type(error)
assert 'nonnumeric port' in msg or 'getaddrinfo failed' in msg or 'Name or service not known' in msg
return
raise RuntimeError("Did not raise")
@@ -160,7 +163,7 @@ class TestPackageIndex(unittest.TestCase):
f.write('<div>content</div>')
f.close()
try:
- url = 'file:' + pathname2url(os.getcwd()) + '/'
+ url = 'file:' + urllib.request.pathname2url(os.getcwd()) + '/'
res = setuptools.package_index.local_open(url)
finally:
os.remove('index.html')
diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py
index 443905cc..2db87efa 100644
--- a/setuptools/tests/test_resources.py
+++ b/setuptools/tests/test_resources.py
@@ -15,7 +15,8 @@ from pkg_resources import (parse_requirements, VersionConflict, parse_version,
from setuptools.command.easy_install import (get_script_header, is_sh,
nt_quote_arg)
-from setuptools.compat import StringIO, iteritems, PY3
+
+import six
try:
frozenset
@@ -270,7 +271,7 @@ class EntryPointTests(TestCase):
def checkSubMap(self, m):
self.assertEqual(len(m), len(self.submap_expect))
- for key, ep in iteritems(self.submap_expect):
+ for key, ep in six.iteritems(self.submap_expect):
self.assertEqual(repr(m.get(key)), repr(ep))
submap_expect = dict(
@@ -522,7 +523,7 @@ class ScriptHeaderTests(TestCase):
def test_get_script_header_jython_workaround(self):
# This test doesn't work with Python 3 in some locales
- if PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"):
+ if six.PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"):
return
class java:
@@ -545,12 +546,12 @@ class ScriptHeaderTests(TestCase):
# Ensure we generate what is basically a broken shebang line
# when there's options, with a warning emitted
- sys.stdout = sys.stderr = StringIO()
+ sys.stdout = sys.stderr = six.StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python -x',
executable=exe),
'#!%s -x\n' % exe)
self.assertTrue('Unable to adapt shebang line' in sys.stdout.getvalue())
- sys.stdout = sys.stderr = StringIO()
+ sys.stdout = sys.stderr = six.StringIO()
self.assertEqual(get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe),
'#!%s -x\n' % self.non_ascii_exe)
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index 5b3862e9..c78e5b0f 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -10,10 +10,11 @@ import unittest
import unicodedata
import re
import contextlib
+
+import six
+
from setuptools.tests import environment, test_svn
from setuptools.tests.py26compat import skipIf
-
-from setuptools.compat import StringIO, unicode, PY3, PY2
from setuptools.command.sdist import sdist, walk_revctrl
from setuptools.command.egg_info import manifest_maker
from setuptools.dist import Distribution
@@ -34,7 +35,7 @@ setup(**%r)
""" % SETUP_ATTRS
-if PY3:
+if six.PY3:
LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1')
else:
LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py'
@@ -44,7 +45,7 @@ else:
@contextlib.contextmanager
def quiet():
old_stdout, old_stderr = sys.stdout, sys.stderr
- sys.stdout, sys.stderr = StringIO(), StringIO()
+ sys.stdout, sys.stderr = six.StringIO(), six.StringIO()
try:
yield
finally:
@@ -53,14 +54,14 @@ def quiet():
# Fake byte literals for Python <= 2.5
def b(s, encoding='utf-8'):
- if PY3:
+ if six.PY3:
return s.encode(encoding)
return s
# Convert to POSIX path
def posix(path):
- if PY3 and not isinstance(path, str):
+ if six.PY3 and not isinstance(path, str):
return path.replace(os.sep.encode('ascii'), b('/'))
else:
return path.replace(os.sep, '/')
@@ -68,7 +69,7 @@ def posix(path):
# HFS Plus uses decomposed UTF-8
def decompose(path):
- if isinstance(path, unicode):
+ if isinstance(path, six.text_type):
return unicodedata.normalize('NFD', path)
try:
path = path.decode('utf-8')
@@ -153,14 +154,14 @@ class TestSdistTest(unittest.TestCase):
self.fail(e)
# The manifest should contain the UTF-8 filename
- if PY2:
+ if six.PY2:
fs_enc = sys.getfilesystemencoding()
filename = filename.decode(fs_enc)
self.assertTrue(posix(filename) in u_contents)
# Python 3 only
- if PY3:
+ if six.PY3:
def test_write_manifest_allows_utf8_filenames(self):
# Test for #303.
@@ -269,12 +270,12 @@ class TestSdistTest(unittest.TestCase):
cmd.read_manifest()
# The filelist should contain the UTF-8 filename
- if PY3:
+ if six.PY3:
filename = filename.decode('utf-8')
self.assertTrue(filename in cmd.filelist.files)
# Python 3 only
- if PY3:
+ if six.PY3:
def test_read_manifest_skips_non_utf8_filenames(self):
# Test for #303.
@@ -310,7 +311,7 @@ class TestSdistTest(unittest.TestCase):
filename = filename.decode('latin-1')
self.assertFalse(filename in cmd.filelist.files)
- @skipIf(PY3 and locale.getpreferredencoding() != 'UTF-8',
+ @skipIf(six.PY3 and locale.getpreferredencoding() != 'UTF-8',
'Unittest fails if locale is not utf-8 but the manifests is recorded correctly')
def test_sdist_with_utf8_encoded_filename(self):
# Test for #303.
@@ -329,7 +330,7 @@ class TestSdistTest(unittest.TestCase):
if sys.platform == 'darwin':
filename = decompose(filename)
- if PY3:
+ if six.PY3:
fs_enc = sys.getfilesystemencoding()
if sys.platform == 'win32':
@@ -361,7 +362,7 @@ class TestSdistTest(unittest.TestCase):
with quiet():
cmd.run()
- if PY3:
+ if six.PY3:
# not all windows systems have a default FS encoding of cp1252
if sys.platform == 'win32':
# Latin-1 is similar to Windows-1252 however
diff --git a/setuptools/tests/test_svn.py b/setuptools/tests/test_svn.py
index 33400362..0e6c3e95 100644
--- a/setuptools/tests/test_svn.py
+++ b/setuptools/tests/test_svn.py
@@ -6,9 +6,10 @@ import os
import subprocess
import sys
import unittest
-from setuptools.tests import environment
-from setuptools.compat import unicode, unichr
+import six
+
+from setuptools.tests import environment
from setuptools import svn_utils
from setuptools.tests.py26compat import skipIf
@@ -119,13 +120,13 @@ class ParserExternalXML(unittest.TestCase):
os.sep.join((example_base, folder3)),
# folder is third_party大介
os.sep.join((example_base,
- unicode('third_party') +
- unichr(0x5927) + unichr(0x4ecb))),
+ six.text_type('third_party') +
+ six.unichr(0x5927) + six.unichr(0x4ecb))),
os.sep.join((example_base, 'folder', folder2)),
os.sep.join((example_base, 'folder', folder3)),
os.sep.join((example_base, 'folder',
- unicode('third_party') +
- unichr(0x5927) + unichr(0x4ecb))),
+ six.text_type('third_party') +
+ six.unichr(0x5927) + six.unichr(0x4ecb))),
])
expected = set(os.path.normpath(x) for x in expected)
diff --git a/setuptools/tests/test_test.py b/setuptools/tests/test_test.py
index df92085e..67df14e5 100644
--- a/setuptools/tests/test_test.py
+++ b/setuptools/tests/test_test.py
@@ -8,9 +8,10 @@ import site
import sys
import tempfile
import unittest
-
from distutils.errors import DistutilsError
-from setuptools.compat import StringIO, PY2
+
+import six
+
from setuptools.command.test import test
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
@@ -34,7 +35,7 @@ except ImportError:
__path__ = extend_path(__path__, __name__)
"""
# Make sure this is Latin-1 binary, before writing:
-if PY2:
+if six.PY2:
NS_INIT = NS_INIT.decode('UTF-8')
NS_INIT = NS_INIT.encode('Latin-1')
@@ -115,7 +116,7 @@ class TestTestTest(unittest.TestCase):
cmd.install_dir = site.USER_SITE
cmd.user = 1
old_stdout = sys.stdout
- sys.stdout = StringIO()
+ sys.stdout = six.StringIO()
try:
try: # try/except/finally doesn't work in Python 2.4, so we need nested try-statements.
cmd.run()