diff options
-rw-r--r-- | Lib/packaging/tests/support.py | 3 | ||||
-rw-r--r-- | Lib/packaging/tests/test_command_sdist.py | 22 | ||||
-rw-r--r-- | Lib/packaging/tests/test_config.py | 2 | ||||
-rw-r--r-- | Lib/packaging/tests/test_database.py | 8 | ||||
-rw-r--r-- | Lib/packaging/tests/test_depgraph.py | 8 | ||||
-rw-r--r-- | Lib/packaging/tests/test_pypi_dist.py | 3 | ||||
-rw-r--r-- | Lib/test/support.py | 9 |
7 files changed, 41 insertions, 14 deletions
diff --git a/Lib/packaging/tests/support.py b/Lib/packaging/tests/support.py index 329b755..b410dba 100644 --- a/Lib/packaging/tests/support.py +++ b/Lib/packaging/tests/support.py @@ -37,10 +37,11 @@ import tempfile from packaging import logger from packaging.dist import Distribution from packaging.tests import unittest +from test.support import requires_zlib __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer', 'DummyCommand', 'unittest', 'create_distribution', - 'skip_unless_symlink'] + 'skip_unless_symlink', 'requires_zlib'] class _TestHandler(logging.handlers.BufferingHandler): diff --git a/Lib/packaging/tests/test_command_sdist.py b/Lib/packaging/tests/test_command_sdist.py index 956e258..a086e62 100644 --- a/Lib/packaging/tests/test_command_sdist.py +++ b/Lib/packaging/tests/test_command_sdist.py @@ -4,12 +4,7 @@ import zipfile import tarfile import logging -# zlib is not used here, but if it's not available -# the tests that use zipfile may fail -try: - import zlib -except ImportError: - zlib = None +from packaging.tests.support import requires_zlib try: import grp @@ -96,7 +91,7 @@ class SDistTestCase(support.TempdirManager, cmd.dist_dir = 'dist' return dist, cmd - @unittest.skipUnless(zlib, "requires zlib") + @requires_zlib def test_prune_file_list(self): # this test creates a package with some vcs dirs in it # and launch sdist to make sure they get pruned @@ -136,7 +131,7 @@ class SDistTestCase(support.TempdirManager, # making sure everything has been pruned correctly self.assertEqual(len(content), 3) - @unittest.skipUnless(zlib, "requires zlib") + @requires_zlib @unittest.skipIf(find_executable('tar') is None or find_executable('gzip') is None, 'requires tar and gzip programs') @@ -166,7 +161,7 @@ class SDistTestCase(support.TempdirManager, result = sorted(os.listdir(dist_folder)) self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz']) - @unittest.skipUnless(zlib, "requires zlib") + @requires_zlib def test_add_defaults(self): # http://bugs.python.org/issue2279 @@ -226,7 +221,7 @@ class SDistTestCase(support.TempdirManager, manifest = fp.read() self.assertEqual(manifest, MANIFEST % {'sep': os.sep}) - @unittest.skipUnless(zlib, "requires zlib") + @requires_zlib def test_metadata_check_option(self): # testing the `check-metadata` option dist, cmd = self.get_cmd(metadata={'name': 'xxx', 'version': 'xxx'}) @@ -280,7 +275,7 @@ class SDistTestCase(support.TempdirManager, cmd.formats = 'supazipa' self.assertRaises(PackagingOptionError, cmd.finalize_options) - @unittest.skipUnless(zlib, "requires zlib") + @requires_zlib @unittest.skipUnless(UID_GID_SUPPORT, "requires grp and pwd support") @unittest.skipIf(find_executable('tar') is None or find_executable('gzip') is None, @@ -321,6 +316,7 @@ class SDistTestCase(support.TempdirManager, for member in archive.getmembers(): self.assertEqual(member.uid, os.getuid()) + @requires_zlib def test_get_file_list(self): # make sure MANIFEST is recalculated dist, cmd = self.get_cmd() @@ -355,6 +351,7 @@ class SDistTestCase(support.TempdirManager, self.assertEqual(len(manifest2), 5) self.assertIn('doc2.txt', manifest2[-1]) + @requires_zlib def test_manifest_marker(self): # check that autogenerated MANIFESTs have a marker dist, cmd = self.get_cmd() @@ -368,6 +365,7 @@ class SDistTestCase(support.TempdirManager, self.assertEqual(manifest[0], '# file GENERATED by packaging, do NOT edit') + @requires_zlib def test_manual_manifest(self): # check that a MANIFEST without a marker is left alone dist, cmd = self.get_cmd() @@ -381,6 +379,7 @@ class SDistTestCase(support.TempdirManager, self.assertEqual(manifest, ['README.manual']) + @requires_zlib def test_template(self): dist, cmd = self.get_cmd() dist.extra_files = ['include yeah'] @@ -392,6 +391,7 @@ class SDistTestCase(support.TempdirManager, self.assertIn('yeah', content) + @requires_zlib def test_manifest_builder(self): dist, cmd = self.get_cmd() cmd.manifest_builders = 'packaging.tests.test_command_sdist.builder' diff --git a/Lib/packaging/tests/test_config.py b/Lib/packaging/tests/test_config.py index e6e5586..ac4f403 100644 --- a/Lib/packaging/tests/test_config.py +++ b/Lib/packaging/tests/test_config.py @@ -11,6 +11,7 @@ from packaging.compiler import new_compiler, _COMPILERS from packaging.command.sdist import sdist from packaging.tests import unittest, support +from packaging.tests.support import requires_zlib SETUP_CFG = """ @@ -343,6 +344,7 @@ class ConfigTestCase(support.TempdirManager, cmd.get_file_list() self.assertRaises(PackagingFileError, cmd.make_distribution) + @requires_zlib def test_metadata_requires_description_files(self): # Create the following file structure: # README diff --git a/Lib/packaging/tests/test_database.py b/Lib/packaging/tests/test_database.py index 251181a..c8d6385 100644 --- a/Lib/packaging/tests/test_database.py +++ b/Lib/packaging/tests/test_database.py @@ -12,6 +12,7 @@ from hashlib import md5 from packaging.errors import PackagingError from packaging.metadata import Metadata from packaging.tests import unittest, run_unittest, support, TESTFN +from packaging.tests.support import requires_zlib from packaging.database import ( Distribution, EggInfoDistribution, get_distribution, get_distributions, @@ -64,11 +65,13 @@ class CommonDistributionTests: self.assertEqual(dist.version, version) self.assertEqual(dist.metadata['Version'], version) + @requires_zlib def test_repr(self): dist = self.cls(self.dirs[0]) # just check that the class name is in the repr self.assertIn(self.cls.__name__, repr(dist)) + @requires_zlib def test_comparison(self): # tests for __eq__ and __hash__ dist = self.cls(self.dirs[0]) @@ -281,6 +284,7 @@ class TestDatabase(support.LoggingCatcher, dirname = distinfo_dirname(name, version) self.assertEqual(dirname, standard_dirname) + @requires_zlib def test_get_distributions(self): # Lookup all distributions found in the ``sys.path``. # This test could potentially pick up other installed distributions @@ -321,6 +325,7 @@ class TestDatabase(support.LoggingCatcher, self.assertEqual(sorted(fake_dists), sorted(found_dists)) + @requires_zlib def test_get_distribution(self): # Test for looking up a distribution by name. # Test the lookup of the towel-stuff distribution @@ -371,6 +376,7 @@ class TestDatabase(support.LoggingCatcher, self.assertIsInstance(dist, Distribution) self.assertEqual(dist.name, name) + @requires_zlib def test_provides(self): # Test for looking up distributions by what they provide checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y)) @@ -437,6 +443,7 @@ class TestDatabase(support.LoggingCatcher, use_egg_info=True)] checkLists(l, []) + @requires_zlib def test_obsoletes(self): # Test looking for distributions based on what they obsolete checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y)) @@ -465,6 +472,7 @@ class TestDatabase(support.LoggingCatcher, l = [dist.name for dist in obsoletes_distribution('truffles', '0.2')] checkLists(l, ['towel-stuff']) + @requires_zlib def test_yield_distribution(self): # tests the internal function _yield_distributions checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y)) diff --git a/Lib/packaging/tests/test_depgraph.py b/Lib/packaging/tests/test_depgraph.py index 9271a7b..64c22eb 100644 --- a/Lib/packaging/tests/test_depgraph.py +++ b/Lib/packaging/tests/test_depgraph.py @@ -7,6 +7,7 @@ import packaging.database from packaging import depgraph from packaging.tests import unittest, support +from packaging.tests.support import requires_zlib class DepGraphTestCase(support.LoggingCatcher, @@ -56,6 +57,7 @@ class DepGraphTestCase(support.LoggingCatcher, self.checkLists([], deps) self.checkLists(graph.missing[towel], ['bacon (<=0.2)']) + @requires_zlib def test_generate_graph_egg(self): dists = [] for name in self.DISTROS_DIST + self.DISTROS_EGG: @@ -117,6 +119,7 @@ class DepGraphTestCase(support.LoggingCatcher, deps = [d.name for d in depgraph.dependent_dists(dists, towel)] self.checkLists(['choxie'], deps) + @requires_zlib def test_dependent_dists_egg(self): dists = [] for name in self.DISTROS_DIST + self.DISTROS_EGG: @@ -144,6 +147,7 @@ class DepGraphTestCase(support.LoggingCatcher, deps = [d.name for d in depgraph.dependent_dists(dists, cheese)] self.checkLists([], deps) + @requires_zlib def test_graph_to_dot(self): expected = ( ('towel-stuff', 'bacon', 'bacon (<=0.2)'), @@ -173,6 +177,7 @@ class DepGraphTestCase(support.LoggingCatcher, self.checkLists(matches, expected) + @requires_zlib def test_graph_disconnected_to_dot(self): dependencies_expected = ( ('towel-stuff', 'bacon', 'bacon (<=0.2)'), @@ -234,6 +239,7 @@ class DepGraphTestCase(support.LoggingCatcher, self.checkLists(dependencies_matches, dependencies_expected) self.checkLists(disconnected_matches, disconnected_expected) + @requires_zlib def test_graph_bad_version_to_dot(self): expected = ( ('towel-stuff', 'bacon', 'bacon (<=0.2)'), @@ -263,6 +269,7 @@ class DepGraphTestCase(support.LoggingCatcher, self.checkLists(matches, expected) + @requires_zlib def test_repr(self): dists = [] for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS: @@ -273,6 +280,7 @@ class DepGraphTestCase(support.LoggingCatcher, graph = depgraph.generate_graph(dists) self.assertTrue(repr(graph)) + @requires_zlib def test_main(self): tempout = io.StringIO() old = sys.stdout diff --git a/Lib/packaging/tests/test_pypi_dist.py b/Lib/packaging/tests/test_pypi_dist.py index b438cb8..108e723 100644 --- a/Lib/packaging/tests/test_pypi_dist.py +++ b/Lib/packaging/tests/test_pypi_dist.py @@ -7,7 +7,7 @@ from packaging.pypi.dist import (ReleaseInfo, ReleasesList, DistInfo, from packaging.pypi.errors import HashDoesNotMatch, UnsupportedHashName from packaging.tests import unittest -from packaging.tests.support import TempdirManager +from packaging.tests.support import TempdirManager, requires_zlib from packaging.tests.pypi_server import use_pypi_server @@ -158,6 +158,7 @@ class TestDistInfo(TempdirManager, unittest.TestCase): hashname="invalid_hashname", hashval="value") + @requires_zlib @use_pypi_server('downloads_with_md5') def test_unpack(self, server): url = server.full_address + self.srcpath diff --git a/Lib/test/support.py b/Lib/test/support.py index e49453e..3f60d55 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -28,6 +28,11 @@ try: except ImportError: _thread = None +try: + import zlib +except ImportError: + zlib = None + __all__ = [ "Error", "TestFailed", "ResourceDenied", "import_module", "verbose", "use_resources", "max_memuse", "record_original_stdout", @@ -43,7 +48,7 @@ __all__ = [ "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754", "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", - "import_fresh_module" + "import_fresh_module", "requires_zlib" ] class Error(Exception): @@ -401,6 +406,8 @@ requires_IEEE_754 = unittest.skipUnless( float.__getformat__("double").startswith("IEEE"), "test requires IEEE 754 doubles") +requires_zlib = unittest.skipUnless(zlib, 'requires zlib') + is_jython = sys.platform.startswith('java') # Filename used for testing |