本文整理汇总了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