summaryrefslogtreecommitdiff
path: root/distutils2/tests
diff options
context:
space:
mode:
author?ric Araujo <merwok@netwok.org>2011-09-18 20:20:13 +0200
committer?ric Araujo <merwok@netwok.org>2011-09-18 20:20:13 +0200
commit506cfea8bbd41e865bc36a836bdbc05aae8d74bb (patch)
tree3bae418473347324060850aab8d34e162b33ecc9 /distutils2/tests
parent8c928044705a70bb845cb45f76edb6eb71393866 (diff)
downloaddisutils2-506cfea8bbd41e865bc36a836bdbc05aae8d74bb.tar.gz
Fix the backport fixes.
Backports: - sysconfig is now always imported from our backports - when hashlib is not found, our backport is used instead of the md5 module (debatable; we could just drop hashlib) Version-dependent features: - PEP 370 features are only enabled for 2.6+ - the check for sys.dont_write_bytecode was fixed to use getattr with a default value instead of hasattr Idioms/syntax: - octal literals lost their extra 0 - misused try/except blocks have been changed back to try/finally (it?s legal in 2.4 too, it?s only try/except/finally that isn?t) - exception catching uses the regular 2.x idiom instead of sys.exc_info - file objects are closed within finally blocks (this causes much whitespace changes but actually makes diff with packaging easier) Renamed modules: - some missed renamings (_thread, Queue, isAlive, urllib.urlsplit, etc.) were fixed Other: - a few false positive replacements of ?packaging? by ?distutils2? in comments or docstrings were reverted - util.is_packaging regained its name - assorted whitespace/comment/import changes to match packaging
Diffstat (limited to 'distutils2/tests')
-rw-r--r--distutils2/tests/__main__.py8
-rw-r--r--distutils2/tests/pypi_server.py22
-rw-r--r--distutils2/tests/test_command_build.py2
-rw-r--r--distutils2/tests/test_command_build_ext.py9
-rw-r--r--distutils2/tests/test_command_upload_docs.py5
-rw-r--r--distutils2/tests/test_install.py3
-rw-r--r--distutils2/tests/test_mixin2to3.py10
-rw-r--r--distutils2/tests/test_pypi_simple.py4
8 files changed, 33 insertions, 30 deletions
diff --git a/distutils2/tests/__main__.py b/distutils2/tests/__main__.py
index b01cbd1..bdcc29d 100644
--- a/distutils2/tests/__main__.py
+++ b/distutils2/tests/__main__.py
@@ -4,8 +4,8 @@
import os
import sys
-import unittest2
-from .support import run_unittest, reap_children, reap_threads
+from distutils2.tests import unittest
+from distutils2.tests.support import reap_children, reap_threads, run_unittest
@reap_threads
@@ -13,7 +13,9 @@ def test_main():
try:
start_dir = os.path.dirname(__file__)
top_dir = os.path.dirname(os.path.dirname(start_dir))
- test_loader = unittest2.TestLoader()
+ test_loader = unittest.TestLoader()
+ # XXX find out how to use unittest.main, to get command-line options
+ # (failfast, catch, etc.)
run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
finally:
reap_children()
diff --git a/distutils2/tests/pypi_server.py b/distutils2/tests/pypi_server.py
index 4d62986..3d25725 100644
--- a/distutils2/tests/pypi_server.py
+++ b/distutils2/tests/pypi_server.py
@@ -30,19 +30,21 @@ implementations (static HTTP and XMLRPC over HTTP).
"""
import os
-import queue
+import Queue
import select
import threading
-import socketserver
+import SocketServer
+from BaseHTTPServer import HTTPServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+
+from distutils2.tests import unittest
+
try:
from functools import wraps
except ImportError:
from distutils2._backport.functools import wraps
-from http.server import HTTPServer, SimpleHTTPRequestHandler
-from xmlrpc.server import SimpleXMLRPCServer
-
-from distutils2.tests import unittest
PYPI_DEFAULT_STATIC_PATH = os.path.join(
os.path.dirname(os.path.abspath(__file__)), 'pypiserver')
@@ -117,7 +119,7 @@ class PyPIServer(threading.Thread):
self.server = HTTPServer(('127.0.0.1', 0), PyPIRequestHandler)
self.server.RequestHandlerClass.pypi_server = self
- self.request_queue = queue.Queue()
+ self.request_queue = Queue.Queue()
self._requests = []
self.default_response_status = 404
self.default_response_headers = [('Content-type', 'text/plain')]
@@ -154,7 +156,7 @@ class PyPIServer(threading.Thread):
def stop(self):
"""self shutdown is not supported for python < 2.6"""
self._run = False
- if self.is_alive():
+ if self.isAlive():
self.join()
self.server.server_close()
@@ -171,7 +173,7 @@ class PyPIServer(threading.Thread):
while True:
try:
self._requests.append(self.request_queue.get_nowait())
- except queue.Empty:
+ except Queue.Empty:
break
return self._requests
@@ -275,7 +277,7 @@ class PyPIRequestHandler(SimpleHTTPRequestHandler):
class PyPIXMLRPCServer(SimpleXMLRPCServer):
def server_bind(self):
"""Override server_bind to store the server name."""
- socketserver.TCPServer.server_bind(self)
+ SocketServer.TCPServer.server_bind(self)
host, port = self.socket.getsockname()[:2]
self.server_port = port
diff --git a/distutils2/tests/test_command_build.py b/distutils2/tests/test_command_build.py
index e70b7b4..08bef58 100644
--- a/distutils2/tests/test_command_build.py
+++ b/distutils2/tests/test_command_build.py
@@ -3,7 +3,7 @@ import os
import sys
from distutils2.command.build import build
-from sysconfig import get_platform
+from distutils2._backport.sysconfig import get_platform
from distutils2.tests import unittest, support
diff --git a/distutils2/tests/test_command_build_ext.py b/distutils2/tests/test_command_build_ext.py
index b0d8bc8..d73fe6c 100644
--- a/distutils2/tests/test_command_build_ext.py
+++ b/distutils2/tests/test_command_build_ext.py
@@ -5,6 +5,7 @@ import shutil
import textwrap
from StringIO import StringIO
from distutils2._backport import sysconfig
+from distutils2._backport.sysconfig import _CONFIG_VARS
from distutils2.dist import Distribution
from distutils2.errors import (UnknownFileError, CompileError,
PackagingPlatformError)
@@ -36,9 +37,10 @@ class BuildExtTestCase(support.TempdirManager,
filename = _get_source_filename()
if os.path.exists(filename):
shutil.copy(filename, self.tmp_dir)
- self.old_user_base = site.USER_BASE
- site.USER_BASE = self.mkdtemp()
- build_ext.USER_BASE = site.USER_BASE
+ if sys.version > "2.6":
+ self.old_user_base = site.USER_BASE
+ site.USER_BASE = self.mkdtemp()
+ build_ext.USER_BASE = site.USER_BASE
def tearDown(self):
# Get everything back to normal
@@ -122,7 +124,6 @@ class BuildExtTestCase(support.TempdirManager,
old = sys.platform
sys.platform = 'sunos' # fooling finalize_options
- from sysconfig import _CONFIG_VARS
old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
_CONFIG_VARS['Py_ENABLE_SHARED'] = 1
diff --git a/distutils2/tests/test_command_upload_docs.py b/distutils2/tests/test_command_upload_docs.py
index 65646e3..c023cd3 100644
--- a/distutils2/tests/test_command_upload_docs.py
+++ b/distutils2/tests/test_command_upload_docs.py
@@ -18,7 +18,7 @@ try:
from distutils2.tests.pypi_server import PyPIServerTestCase
except ImportError:
threading = None
- PyPIServerTestCase = object
+ PyPIServerTestCase = unittest.TestCase
PYPIRC = """\
@@ -32,8 +32,7 @@ password = long_island
"""
-class UploadDocsTestCase(unittest.TestCase,
- support.TempdirManager,
+class UploadDocsTestCase(support.TempdirManager,
support.EnvironRestorer,
support.LoggingCatcher,
PyPIServerTestCase):
diff --git a/distutils2/tests/test_install.py b/distutils2/tests/test_install.py
index 06a1181..f6b91f3 100644
--- a/distutils2/tests/test_install.py
+++ b/distutils2/tests/test_install.py
@@ -1,7 +1,6 @@
"""Tests for the distutils2.install module."""
import os
import logging
-from sysconfig import is_python_build
from tempfile import mkstemp
from distutils2 import install
@@ -9,6 +8,8 @@ from distutils2.pypi.xmlrpc import Client
from distutils2.metadata import Metadata
from distutils2.tests.support import (LoggingCatcher, TempdirManager, unittest,
fake_dec)
+from distutils2._backport.sysconfig import is_python_build
+
try:
import threading
from distutils2.tests.pypi_server import use_xmlrpc_server
diff --git a/distutils2/tests/test_mixin2to3.py b/distutils2/tests/test_mixin2to3.py
index 8cfdf7a..71bd74e 100644
--- a/distutils2/tests/test_mixin2to3.py
+++ b/distutils2/tests/test_mixin2to3.py
@@ -1,3 +1,4 @@
+import sys
import textwrap
from distutils2.tests import unittest, support
@@ -8,8 +9,7 @@ class Mixin2to3TestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
- #@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
- @unittest.skipIf(True, 'Not needed for backport')
+ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_convert_code_only(self):
# used to check if code gets converted properly.
code = "print 'test'"
@@ -28,8 +28,7 @@ class Mixin2to3TestCase(support.TempdirManager,
self.assertEqual(expected, converted)
- #@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
- @unittest.skipIf(True, 'Not needed for backport')
+ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_doctests_only(self):
# used to check if doctests gets converted properly.
doctest = textwrap.dedent('''\
@@ -62,8 +61,7 @@ class Mixin2to3TestCase(support.TempdirManager,
self.assertEqual(expected, converted)
- #@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
- @unittest.skipIf(True, 'Not needed for backport')
+ @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_additional_fixers(self):
# used to check if use_2to3_fixers works
code = 'type(x) is not T'
diff --git a/distutils2/tests/test_pypi_simple.py b/distutils2/tests/test_pypi_simple.py
index dde0b3a..4607a40 100644
--- a/distutils2/tests/test_pypi_simple.py
+++ b/distutils2/tests/test_pypi_simple.py
@@ -12,9 +12,9 @@ from distutils2.tests.support import (TempdirManager, LoggingCatcher,
fake_dec)
try:
- import _thread
+ import thread as _thread
from distutils2.tests.pypi_server import (use_pypi_server, PyPIServer,
- PYPI_DEFAULT_STATIC_PATH)
+ PYPI_DEFAULT_STATIC_PATH)
except ImportError:
_thread = None
use_pypi_server = fake_dec