Parcourir la source

tests: move chunker tests to own package

Thomas Waldmann il y a 1 mois
Parent
commit
e7c9db9506

+ 1 - 1
src/borg/selftest.py

@@ -22,7 +22,7 @@ import time
 from unittest import TestResult, TestSuite, defaultTestLoader
 
 from .testsuite.crypto_test import CryptoTestCase
-from .testsuite.chunker_test import ChunkerTestCase
+from .testsuite.chunkers.chunker_test import ChunkerTestCase
 
 SELFTEST_CASES = [CryptoTestCase, ChunkerTestCase]
 

+ 17 - 0
src/borg/testsuite/chunkers/__init__.py

@@ -0,0 +1,17 @@
+from borg.constants import *  # noqa
+
+
+def cf(chunks):
+    """chunk filter"""
+
+    # this is to simplify testing: either return the data piece (bytes) or the hole length (int).
+    def _cf(chunk):
+        if chunk.meta["allocation"] == CH_DATA:
+            assert len(chunk.data) == chunk.meta["size"]
+            return bytes(chunk.data)  # make sure we have bytes, not memoryview
+        if chunk.meta["allocation"] in (CH_HOLE, CH_ALLOC):
+            assert chunk.data is None
+            return chunk.meta["size"]
+        assert False, "unexpected allocation value"
+
+    return [_cf(chunk) for chunk in chunks]

+ 2 - 2
src/borg/testsuite/chunker_pytest_test.py → src/borg/testsuite/chunkers/chunker_pytest_test.py

@@ -5,7 +5,7 @@ import tempfile
 import pytest
 
 from .chunker_test import cf
-from ..chunkers import (
+from ...chunkers import (
     Chunker,
     ChunkerFixed,
     sparsemap,
@@ -15,7 +15,7 @@ from ..chunkers import (
     FileFMAPReader,
     Chunk,
 )
-from ..constants import *  # NOQA
+from ...constants import *  # NOQA
 
 BS = 4096  # fs block size
 

+ 3 - 3
src/borg/testsuite/chunker_slow_test.py → src/borg/testsuite/chunkers/chunker_slow_test.py

@@ -2,9 +2,9 @@ from hashlib import sha256
 from io import BytesIO
 
 from .chunker_test import cf
-from ..chunkers import Chunker
-from ..constants import *  # NOQA
-from ..helpers import hex_to_bin
+from ...chunkers import Chunker
+from ...constants import *  # NOQA
+from ...helpers import hex_to_bin
 
 
 def H(data):

+ 6 - 21
src/borg/testsuite/chunker_test.py → src/borg/testsuite/chunkers/chunker_test.py

@@ -3,27 +3,12 @@
 
 from io import BytesIO
 
-from ..chunkers import get_chunker
-from ..chunkers.fixed import ChunkerFixed
-from ..chunkers.buzhash import buzhash, buzhash_update, Chunker
-from ..constants import *  # NOQA
-from . import BaseTestCase
-
-
-def cf(chunks):
-    """chunk filter"""
-
-    # this is to simplify testing: either return the data piece (bytes) or the hole length (int).
-    def _cf(chunk):
-        if chunk.meta["allocation"] == CH_DATA:
-            assert len(chunk.data) == chunk.meta["size"]
-            return bytes(chunk.data)  # make sure we have bytes, not memoryview
-        if chunk.meta["allocation"] in (CH_HOLE, CH_ALLOC):
-            assert chunk.data is None
-            return chunk.meta["size"]
-        assert False, "unexpected allocation value"
-
-    return [_cf(chunk) for chunk in chunks]
+from ...chunkers import get_chunker
+from ...chunkers.fixed import ChunkerFixed
+from ...chunkers.buzhash import buzhash, buzhash_update, Chunker
+from ...constants import *  # NOQA
+from .. import BaseTestCase
+from . import cf
 
 
 class ChunkerFixedTestCase(BaseTestCase):