本文整理匯總了Python中shutil.ReadError方法的典型用法代碼示例。如果您正苦於以下問題:Python shutil.ReadError方法的具體用法?Python shutil.ReadError怎麽用?Python shutil.ReadError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類shutil
的用法示例。
在下文中一共展示了shutil.ReadError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_detects_bad_zipfile
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def test_detects_bad_zipfile(mock_command, tmp_path):
"If the ZIP file is corrupted, an error is raised."
android_sdk_root_path = tmp_path / ".briefcase" / "tools" / "android_sdk"
# The download will produce a cached file
cache_file = MagicMock()
cache_file.__str__.return_value = "/path/to/download.zip"
mock_command.download_url.return_value = cache_file
# But the unpack will fail.
mock_command.shutil.unpack_archive.side_effect = shutil.ReadError
with pytest.raises(BriefcaseCommandError):
verify_android_sdk(mock_command)
# The download attempt was made.
mock_command.download_url.assert_called_once_with(
url="https://dl.google.com/android/repository/sdk-tools-unknown-4333796.zip",
download_path=mock_command.dot_briefcase_path / "tools",
)
mock_command.shutil.unpack_archive.assert_called_once_with(
"/path/to/download.zip",
extract_dir=str(android_sdk_root_path)
)
示例2: get_mathlib_olean
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def get_mathlib_olean(self) -> None:
"""Get precompiled mathlib oleans for this project."""
# Just in case the user broke the workflow (for instance git clone
# mathlib by hand and then run `leanproject get-cache`)
if not (self.directory/'leanpkg.path').exists():
self.run(['leanpkg', 'configure'])
try:
archive = get_mathlib_archive(self.mathlib_rev, self.cache_url,
self.force_download, self.repo)
except (EOFError, shutil.ReadError):
log.info('Something wrong happened with the olean archive. '
'I will now retry downloading.')
archive = get_mathlib_archive(self.mathlib_rev, self.cache_url,
True, self.repo)
self.clean_mathlib()
self.mathlib_folder.mkdir(parents=True, exist_ok=True)
unpack_archive(archive, self.mathlib_folder)
# Let's now touch oleans, just in case
touch_oleans(self.mathlib_folder)
示例3: test_unpack_archive
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def test_unpack_archive(self):
formats = ['tar', 'gztar', 'zip']
if BZ2_SUPPORTED:
formats.append('bztar')
if LZMA_SUPPORTED:
formats.append('xztar')
root_dir, base_dir = self._create_files()
expected = rlistdir(root_dir)
expected.remove('outer')
for format in formats:
base_name = os.path.join(self.mkdtemp(), 'archive')
filename = make_archive(base_name, format, root_dir, base_dir)
# let's try to unpack it now
tmpdir2 = self.mkdtemp()
unpack_archive(filename, tmpdir2)
self.assertEqual(rlistdir(tmpdir2), expected)
# and again, this time with the format specified
tmpdir3 = self.mkdtemp()
unpack_archive(filename, tmpdir3, format=format)
self.assertEqual(rlistdir(tmpdir3), expected)
self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
示例4: test_unpack_archive
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def test_unpack_archive(self):
formats = ['tar', 'gztar', 'zip']
if BZ2_SUPPORTED:
formats.append('bztar')
root_dir, base_dir = self._create_files()
expected = rlistdir(root_dir)
expected.remove('outer')
for format in formats:
base_name = os.path.join(self.mkdtemp(), 'archive')
filename = make_archive(base_name, format, root_dir, base_dir)
# let's try to unpack it now
tmpdir2 = self.mkdtemp()
unpack_archive(filename, tmpdir2)
self.assertEqual(rlistdir(tmpdir2), expected)
# and again, this time with the format specified
tmpdir3 = self.mkdtemp()
unpack_archive(filename, tmpdir3, format=format)
self.assertEqual(rlistdir(tmpdir3), expected)
self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
示例5: check_unpack_archive
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def check_unpack_archive(self, format):
root_dir, base_dir = self._create_files()
expected = rlistdir(root_dir)
expected.remove('outer')
base_name = os.path.join(self.mkdtemp(), 'archive')
filename = make_archive(base_name, format, root_dir, base_dir)
# let's try to unpack it now
tmpdir2 = self.mkdtemp()
unpack_archive(filename, tmpdir2)
self.assertEqual(rlistdir(tmpdir2), expected)
# and again, this time with the format specified
tmpdir3 = self.mkdtemp()
unpack_archive(filename, tmpdir3, format=format)
self.assertEqual(rlistdir(tmpdir3), expected)
self.assertRaises(shutil.ReadError, unpack_archive, TESTFN)
self.assertRaises(ValueError, unpack_archive, TESTFN, format='xxx')
示例6: test_invalid_jdk_archive
# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import ReadError [as 別名]
def test_invalid_jdk_archive(test_command, tmp_path):
"If the JDK download isn't a valid archive, raise an error"
# Mock Linux as the host
test_command.host_os = 'Linux'
# Mock the cached download path
archive = mock.MagicMock()
archive.__str__.return_value = '/path/to/download.zip'
test_command.download_url.return_value = archive
# Mock an unpack failure due to an invalid archive
test_command.shutil.unpack_archive.side_effect = shutil.ReadError
with pytest.raises(BriefcaseCommandError):
verify_jdk(command=test_command)
# The download occurred
test_command.download_url.assert_called_with(
url="https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/"
"jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz",
download_path=tmp_path / "tools",
)
# An attempt was made to unpack the archive
test_command.shutil.unpack_archive.assert_called_with(
'/path/to/download.zip',
extract_dir=str(tmp_path / "tools")
)
# The original archive was not deleted
assert archive.unlink.call_count == 0