bpo-40275: More lazy imports in test.support (GH-20131)
Make the the following imports lazy in test.support:
* bz2
* gzip
* lzma
* resource
* zlib
The following test.support decorators now need to be called
with parenthesis:
* @support.requires_bz2
* @support.requires_gzip
* @support.requires_lzma
* @support.requires_zlib
For example, "@requires_zlib" becomes "@requires_zlib()".
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index b9fdfd1..e56b337 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1246,7 +1246,7 @@
### shutil.make_archive
- @support.requires_zlib
+ @support.requires_zlib()
def test_make_tarball(self):
# creating something to tar
root_dir, base_dir = self._create_files('')
@@ -1302,7 +1302,7 @@
write_file((root_dir, 'outer'), 'xxx')
return root_dir, base_dir
- @support.requires_zlib
+ @support.requires_zlib()
@unittest.skipUnless(shutil.which('tar'),
'Need the tar command to run')
def test_tarfile_vs_tar(self):
@@ -1335,7 +1335,7 @@
self.assertEqual(tarball, base_name + '.tar')
self.assertTrue(os.path.isfile(tarball))
- @support.requires_zlib
+ @support.requires_zlib()
def test_make_zipfile(self):
# creating something to zip
root_dir, base_dir = self._create_files()
@@ -1372,7 +1372,7 @@
['dist/', 'dist/sub/', 'dist/sub2/',
'dist/file1', 'dist/file2', 'dist/sub/file3'])
- @support.requires_zlib
+ @support.requires_zlib()
@unittest.skipUnless(shutil.which('zip'),
'Need the zip command to run')
def test_zipfile_vs_zip(self):
@@ -1398,7 +1398,7 @@
names2 = zf.namelist()
self.assertEqual(sorted(names), sorted(names2))
- @support.requires_zlib
+ @support.requires_zlib()
@unittest.skipUnless(shutil.which('unzip'),
'Need the unzip command to run')
def test_unzip_zipfile(self):
@@ -1427,7 +1427,7 @@
base_name = os.path.join(tmpdir, 'archive')
self.assertRaises(ValueError, make_archive, base_name, 'xxx')
- @support.requires_zlib
+ @support.requires_zlib()
def test_make_archive_owner_group(self):
# testing make_archive with owner and group, with various combinations
# this works even if there's not gid/uid support
@@ -1455,7 +1455,7 @@
self.assertTrue(os.path.isfile(res))
- @support.requires_zlib
+ @support.requires_zlib()
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
def test_tarfile_root_owner(self):
root_dir, base_dir = self._create_files()
@@ -1500,7 +1500,7 @@
self.assertEqual(make_archive('test', 'tar'), 'test.tar')
self.assertTrue(os.path.isfile('test.tar'))
- @support.requires_zlib
+ @support.requires_zlib()
def test_make_zipfile_in_curdir(self):
# Issue #21280
root_dir = self.mkdtemp()
@@ -1555,20 +1555,20 @@
def test_unpack_archive_tar(self):
self.check_unpack_archive('tar')
- @support.requires_zlib
+ @support.requires_zlib()
def test_unpack_archive_gztar(self):
self.check_unpack_archive('gztar')
- @support.requires_bz2
+ @support.requires_bz2()
def test_unpack_archive_bztar(self):
self.check_unpack_archive('bztar')
- @support.requires_lzma
+ @support.requires_lzma()
@unittest.skipIf(AIX and not _maxdataOK(), "AIX MAXDATA must be 0x20000000 or larger")
def test_unpack_archive_xztar(self):
self.check_unpack_archive('xztar')
- @support.requires_zlib
+ @support.requires_zlib()
def test_unpack_archive_zip(self):
self.check_unpack_archive('zip')