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):
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
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
# 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')
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
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'})
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,
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()
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()
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()
self.assertEqual(manifest, ['README.manual'])
+ @requires_zlib
def test_template(self):
dist, cmd = self.get_cmd()
dist.extra_files = ['include yeah']
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'
from packaging.command.sdist import sdist
from packaging.tests import unittest, support
+from packaging.tests.support import requires_zlib
SETUP_CFG = """
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
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,
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])
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
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
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))
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))
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))
from packaging import depgraph
from packaging.tests import unittest, support
+from packaging.tests.support import requires_zlib
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:
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:
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)'),
self.checkLists(matches, expected)
+ @requires_zlib
def test_graph_disconnected_to_dot(self):
dependencies_expected = (
('towel-stuff', 'bacon', 'bacon (<=0.2)'),
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)'),
self.checkLists(matches, expected)
+ @requires_zlib
def test_repr(self):
dists = []
for name in self.DISTROS_DIST + self.DISTROS_EGG + self.BAD_EGGS:
graph = depgraph.generate_graph(dists)
self.assertTrue(repr(graph))
+ @requires_zlib
def test_main(self):
tempout = io.StringIO()
old = sys.stdout
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
hashname="invalid_hashname",
hashval="value")
+ @requires_zlib
@use_pypi_server('downloads_with_md5')
def test_unpack(self, server):
url = server.full_address + self.srcpath
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",
"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):
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