Skip to content

Commit

Permalink
[test] Make ratarmountcore tests look for test files depending on __f…
Browse files Browse the repository at this point in the history
…ile__
  • Loading branch information
mxmlnkn committed Sep 23, 2023
1 parent 12d7c2c commit ea43572
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 11 additions & 3 deletions core/tests/test_AutoMountLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
from ratarmountcore import AutoMountLayer, openMountSource # noqa: E402


def findTestFile(relativePathOrName):
for i in range(3):
path = os.path.sep.join([".."] * i + ["tests", relativePathOrName])
if os.path.exists(path):
return path
return relativePathOrName


@pytest.mark.parametrize("parallelization", [1, 2, 4])
class TestAutoMountLayer:
@staticmethod
Expand All @@ -25,7 +33,7 @@ def test_regex_mount_point_tar(parallelization):
'transformRecursiveMountPoint': ('.*/([^/]*).tar', r'\1'),
}

with openMountSource("tests/packed-100-times.tar.gz", **options) as mountSource:
with openMountSource(findTestFile("packed-100-times.tar.gz"), **options) as mountSource:
recursivelyMounted = AutoMountLayer(mountSource, **options)

assert recursivelyMounted.listDir('/')
Expand All @@ -47,7 +55,7 @@ def test_regex_mount_point_tar_gz(parallelization):
# other files and those other files will actually take 10x or more longer than without this test running
# before! It might be that the memory usage makes Python's garbage collector a bottleneck because of too
# many small objects?!
with openMountSource("tests/compressed-100-times.tar.gz", **options) as mountSource:
with openMountSource(findTestFile("compressed-100-times.tar.gz"), **options) as mountSource:
recursivelyMounted = AutoMountLayer(mountSource, **options)

assert recursivelyMounted.listDir('/')
Expand All @@ -68,7 +76,7 @@ def test_regex_mount_point_gz(parallelization):
# > Recursively mounted: /ufo_805.gz
# > File "core/ratarmountcore/SQLiteIndexedTar.py", line 2085, in _detectTar
# > indexed_gzip.indexed_gzip.ZranError: zran_read returned error: ZRAN_READ_FAIL (file: n/a)
with openMountSource("tests/compressed-100-times.gz", **options) as mountSource:
with openMountSource(findTestFile("compressed-100-times.gz"), **options) as mountSource:
recursivelyMounted = AutoMountLayer(mountSource, **options)

assert recursivelyMounted.listDir('/')
Expand Down
18 changes: 13 additions & 5 deletions core/tests/test_SQLiteIndexedTar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
from ratarmountcore import RatarmountError, SQLiteIndexedTar # noqa: E402


def findTestFile(relativePathOrName):
for i in range(3):
path = os.path.sep.join([".."] * i + ["tests", relativePathOrName])
if os.path.exists(path):
return path
return relativePathOrName


@pytest.mark.parametrize("parallelization", [1, 2, 4])
class TestSQLiteIndexedTarParallelized:
@staticmethod
Expand All @@ -40,13 +48,13 @@ def _makeFolder(tarArchive, name):

@staticmethod
def test_context_manager(parallelization):
with SQLiteIndexedTar('tests/single-file.tar', writeIndex=False, parallelization=parallelization) as indexedTar:
with SQLiteIndexedTar(findTestFile('single-file.tar'), writeIndex=False, parallelization=parallelization) as indexedTar:
assert indexedTar.listDir('/')

@staticmethod
def test_tar_bz2_with_parallelization(parallelization):
with SQLiteIndexedTar(
"tests/2k-recursive-tars.tar.bz2",
findTestFile("2k-recursive-tars.tar.bz2"),
clearIndexCache=True,
recursive=False,
parallelization=parallelization,
Expand All @@ -65,7 +73,7 @@ def test_tar_bz2_with_parallelization(parallelization):
@staticmethod
def test_recursive_tar_bz2_with_parallelization(parallelization):
with SQLiteIndexedTar(
"tests/2k-recursive-tars.tar.bz2",
findTestFile("2k-recursive-tars.tar.bz2"),
clearIndexCache=True,
recursive=True,
parallelization=parallelization,
Expand All @@ -84,7 +92,7 @@ def test_recursive_tar_bz2_with_parallelization(parallelization):
@staticmethod
def test_deep_recursive(parallelization):
with SQLiteIndexedTar(
"tests/packed-5-times.tar.gz",
findTestFile("packed-5-times.tar.gz"),
clearIndexCache=True,
recursive=True,
parallelization=parallelization,
Expand Down Expand Up @@ -430,7 +438,7 @@ def test_appending_to_large_archive(parallelization, tmpdir):

# Create a TAR large in size as well as file count
tarPath = os.path.join(tmpdir, "foo.tar")
with indexed_bzip2.open("tests/tar-with-300-folders-with-1000-files-0B-files.tar.bz2") as file, open(
with indexed_bzip2.open(findTestFile("tar-with-300-folders-with-1000-files-0B-files.tar.bz2")) as file, open(
tarPath, 'wb'
) as extracted:
while True:
Expand Down

0 comments on commit ea43572

Please sign in to comment.