bpo-8978: improve tarfile.open error message when lzma / bz2 are missing (GH-24850)

Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
Anthony Sottile 2021-04-27 10:39:01 -07:00 committed by GitHub
parent 8a37463989
commit 9aea31dedd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 2 deletions

View file

@ -2283,6 +2283,18 @@ class MiscTest(unittest.TestCase):
'SubsequentHeaderError', 'ExFileObject', 'main'}
support.check__all__(self, tarfile, not_exported=not_exported)
def test_useful_error_message_when_modules_missing(self):
fname = os.path.join(os.path.dirname(__file__), 'testtar.tar.xz')
with self.assertRaises(tarfile.ReadError) as excinfo:
error = tarfile.CompressionError('lzma module is not available'),
with unittest.mock.patch.object(tarfile.TarFile, 'xzopen', side_effect=error):
tarfile.open(fname)
self.assertIn(
"\n- method xz: CompressionError('lzma module is not available')\n",
str(excinfo.exception),
)
class CommandLineTest(unittest.TestCase):