aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/__init__.py1
-rw-r--r--setuptools/tests/server.py14
-rw-r--r--setuptools/tests/test_develop.py13
-rw-r--r--setuptools/tests/test_dist_info.py43
-rw-r--r--setuptools/tests/test_easy_install.py2
-rw-r--r--setuptools/tests/test_packageindex.py3
-rw-r--r--setuptools/tests/test_sdist.py6
-rw-r--r--setuptools/tests/test_test.py12
-rw-r--r--setuptools/tests/win_script_wrapper.txt66
9 files changed, 73 insertions, 87 deletions
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 1cd5df2b..b5328ce6 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -9,6 +9,7 @@ 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 setuptools.dist
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py
index 5f5ed6bb..ae2381e3 100644
--- a/setuptools/tests/server.py
+++ b/setuptools/tests/server.py
@@ -2,10 +2,10 @@
"""
import sys
import time
-from threading import Thread
+import threading
+from setuptools.compat import BaseHTTPRequestHandler
from setuptools.compat import (urllib2, URLError, HTTPServer,
- SimpleHTTPRequestHandler,
- BaseHTTPRequestHandler)
+ SimpleHTTPRequestHandler)
class IndexServer(HTTPServer):
"""Basic single-threaded http server simulating a package index
@@ -28,7 +28,7 @@ class IndexServer(HTTPServer):
self.handle_request()
def start(self):
- self.thread = Thread(target=self.serve)
+ self.thread = threading.Thread(target=self.serve)
self.thread.start()
def stop(self):
@@ -47,7 +47,7 @@ class IndexServer(HTTPServer):
urllib2.urlopen(url, timeout=5)
else:
urllib2.urlopen(url)
- except urllib2.URLError:
+ except URLError:
# ignore any errors; all that's important is the request
pass
self.thread.join()
@@ -63,14 +63,14 @@ class RequestRecorder(BaseHTTPRequestHandler):
requests.append(self)
self.send_response(200, 'OK')
-class MockServer(HTTPServer, Thread):
+class MockServer(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)
- Thread.__init__(self)
+ threading.Thread.__init__(self)
self.setDaemon(True)
self.requests = []
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index e2939fea..7b90161a 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -90,11 +90,15 @@ class TestDevelopTest(unittest.TestCase):
# Check that we are using the right code.
egg_link_file = open(os.path.join(site.USER_SITE, 'foo.egg-link'), 'rt')
- path = egg_link_file.read().split()[0].strip()
- egg_link_file.close()
+ try:
+ path = egg_link_file.read().split()[0].strip()
+ finally:
+ egg_link_file.close()
init_file = open(os.path.join(path, 'foo', '__init__.py'), 'rt')
- init = init_file.read().strip()
- init_file.close()
+ try:
+ init = init_file.read().strip()
+ finally:
+ init_file.close()
if sys.version < "3":
self.assertEqual(init, 'print "foo"')
else:
@@ -116,4 +120,3 @@ class TestDevelopTest(unittest.TestCase):
pass
finally:
os.chdir(old_dir)
-
diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py
index fcb78c36..a8adb68c 100644
--- a/setuptools/tests/test_dist_info.py
+++ b/setuptools/tests/test_dist_info.py
@@ -51,30 +51,33 @@ class TestDistInfo(unittest.TestCase):
'VersionedDistribution-2.718.dist-info')
os.mkdir(versioned)
metadata_file = open(os.path.join(versioned, 'METADATA'), 'w+')
- metadata_file.write(DALS(
- """
- Metadata-Version: 1.2
- Name: VersionedDistribution
- Requires-Dist: splort (4)
- Provides-Extra: baz
- Requires-Dist: quux (>=1.1); extra == 'baz'
- """))
- metadata_file.close()
-
+ try:
+ metadata_file.write(DALS(
+ """
+ Metadata-Version: 1.2
+ Name: VersionedDistribution
+ Requires-Dist: splort (4)
+ Provides-Extra: baz
+ Requires-Dist: quux (>=1.1); extra == 'baz'
+ """))
+ finally:
+ metadata_file.close()
unversioned = os.path.join(self.tmpdir,
'UnversionedDistribution.dist-info')
os.mkdir(unversioned)
metadata_file = open(os.path.join(unversioned, 'METADATA'), 'w+')
- metadata_file.write(DALS(
- """
- Metadata-Version: 1.2
- Name: UnversionedDistribution
- Version: 0.3
- Requires-Dist: splort (==4)
- Provides-Extra: baz
- Requires-Dist: quux (>=1.1); extra == 'baz'
- """))
- metadata_file.close()
+ try:
+ metadata_file.write(DALS(
+ """
+ Metadata-Version: 1.2
+ Name: UnversionedDistribution
+ Version: 0.3
+ Requires-Dist: splort (==4)
+ Provides-Extra: baz
+ Requires-Dist: quux (>=1.1); extra == 'baz'
+ """))
+ finally:
+ metadata_file.close()
def tearDown(self):
shutil.rmtree(self.tmpdir)
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 66d43b62..b0609eb1 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -6,6 +6,8 @@ import shutil
import tempfile
import unittest
import site
+from setuptools.compat import StringIO, BytesIO, next
+from setuptools.compat import urlparse
import textwrap
import tarfile
import distutils.core
diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py
index c2ff0539..92d1e2e0 100644
--- a/setuptools/tests/test_packageindex.py
+++ b/setuptools/tests/test_packageindex.py
@@ -69,7 +69,8 @@ class TestPackageIndex(unittest.TestCase):
try:
index.open_url(url)
except distutils.errors.DistutilsError:
- msg = unicode(sys.exc_info()[1])
+ error = sys.exc_info()[1]
+ msg = unicode(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")
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index c1e7864b..a58b749c 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -342,7 +342,7 @@ class TestSdistTest(unittest.TestCase):
if sys.version_info >= (3,):
fs_enc = sys.getfilesystemencoding()
- if sys.platform == 'win32':
+ if sys.platform == 'win32':
if fs_enc == 'cp1252':
# Python 3 mangles the UTF-8 filename
filename = filename.decode('cp1252')
@@ -377,14 +377,14 @@ class TestSdistTest(unittest.TestCase):
if sys.version_info >= (3,):
#not all windows systems have a default FS encoding of cp1252
if sys.platform == 'win32':
- # Latin-1 is similar to Windows-1252 however
+ # Latin-1 is similar to Windows-1252 however
# on mbcs filesys it is not in latin-1 encoding
fs_enc = sys.getfilesystemencoding()
if fs_enc == 'mbcs':
filename = filename.decode('mbcs')
else:
filename = filename.decode('latin-1')
-
+
self.assertTrue(filename in cmd.filelist.files)
else:
# The Latin-1 filename should have been skipped
diff --git a/setuptools/tests/test_test.py b/setuptools/tests/test_test.py
index d6e68590..7a06a403 100644
--- a/setuptools/tests/test_test.py
+++ b/setuptools/tests/test_test.py
@@ -1,4 +1,4 @@
-# -*- coding: UTF-8 -*-
+# -*- coding: UTF-8 -*-
"""develop tests
"""
@@ -23,7 +23,7 @@ setup(name='foo',
)
"""
-NS_INIT = """# -*- coding: Latin-1 -*-
+NS_INIT = """# -*- coding: Latin-1 -*-
# Söme Arbiträry Ünicode to test Issüé 310
try:
__import__('pkg_resources').declare_namespace(__name__)
@@ -77,7 +77,7 @@ class TestTestTest(unittest.TestCase):
f = open(init, 'wt')
f.write(TEST_PY)
f.close()
-
+
os.chdir(self.dir)
self.old_base = site.USER_BASE
site.USER_BASE = tempfile.mkdtemp()
@@ -87,7 +87,7 @@ class TestTestTest(unittest.TestCase):
def tearDown(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
-
+
os.chdir(self.old_cwd)
shutil.rmtree(self.dir)
shutil.rmtree(site.USER_BASE)
@@ -98,7 +98,7 @@ class TestTestTest(unittest.TestCase):
def test_test(self):
if sys.version < "2.6" or hasattr(sys, 'real_prefix'):
return
-
+
dist = Distribution(dict(
name='foo',
packages=['name', 'name.space', 'name.space.tests'],
@@ -121,4 +121,4 @@ class TestTestTest(unittest.TestCase):
pass
finally:
sys.stdout = old_stdout
- \ No newline at end of file
+
diff --git a/setuptools/tests/win_script_wrapper.txt b/setuptools/tests/win_script_wrapper.txt
index db1daf6b..731243dd 100644
--- a/setuptools/tests/win_script_wrapper.txt
+++ b/setuptools/tests/win_script_wrapper.txt
@@ -49,37 +49,16 @@ GUI programs, the suffix '-script-pyw' is added.) This is why we
named out script the way we did. Now we can run out script by running
the wrapper:
- >>> from subprocess import Popen, PIPE, STDOUT
- >>> try:
- ... unicode=unicode
- ... except:
- ... unicode=str
- >>> def popen4(cmd, *args):
- ... if hasattr(os, 'popen4'):
- ... input, output = os.popen4(cmd + " ".join(args))
- ... return input, output
- ... else:
- ... #emulate popen4 in python 3
- ... if cmd[0] == '"' and cmd[-1] != '"':
- ... cmd = cmd[1:]
- ... cmd += " ".join(args)
- ... p = Popen(cmd, shell=True, bufsize=0,
- ... stdin=PIPE, stdout=PIPE, stderr=STDOUT)
- ... return p.stdin, p.stdout
-
- >>> input, output = popen4('"' + nt_quote_arg(os.path.join(sample_directory, 'foo.exe')),
- ... r' arg1', r'"arg 2"', r'"arg \"2\\\""', r'"arg 4\\"', r'"arg5 a\\b"')
- >>> bytes_written = input.write('hello\nworld\n'.encode('utf-8'))
- >>> input.close()
- >>> # This is needed for line ending differences between py2 and py3 on win32
- >>> msg = unicode(output.read(), encoding='utf-8').split("\n")
- >>> for line in msg:
- ... print(line.strip())
+ >>> import subprocess
+ >>> cmd = [os.path.join(sample_directory, 'foo.exe'), 'arg1', 'arg 2',
+ ... 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
+ >>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
+ >>> stdout, stderr = proc.communicate('hello\nworld\n'.encode('ascii'))
+ >>> bytes = sys.stdout.write(stdout.decode('ascii').replace('\r\n', '\n'))
\foo-script.py
['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
'hello\nworld\n'
non-optimized
- <BLANKLINE>
This example was a little pathological in that it exercised windows
(MS C runtime) quoting rules:
@@ -115,18 +94,14 @@ enter the interpreter after running the script, you could use -Oi:
... sys.ps1 = '---'
... """ % dict(python_exe=nt_quote_arg(sys.executable)))
>>> f.close()
-
- >>> input, output = popen4(nt_quote_arg(os.path.join(sample_directory, 'foo.exe')))
- >>> input.close()
- >>> # This is needed for line ending differences between py2 and py3 on win32
- >>> msg = unicode(output.read(), encoding='utf-8').split("\n")
- >>> for line in msg:
- ... print(line.strip())
+ >>> cmd = [os.path.join(sample_directory, 'foo.exe')]
+ >>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
+ >>> stdout, stderr = proc.communicate()
+ >>> bytes = sys.stdout.write(stdout.decode('ascii').replace('\r\n', '\n'))
\foo-script.py
[]
''
---
- <BLANKLINE>
Testing the GUI Version
-----------------------
@@ -157,18 +132,19 @@ We'll also copy gui.exe to the sample-directory with the name bar.exe:
Finally, we'll run the script and check the result:
- >>> input, output = popen4('"'+nt_quote_arg(os.path.join(sample_directory, 'bar.exe')),
- ... r' "%s" "Test Argument"' % os.path.join(sample_directory, 'test_output.txt'))
- >>> input.close()
- >>> # This is needed for line ending differences between py2 and py3 on win32
- >>> msg = unicode(output.read(), encoding='utf-8').split("\n")
- >>> for line in msg:
- ... print(line.strip())
+ >>> cmd = [
+ ... os.path.join(sample_directory, 'bar.exe'),
+ ... os.path.join(sample_directory, 'test_output.txt'),
+ ... 'Test Argument',
+ ... ]
+ >>> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
+ >>> stdout, stderr = proc.communicate()
+ >>> print(stdout.decode('ascii'))
<BLANKLINE>
- >>> f = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
- >>> print(unicode(f.read(), encoding='utf-8'))
+ >>> f_out = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
+ >>> print(f_out.read().decode('ascii'))
'Test Argument'
- >>> f.close()
+ >>> f_out.close()
We're done with the sample_directory: