1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import tarfile
import pytest
from upath import UPath
from upath.implementations.tar import TarPath
from ..cases import JoinablePathTests
from ..cases import NonWritablePathTests
from ..cases import ReadablePathTests
from ..utils import OverrideMeta
from ..utils import overrides_base
@pytest.fixture(scope="function")
def tarred_testdir_file(local_testdir, tmp_path_factory):
base = tmp_path_factory.mktemp("tarpath")
tar_path = base / "test.tar"
with tarfile.TarFile(tar_path, "w") as tf:
tf.add(local_testdir, arcname="", recursive=True)
return str(tar_path)
class TestTarPath(
JoinablePathTests,
ReadablePathTests,
NonWritablePathTests,
metaclass=OverrideMeta,
):
@pytest.fixture(autouse=True)
def path(self, tarred_testdir_file):
self.path = UPath("tar://", fo=tarred_testdir_file)
# self.prepare_file_system() done outside of UPath
@overrides_base
def test_is_correct_class(self):
assert isinstance(self.path, TarPath)
@pytest.fixture(scope="function")
def tarred_testdir_file_in_memory(tarred_testdir_file, clear_fsspec_memory_cache):
p = UPath(tarred_testdir_file, protocol="file")
t = p.move(UPath("memory:///mytarfile.tar"))
assert t.protocol == "memory"
assert t.exists()
yield t.as_uri()
class TestChainedTarPath(TestTarPath):
@pytest.fixture(autouse=True)
def path(self, tarred_testdir_file_in_memory):
self.path = UPath("tar://::memory:///mytarfile.tar")
|