]> granicus.if.org Git - python/commitdiff
Make a number of small changes to ease the backport to distutils2
authorÉric Araujo <merwok@netwok.org>
Sun, 18 Sep 2011 18:11:48 +0000 (20:11 +0200)
committerÉric Araujo <merwok@netwok.org>
Sun, 18 Sep 2011 18:11:48 +0000 (20:11 +0200)
19 files changed:
Lib/packaging/command/build_clib.py
Lib/packaging/command/upload_docs.py
Lib/packaging/compiler/unixccompiler.py
Lib/packaging/database.py
Lib/packaging/tests/__init__.py
Lib/packaging/tests/__main__.py
Lib/packaging/tests/pypi_server.py
Lib/packaging/tests/test_command_build_ext.py
Lib/packaging/tests/test_command_install_lib.py
Lib/packaging/tests/test_command_upload.py
Lib/packaging/tests/test_command_upload_docs.py
Lib/packaging/tests/test_create.py
Lib/packaging/tests/test_database.py
Lib/packaging/tests/test_depgraph.py
Lib/packaging/tests/test_dist.py
Lib/packaging/tests/test_install.py
Lib/packaging/tests/test_pypi_server.py
Lib/packaging/tests/test_run.py
Lib/packaging/tests/test_util.py

index 4a249964c5a560abf86c3747f07cd97589ace085..5388ccd4d47af002bbd83ce0bf6e07f2063b7fca 100644 (file)
@@ -16,7 +16,7 @@ distribution and needed by extension modules.
 import os
 from packaging.command.cmd import Command
 from packaging.errors import PackagingSetupError
-from packaging.compiler import customize_compiler
+from packaging.compiler import customize_compiler, new_compiler
 from packaging import logger
 
 
@@ -93,7 +93,6 @@ class build_clib(Command):
             return
 
         # Yech -- this is cut 'n pasted from build_ext.py!
-        from packaging.compiler import new_compiler
         self.compiler = new_compiler(compiler=self.compiler,
                                      dry_run=self.dry_run,
                                      force=self.force)
index 03dd3ec3745d3cd1f1f32cd4ad669edeab43d55e..30e37b52c9141ecd56379fe7f68e7e56f30bd9c2 100644 (file)
@@ -87,6 +87,7 @@ class upload_docs(Command):
         content_type, body = encode_multipart(fields, files)
 
         credentials = self.username + ':' + self.password
+        # FIXME should use explicit encoding
         auth = b"Basic " + base64.encodebytes(credentials.encode()).strip()
 
         logger.info("Submitting documentation to %s", self.repository)
index c857d03e09aeea9b76a3f6a93207415a48f93532..3458faabe09901c034d7a1282f6f49f219de0302 100644 (file)
@@ -127,7 +127,7 @@ class UnixCCompiler(CCompiler):
         executables['ranlib'] = ["ranlib"]
 
     # Needed for the filename generation methods provided by the base
-    # class, CCompiler.  NB. whoever instantiates/uses a particular
+    # class, CCompiler.  XXX whoever instantiates/uses a particular
     # UnixCCompiler instance should set 'shared_lib_ext' -- we set a
     # reasonable common default here, but it's not necessarily used on all
     # Unices!
index b606db6b0547b19e12db3ed4bea2e19863101c8d..b2fcb97c37b243d41598a5e37d246b6ef99f2c00 100644 (file)
@@ -1,12 +1,13 @@
 """PEP 376 implementation."""
 
-import io
 import os
 import re
 import csv
 import sys
 import zipimport
+from io import StringIO
 from hashlib import md5
+
 from packaging import logger
 from packaging.errors import PackagingError
 from packaging.version import suggest_normalized_version, VersionPredicate
@@ -173,7 +174,7 @@ class Distribution:
     def get_resource_path(self, relative_path):
         with self.get_distinfo_file('RESOURCES') as resources_file:
             resources_reader = csv.reader(resources_file, delimiter=',',
-                                           lineterminator='\n')
+                                          lineterminator='\n')
             for relative, destination in resources_reader:
                 if relative == relative_path:
                     return destination
@@ -334,7 +335,7 @@ class EggInfoDistribution:
             else:
                 # FIXME handle the case where zipfile is not available
                 zipf = zipimport.zipimporter(path)
-                fileobj = io.StringIO(
+                fileobj = StringIO(
                     zipf.get_data('EGG-INFO/PKG-INFO').decode('utf8'))
                 self.metadata = Metadata(fileobj=fileobj)
                 try:
index 0b0e3c55438d4d9a37183bed8bd2c72aec64ce18..56e487a911571fffe23ba6856fe0ed417bb396f4 100644 (file)
@@ -6,17 +6,15 @@ packaging.tests package.  Each test module has a name starting with
 to return an initialized unittest.TestSuite instance.
 
 Utility code is included in packaging.tests.support.
-"""
 
-# Put this text back for the backport
-#Always import unittest from this module, it will be the right version
-#(standard library unittest for 3.2 and higher, third-party unittest2
-#elease for older versions).
+Always import unittest from this module: it will be unittest from the
+standard library for packaging tests and unittest2 for distutils2 tests.
+"""
 
 import os
 import sys
 import unittest
-from test.support import TESTFN
+from io import StringIO
 
 # XXX move helpers to support, add tests for them, remove things that
 # duplicate test.support (or keep them for the backport; needs thinking)
@@ -115,9 +113,8 @@ def reap_children():
 
 
 def captured_stdout(func, *args, **kw):
-    import io
     orig_stdout = getattr(sys, 'stdout')
-    setattr(sys, 'stdout', io.StringIO())
+    setattr(sys, 'stdout', StringIO())
     try:
         res = func(*args, **kw)
         sys.stdout.seek(0)
index 0f175cf96109d372a05aa3a9808756f1b8c21b1a..51daba47155dcb00f6c40c669b4cda590b4e503d 100644 (file)
@@ -14,6 +14,8 @@ def test_main():
         start_dir = os.path.dirname(__file__)
         top_dir = os.path.dirname(os.path.dirname(start_dir))
         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()
index 41bf9c42a4bef3c78a8afdf5e22e4a2d5d32f2b7..72cf8bed46d6552a57132ff66874238dedff5e54 100644 (file)
@@ -40,6 +40,7 @@ from xmlrpc.server import SimpleXMLRPCServer
 
 from packaging.tests import unittest
 
+
 PYPI_DEFAULT_STATIC_PATH = os.path.join(
     os.path.dirname(os.path.abspath(__file__)), 'pypiserver')
 
@@ -219,7 +220,7 @@ class PyPIRequestHandler(SimpleHTTPRequestHandler):
                         relative_path += "index.html"
 
                     if relative_path.endswith('.tar.gz'):
-                        with open(fs_path + relative_path, 'br') as file:
+                        with open(fs_path + relative_path, 'rb') as file:
                             data = file.read()
                         headers = [('Content-type', 'application/x-gtar')]
                     else:
@@ -260,8 +261,8 @@ class PyPIRequestHandler(SimpleHTTPRequestHandler):
             self.send_header(header, value)
         self.end_headers()
 
-        if type(data) is str:
-            data = data.encode()
+        if isinstance(data, str):
+            data = data.encode('utf-8')
 
         self.wfile.write(data)
 
index 59d09bf7107ac5633c833aea47f0b9d81af4f6d6..a6ad6ac0afe674d2af7a7cf688f3855021812ceb 100644 (file)
@@ -4,6 +4,7 @@ import site
 import sysconfig
 import textwrap
 from io import StringIO
+from sysconfig import _CONFIG_VARS
 from packaging.dist import Distribution
 from packaging.errors import (UnknownFileError, CompileError,
                               PackagingPlatformError)
@@ -78,7 +79,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
index b46f3bd2bb578d69974b5c19ddf220c860dad82f..c1066f65121459032805b441b6b684c5cfebea59 100644 (file)
@@ -40,7 +40,7 @@ class InstallLibTestCase(support.TempdirManager,
         cmd.finalize_options()
         self.assertEqual(cmd.optimize, 2)
 
-    @unittest.skipIf(no_bytecode, 'byte-compile not supported')
+    @unittest.skipIf(no_bytecode, 'byte-compile disabled')
     def test_byte_compile(self):
         pkg_dir, dist = self.create_dist()
         cmd = install_lib(dist)
index dbb4db784bba09fa1ac912a47146ba2bcaab949d..82d73603f7dc9cdefbee1654d0074a8bd488efaa 100644 (file)
@@ -1,6 +1,5 @@
 """Tests for packaging.command.upload."""
 import os
-import sys
 
 from packaging.command.upload import upload
 from packaging.dist import Distribution
@@ -103,22 +102,23 @@ class UploadTestCase(support.TempdirManager, support.EnvironRestorer,
         command, pyversion, filename = 'xxx', '3.3', path
         dist_files = [(command, pyversion, filename)]
 
-        # lets run it
-        pkg_dir, dist = self.create_dist(dist_files=dist_files, author='dédé')
+        # let's run it
+        dist = self.create_dist(dist_files=dist_files, author='dédé')[1]
         cmd = upload(dist)
         cmd.ensure_finalized()
         cmd.repository = self.pypi.full_address
         cmd.run()
 
-        # what did we send ?
+        # what did we send?
         handler, request_data = self.pypi.requests[-1]
         headers = handler.headers
-        #self.assertIn('dédé', str(request_data))
+        self.assertIn('dédé'.encode('utf-8'), request_data)
         self.assertIn(b'xxx', request_data)
 
         self.assertEqual(int(headers['content-length']), len(request_data))
         self.assertLess(int(headers['content-length']), 2500)
-        self.assertTrue(headers['content-type'].startswith('multipart/form-data'))
+        self.assertTrue(headers['content-type'].startswith(
+            'multipart/form-data'))
         self.assertEqual(handler.command, 'POST')
         self.assertNotIn('\n', headers['authorization'])
 
@@ -132,20 +132,16 @@ class UploadTestCase(support.TempdirManager, support.EnvironRestorer,
         self.write_file(os.path.join(docs_path, "index.html"), "yellow")
         self.write_file(self.rc, PYPIRC)
 
-        # lets run it
-        pkg_dir, dist = self.create_dist(dist_files=dist_files, author='dédé')
+        # let's run it
+        dist = self.create_dist(dist_files=dist_files, author='dédé')[1]
 
         cmd = upload(dist)
         cmd.get_finalized_command("build").run()
         cmd.upload_docs = True
         cmd.ensure_finalized()
         cmd.repository = self.pypi.full_address
-        prev_dir = os.getcwd()
-        try:
-            os.chdir(self.tmp_dir)
-            cmd.run()
-        finally:
-            os.chdir(prev_dir)
+        os.chdir(self.tmp_dir)
+        cmd.run()
 
         handler, request_data = self.pypi.requests[-1]
         action, name, content = request_data.split(
index c00f5c1c4a4d231dbbd1e268095fdd8589d46ad3..f4437276e7a69b82ff808a18105bec638206b74d 100644 (file)
@@ -1,6 +1,5 @@
 """Tests for packaging.command.upload_docs."""
 import os
-import sys
 import shutil
 import zipfile
 try:
@@ -52,34 +51,27 @@ class UploadDocsTestCase(support.TempdirManager,
 
     def test_default_uploaddir(self):
         sandbox = self.mkdtemp()
-        previous = os.getcwd()
         os.chdir(sandbox)
-        try:
-            os.mkdir("build")
-            self.prepare_sample_dir("build")
-            self.cmd.ensure_finalized()
-            self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
-        finally:
-            os.chdir(previous)
+        os.mkdir("build")
+        self.prepare_sample_dir("build")
+        self.cmd.ensure_finalized()
+        self.assertEqual(self.cmd.upload_dir, os.path.join("build", "docs"))
 
     def test_default_uploaddir_looks_for_doc_also(self):
         sandbox = self.mkdtemp()
-        previous = os.getcwd()
         os.chdir(sandbox)
-        try:
-            os.mkdir("build")
-            self.prepare_sample_dir("build")
-            os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
-            self.cmd.ensure_finalized()
-            self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
-        finally:
-            os.chdir(previous)
+        os.mkdir("build")
+        self.prepare_sample_dir("build")
+        os.rename(os.path.join("build", "docs"), os.path.join("build", "doc"))
+        self.cmd.ensure_finalized()
+        self.assertEqual(self.cmd.upload_dir, os.path.join("build", "doc"))
 
     def prepare_sample_dir(self, sample_dir=None):
         if sample_dir is None:
             sample_dir = self.mkdtemp()
         os.mkdir(os.path.join(sample_dir, "docs"))
-        self.write_file(os.path.join(sample_dir, "docs", "index.html"), "Ce mortel ennui")
+        self.write_file(os.path.join(sample_dir, "docs", "index.html"),
+                        "Ce mortel ennui")
         self.write_file(os.path.join(sample_dir, "index.html"), "Oh la la")
         return sample_dir
 
@@ -108,9 +100,8 @@ class UploadDocsTestCase(support.TempdirManager,
         self.assertTrue(handler.headers['content-type']
             .startswith('multipart/form-data;'))
 
-        action, name, version, content =\
-            request_data.split("----------------GHSKFJDLGDS7543FJKLFHRE75642756743254".encode())[1:5]
-
+        action, name, version, content = request_data.split(
+            b'----------------GHSKFJDLGDS7543FJKLFHRE75642756743254')[1:5]
 
         # check that we picked the right chunks
         self.assertIn(b'name=":action"', action)
@@ -126,27 +117,25 @@ class UploadDocsTestCase(support.TempdirManager,
 
     @unittest.skipIf(_ssl is None, 'Needs SSL support')
     def test_https_connection(self):
-        https_called = False
-
-        orig_https = upload_docs_mod.http.client.HTTPSConnection
+        self.https_called = False
+        self.addCleanup(
+            setattr, upload_docs_mod.http.client, 'HTTPSConnection',
+            upload_docs_mod.http.client.HTTPSConnection)
 
         def https_conn_wrapper(*args):
-            nonlocal https_called
-            https_called = True
+            self.https_called = True
             # the testing server is http
             return upload_docs_mod.http.client.HTTPConnection(*args)
 
         upload_docs_mod.http.client.HTTPSConnection = https_conn_wrapper
-        try:
-            self.prepare_command()
-            self.cmd.run()
-            self.assertFalse(https_called)
 
-            self.cmd.repository = self.cmd.repository.replace("http", "https")
-            self.cmd.run()
-            self.assertTrue(https_called)
-        finally:
-            upload_docs_mod.http.client.HTTPSConnection = orig_https
+        self.prepare_command()
+        self.cmd.run()
+        self.assertFalse(self.https_called)
+
+        self.cmd.repository = self.cmd.repository.replace("http", "https")
+        self.cmd.run()
+        self.assertTrue(self.https_called)
 
     def test_handling_response(self):
         self.pypi.default_response_status = '403 Forbidden'
@@ -155,7 +144,8 @@ class UploadDocsTestCase(support.TempdirManager,
         self.assertIn('Upload failed (403): Forbidden', self.get_logs()[-1])
 
         self.pypi.default_response_status = '301 Moved Permanently'
-        self.pypi.default_response_headers.append(("Location", "brand_new_location"))
+        self.pypi.default_response_headers.append(
+            ("Location", "brand_new_location"))
         self.cmd.run()
         self.assertIn('brand_new_location', self.get_logs()[-1])
 
@@ -185,6 +175,7 @@ class UploadDocsTestCase(support.TempdirManager,
         self.assertTrue(record, "should report the response")
         self.assertIn(self.pypi.default_response_data, record)
 
+
 def test_suite():
     return unittest.makeSuite(UploadDocsTestCase)
 
index a82ab43254e602ff7c53f3ff67af5887bab217c1..b896619ed0c4dd25976de59bf66b918c4e2b596c 100644 (file)
@@ -1,8 +1,8 @@
 """Tests for packaging.create."""
-import io
 import os
 import sys
 import sysconfig
+from io import StringIO
 from textwrap import dedent
 from packaging.create import MainProgram, ask_yn, ask, main
 
@@ -20,8 +20,8 @@ class CreateTestCase(support.TempdirManager,
         super(CreateTestCase, self).setUp()
         self._stdin = sys.stdin  # TODO use Inputs
         self._stdout = sys.stdout
-        sys.stdin = io.StringIO()
-        sys.stdout = io.StringIO()
+        sys.stdin = StringIO()
+        sys.stdout = StringIO()
         self._cwd = os.getcwd()
         self.wdir = self.mkdtemp()
         os.chdir(self.wdir)
@@ -135,7 +135,8 @@ class CreateTestCase(support.TempdirManager,
         sys.stdin.seek(0)
         main()
 
-        with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
+        path = os.path.join(self.wdir, 'setup.cfg')
+        with open(path, encoding='utf-8') as fp:
             contents = fp.read()
 
         self.assertEqual(contents, dedent("""\
@@ -210,7 +211,9 @@ ho, baby!
         sys.stdin.seek(0)
         # FIXME Out of memory error.
         main()
-        with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
+
+        path = os.path.join(self.wdir, 'setup.cfg')
+        with open(path, encoding='utf-8') as fp:
             contents = fp.read()
 
         self.assertEqual(contents, dedent("""\
index b36e66d22da750908e92e0f6f0d2290a8234e628..6f63e19a31ebf74b74d96c641b45afa7f3528831 100644 (file)
@@ -49,8 +49,8 @@ class FakeDistsMixin:
         # distributions
         tmpdir = tempfile.mkdtemp()
         self.addCleanup(shutil.rmtree, tmpdir)
-        self.fake_dists_path = os.path.join(tmpdir, 'fake_dists')
-        self.fake_dists_path = os.path.realpath(self.fake_dists_path)
+        self.fake_dists_path = os.path.realpath(
+            os.path.join(tmpdir, 'fake_dists'))
         fake_dists_src = os.path.abspath(
             os.path.join(os.path.dirname(__file__), 'fake_dists'))
         shutil.copytree(fake_dists_src, self.fake_dists_path)
@@ -58,6 +58,7 @@ class FakeDistsMixin:
         # back (to avoid getting a read-only copy of a read-only file).  we
         # could pass a custom copy_function to change the mode of files, but
         # shutil gives no control over the mode of directories :(
+        # see http://bugs.python.org/issue1666318
         for root, dirs, files in os.walk(self.fake_dists_path):
             os.chmod(root, 0o755)
             for f in files:
index 64c22eb1756a8d8125d2d7b2e3991337c2b98df3..88333020d3c483ca6e1162c0ec508cd65cae8ea8 100644 (file)
@@ -1,10 +1,11 @@
 """Tests for packaging.depgraph """
-import io
 import os
 import re
 import sys
-import packaging.database
+from io import StringIO
+
 from packaging import depgraph
+from packaging.database import get_distribution, enable_cache, disable_cache
 
 from packaging.tests import unittest, support
 from packaging.tests.support import requires_zlib
@@ -30,13 +31,13 @@ class DepGraphTestCase(support.LoggingCatcher,
         path = os.path.abspath(path)
         sys.path.insert(0, path)
         self.addCleanup(sys.path.remove, path)
-        self.addCleanup(packaging.database.enable_cache)
-        packaging.database.disable_cache()
+        self.addCleanup(enable_cache)
+        disable_cache()
 
     def test_generate_graph(self):
         dists = []
         for name in self.DISTROS_DIST:
-            dist = packaging.database.get_distribution(name)
+            dist = get_distribution(name)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -61,7 +62,7 @@ class DepGraphTestCase(support.LoggingCatcher,
     def test_generate_graph_egg(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -104,7 +105,7 @@ class DepGraphTestCase(support.LoggingCatcher,
     def test_dependent_dists(self):
         dists = []
         for name in self.DISTROS_DIST:
-            dist = packaging.database.get_distribution(name)
+            dist = get_distribution(name)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -123,7 +124,7 @@ class DepGraphTestCase(support.LoggingCatcher,
     def test_dependent_dists_egg(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -158,12 +159,12 @@ class DepGraphTestCase(support.LoggingCatcher,
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf)
         buf.seek(0)
         matches = []
@@ -189,12 +190,12 @@ class DepGraphTestCase(support.LoggingCatcher,
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf, skip_disconnected=False)
         buf.seek(0)
         lines = buf.readlines()
@@ -250,12 +251,12 @@ class DepGraphTestCase(support.LoggingCatcher,
 
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
         graph = depgraph.generate_graph(dists)
-        buf = io.StringIO()
+        buf = StringIO()
         depgraph.graph_to_dot(graph, buf)
         buf.seek(0)
         matches = []
@@ -273,7 +274,7 @@ class DepGraphTestCase(support.LoggingCatcher,
     def test_repr(self):
         dists = []
         for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS:
-            dist = packaging.database.get_distribution(name, use_egg_info=True)
+            dist = get_distribution(name, use_egg_info=True)
             self.assertNotEqual(dist, None)
             dists.append(dist)
 
@@ -282,7 +283,7 @@ class DepGraphTestCase(support.LoggingCatcher,
 
     @requires_zlib
     def test_main(self):
-        tempout = io.StringIO()
+        tempout = StringIO()
         old = sys.stdout
         sys.stdout = tempout
         oldargv = sys.argv[:]
index bd862450b2f25787e537f8948be75709c198f039..8d91a92a27c86b365bb8eb83366bdc88c7e9ccf2 100644 (file)
@@ -3,13 +3,14 @@ import os
 import sys
 import logging
 import textwrap
+
 import packaging.dist
 
 from packaging.dist import Distribution
 from packaging.command import set_command
 from packaging.command.cmd import Command
 from packaging.errors import PackagingModuleError, PackagingOptionError
-from packaging.tests import TESTFN, captured_stdout
+from packaging.tests import captured_stdout
 from packaging.tests import support, unittest
 from packaging.tests.support import create_distribution
 from test.support import unload
@@ -48,12 +49,13 @@ class DistributionTestCase(support.TempdirManager,
 
     @unittest.skip('needs to be updated')
     def test_debug_mode(self):
-        self.addCleanup(os.unlink, TESTFN)
-        with open(TESTFN, "w") as f:
+        tmpdir = self.mkdtemp()
+        setupcfg = os.path.join(tmpdir, 'setup.cfg')
+        with open(setupcfg, "w") as f:
             f.write("[global]\n")
             f.write("command_packages = foo.bar, splat")
 
-        files = [TESTFN]
+        files = [setupcfg]
         sys.argv.append("build")
         __, stdout = captured_stdout(create_distribution, files)
         self.assertEqual(stdout, '')
index cf0817ca4d0fb63e1ca64eea13853cde65c628ad..cc1f5d3a047bf6984ba916e53595d7ca2d42c23f 100644 (file)
@@ -1,8 +1,8 @@
 """Tests for the packaging.install module."""
 import os
 import logging
-from sysconfig import is_python_build
 from tempfile import mkstemp
+from sysconfig import is_python_build
 
 from packaging import install
 from packaging.pypi.xmlrpc import Client
index 2c4ec0d34c347ea505213935c2cf9124561903c3..057c49498ae6c1c21e8f79b7923a0232539c27a1 100644 (file)
@@ -1,13 +1,12 @@
 """Tests for packaging.command.bdist."""
-import sys
-
 import urllib.request
 import urllib.parse
 import urllib.error
 
 try:
     import threading
-    from packaging.tests.pypi_server import PyPIServer, PYPI_DEFAULT_STATIC_PATH
+    from packaging.tests.pypi_server import (
+        PyPIServer, PYPI_DEFAULT_STATIC_PATH)
 except ImportError:
     threading = None
     PyPIServer = None
@@ -32,18 +31,19 @@ class PyPIServerTest(unittest.TestCase):
 
             headers = {"X-test-header": "Mister Iceberg"}
 
-            request = urllib.request.Request(server.full_address, data, headers)
+            request = urllib.request.Request(
+                server.full_address, data, headers)
             urllib.request.urlopen(request)
             self.assertEqual(len(server.requests), 1)
             handler, request_data = server.requests[-1]
             self.assertIn(data, request_data)
             self.assertIn("x-test-header", handler.headers)
-            self.assertEqual(handler.headers["x-test-header"], "Mister Iceberg")
+            self.assertEqual(handler.headers["x-test-header"],
+                             "Mister Iceberg")
 
         finally:
             server.stop()
 
-
     def test_serve_static_content(self):
         # PYPI Mocked server can serve static content from disk.
 
@@ -74,7 +74,8 @@ class PyPIServerTest(unittest.TestCase):
             self.assertTrue(uses_local_files_for(server, "/simple/index.html"))
 
             # and another one in another root path
-            self.assertTrue(uses_local_files_for(server, "/external/index.html"))
+            self.assertTrue(uses_local_files_for(server,
+                                                 "/external/index.html"))
 
         finally:
             server.stop()
index 6a3b8fb1309adab2ed54c1d52eb76b1b50d2d5ec..d9460cf526cff77a9cd7fac6db27ebe3e5833bdc 100644 (file)
@@ -2,11 +2,10 @@
 
 import os
 import sys
-import shutil
 from io import StringIO
 
 from packaging import install
-from packaging.tests import unittest, support, TESTFN
+from packaging.tests import unittest, support
 from packaging.run import main
 
 from test.script_helper import assert_python_ok
@@ -35,28 +34,14 @@ class RunTestCase(support.TempdirManager,
     def setUp(self):
         super(RunTestCase, self).setUp()
         self.old_stdout = sys.stdout
-        self.cleanup_testfn()
         self.old_argv = sys.argv, sys.argv[:]
 
     def tearDown(self):
         sys.stdout = self.old_stdout
-        self.cleanup_testfn()
         sys.argv = self.old_argv[0]
         sys.argv[:] = self.old_argv[1]
         super(RunTestCase, self).tearDown()
 
-    def cleanup_testfn(self):
-        path = TESTFN
-        if os.path.isfile(path):
-            os.remove(path)
-        elif os.path.isdir(path):
-            shutil.rmtree(path)
-
-    def write_setup(self, text, path=TESTFN):
-        with open(path, "w") as fp:
-            fp.write(text)
-        return path
-
     # TODO restore the tests removed six months ago and port them to pysetup
 
     def test_install(self):
index c3d91aa05984a1e5db67bf4fc1a6a5098fe76b53..dcd210f7bfc11baff9d6f61e7995378cf963ab1d 100644 (file)
@@ -15,7 +15,7 @@ from packaging.errors import (
 from packaging import util
 from packaging.dist import Distribution
 from packaging.util import (
-    convert_path, change_root, split_quoted, strtobool,
+    convert_path, change_root, split_quoted, strtobool, run_2to3,
     get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages,
     spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob,
     RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging,
@@ -374,7 +374,7 @@ class UtilTestCase(support.EnvironRestorer,
 
         res = find_packages([root], ['pkg1.pkg2'])
         self.assertEqual(set(res), set(['pkg1', 'pkg5', 'pkg1.pkg3',
-                                         'pkg1.pkg3.pkg6']))
+                                        'pkg1.pkg3.pkg6']))
 
     def test_resolve_name(self):
         self.assertIs(str, resolve_name('builtins.str'))
@@ -416,7 +416,6 @@ class UtilTestCase(support.EnvironRestorer,
         file_handle.write(content)
         file_handle.flush()
         file_handle.seek(0)
-        from packaging.util import run_2to3
         run_2to3([file_name])
         new_content = "".join(file_handle.read())
         file_handle.close()
@@ -432,7 +431,6 @@ class UtilTestCase(support.EnvironRestorer,
         file_handle.write(content)
         file_handle.flush()
         file_handle.seek(0)
-        from packaging.util import run_2to3
         run_2to3([file_name], doctests_only=True)
         new_content = "".join(file_handle.readlines())
         file_handle.close()