summaryrefslogtreecommitdiff
path: root/setuptools/tests
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py4
-rw-r--r--setuptools/tests/contexts.py6
-rw-r--r--setuptools/tests/server.py18
-rw-r--r--setuptools/tests/test_bdist_egg.py1
-rw-r--r--setuptools/tests/test_easy_install.py16
-rw-r--r--setuptools/tests/test_packageindex.py13
-rw-r--r--setuptools/tests/test_sdist.py26
-rw-r--r--setuptools/tests/test_test.py2
8 files changed, 44 insertions, 42 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index b8a29cba..8cde6f60 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -7,8 +7,8 @@ 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
+import six
import pytest
import setuptools.dist
@@ -47,7 +47,7 @@ class TestDepends:
x = "test"
y = z
- fc = func_code(f1)
+ fc = six.get_function_code(f1)
# unrecognized name
assert dep.extract_constant(fc,'q', -1) is None
diff --git a/setuptools/tests/contexts.py b/setuptools/tests/contexts.py
index d06a333f..fabab071 100644
--- a/setuptools/tests/contexts.py
+++ b/setuptools/tests/contexts.py
@@ -5,7 +5,7 @@ import sys
import contextlib
import site
-from ..compat import StringIO
+import six
@contextlib.contextmanager
@@ -65,8 +65,8 @@ def quiet():
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/server.py b/setuptools/tests/server.py
index 6b214279..1fee0563 100644
--- a/setuptools/tests/server.py
+++ b/setuptools/tests/server.py
@@ -3,10 +3,10 @@
import time
import threading
-from setuptools.compat import BaseHTTPRequestHandler
-from setuptools.compat import HTTPServer, SimpleHTTPRequestHandler
-class IndexServer(HTTPServer):
+from six.moves import BaseHTTPServer, SimpleHTTPServer
+
+class IndexServer(BaseHTTPServer.HTTPServer):
"""Basic single-threaded http server simulating a package index
You can use this server in unittest like this::
@@ -18,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 start(self):
@@ -40,19 +41,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 ccfb2ea7..f8a68378 100644
--- a/setuptools/tests/test_bdist_egg.py
+++ b/setuptools/tests/test_bdist_egg.py
@@ -3,6 +3,7 @@
import os
import re
+import six
import pytest
from setuptools.dist import Distribution
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 04271178..5d5ec16d 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -13,13 +13,14 @@ import contextlib
import tarfile
import logging
import itertools
+import io
+import six
+from six.moves import urllib
import pytest
import mock
from setuptools import sandbox
-from setuptools import compat
-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,
@@ -287,7 +288,7 @@ class TestSetupRequires:
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.
@@ -410,12 +411,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())
with tarfile_open(dist_path, 'w:gz') as dist:
dist.addfile(setup_py_file, fileobj=setup_py_bytes)
@@ -442,7 +438,7 @@ class TestScriptHeader:
assert candidate == '#!"%s"\n' % self.exe_with_spaces
@pytest.mark.xfail(
- compat.PY3 and os.environ.get("LC_CTYPE") in ("C", "POSIX"),
+ six.PY3 and os.environ.get("LC_CTYPE") in ("C", "POSIX"),
reason="Test fails in this locale on Python 3"
)
@mock.patch.dict(sys.modules, java=mock.Mock(lang=mock.Mock(System=
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index 3e9d1d84..4eb98bb1 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -1,7 +1,8 @@
import sys
import distutils.errors
-from setuptools.compat import httplib, HTTPError, unicode, pathname2url
+import six
+from six.moves import urllib, http_client
import pkg_resources
import setuptools.package_index
@@ -19,7 +20,7 @@ class TestPackageIndex:
v = sys.exc_info()[1]
assert url in str(v)
else:
- assert isinstance(v, HTTPError)
+ assert isinstance(v, urllib.error.HTTPError)
def test_bad_url_typo(self):
# issue 16
@@ -36,7 +37,7 @@ class TestPackageIndex:
v = sys.exc_info()[1]
assert url in str(v)
else:
- assert isinstance(v, HTTPError)
+ assert isinstance(v, urllib.error.HTTPError)
def test_bad_url_bad_status_line(self):
index = setuptools.package_index.PackageIndex(
@@ -44,7 +45,7 @@ class TestPackageIndex:
)
def _urlopen(*args):
- raise httplib.BadStatusLine('line')
+ raise http_client.BadStatusLine('line')
index.opener = _urlopen
url = 'http://example.com'
@@ -70,7 +71,7 @@ class TestPackageIndex:
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")
@@ -167,7 +168,7 @@ class TestPackageIndex:
index_file = tmpdir / 'index.html'
with index_file.open('w') as f:
f.write('<div>content</div>')
- url = 'file:' + pathname2url(str(tmpdir)) + '/'
+ url = 'file:' + urllib.request.pathname2url(str(tmpdir)) + '/'
res = setuptools.package_index.local_open(url)
assert 'content' in res.read()
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index 943a5dee..d30e21ac 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -9,10 +9,10 @@ import tempfile
import unicodedata
import contextlib
+import six
import pytest
import pkg_resources
-from setuptools.compat import StringIO, unicode, PY3, PY2
from setuptools.command.sdist import sdist
from setuptools.command.egg_info import manifest_maker
from setuptools.dist import Distribution
@@ -32,7 +32,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'
@@ -42,7 +42,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:
@@ -51,14 +51,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, '/')
@@ -66,7 +66,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')
@@ -179,14 +179,14 @@ class TestSdistTest:
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)
assert posix(filename) in u_contents
# Python 3 only
- if PY3:
+ if six.PY3:
def test_write_manifest_allows_utf8_filenames(self):
# Test for #303.
@@ -295,12 +295,12 @@ class TestSdistTest:
cmd.read_manifest()
# The filelist should contain the UTF-8 filename
- if PY3:
+ if six.PY3:
filename = filename.decode('utf-8')
assert 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.
@@ -336,7 +336,7 @@ class TestSdistTest:
filename = filename.decode('latin-1')
assert filename not in cmd.filelist.files
- @pytest.mark.skipif(PY3 and locale.getpreferredencoding() != 'UTF-8',
+ @pytest.mark.skipif(six.PY3 and locale.getpreferredencoding() != 'UTF-8',
reason='Unittest fails if locale is not utf-8 but the manifests is '
'recorded correctly')
def test_sdist_with_utf8_encoded_filename(self):
@@ -356,7 +356,7 @@ class TestSdistTest:
if sys.platform == 'darwin':
filename = decompose(filename)
- if PY3:
+ if six.PY3:
fs_enc = sys.getfilesystemencoding()
if sys.platform == 'win32':
@@ -388,7 +388,7 @@ class TestSdistTest:
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_test.py b/setuptools/tests/test_test.py
index a66294c9..6587dc40 100644
--- a/setuptools/tests/test_test.py
+++ b/setuptools/tests/test_test.py
@@ -4,7 +4,9 @@ from __future__ import unicode_literals
import os
import site
+from distutils.errors import DistutilsError
+import six
import pytest
from setuptools.command.test import test