Python shutil.ReadError() Examples
The following are 6 code examples for showing how to use shutil.ReadError(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
shutil
, or try the search function
.
Example 1
Project: briefcase Author: beeware File: test_verify_android_sdk.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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) )
Example 2
Project: mathlib-tools Author: leanprover-community File: lib.py License: Apache License 2.0 | 6 votes |
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)
Example 3
Project: Fluid-Designer Author: Microvellum File: test_shutil.py License: GNU General Public License v3.0 | 6 votes |
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')
Example 4
Project: ironpython3 Author: IronLanguages File: test_shutil.py License: Apache License 2.0 | 6 votes |
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')
Example 5
Project: Project-New-Reign---Nemesis-Main Author: ShikyoKira File: test_shutil.py License: GNU General Public License v3.0 | 6 votes |
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')
Example 6
Project: briefcase Author: beeware File: test_verify_jdk.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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