Split chunker_test into fixed_test and buzhash_test modules

Separated `chunker_test` into two dedicated test modules: `fixed_test` (for `ChunkerFixed`) and `buzhash_test` (for `Chunker`). Updated imports and adjusted references accordingly.
This commit is contained in:
Thomas Waldmann 2025-06-05 00:47:08 +02:00
parent e7c9db9506
commit cd6360a894
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
5 changed files with 62 additions and 57 deletions

View file

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

View file

@ -4,66 +4,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
from . import cf
class ChunkerFixedTestCase(BaseTestCase):
def test_chunkify_just_blocks(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096)
parts = cf(chunker.chunkify(BytesIO(data)))
self.assert_equal(parts, [data[0:4096], data[4096:8192], data[8192:]])
def test_chunkify_header_and_blocks(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096, 123)
parts = cf(chunker.chunkify(BytesIO(data)))
self.assert_equal(
parts, [data[0:123], data[123 : 123 + 4096], data[123 + 4096 : 123 + 8192], data[123 + 8192 :]]
)
def test_chunkify_just_blocks_fmap_complete(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096)
fmap = [(0, 4096, True), (4096, 8192, True), (8192, 99999999, True)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
self.assert_equal(parts, [data[0:4096], data[4096:8192], data[8192:]])
def test_chunkify_header_and_blocks_fmap_complete(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096, 123)
fmap = [(0, 123, True), (123, 4096, True), (123 + 4096, 4096, True), (123 + 8192, 4096, True)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
self.assert_equal(
parts, [data[0:123], data[123 : 123 + 4096], data[123 + 4096 : 123 + 8192], data[123 + 8192 :]]
)
def test_chunkify_header_and_blocks_fmap_zeros(self):
data = b"H" * 123 + b"_" * 4096 + b"X" * 4096 + b"_" * 4096
chunker = ChunkerFixed(4096, 123)
fmap = [(0, 123, True), (123, 4096, False), (123 + 4096, 4096, True), (123 + 8192, 4096, False)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
# because we marked the '_' ranges as holes, we will get hole ranges instead!
self.assert_equal(parts, [data[0:123], 4096, data[123 + 4096 : 123 + 8192], 4096])
def test_chunkify_header_and_blocks_fmap_partial(self):
data = b"H" * 123 + b"_" * 4096 + b"X" * 4096 + b"_" * 4096
chunker = ChunkerFixed(4096, 123)
fmap = [
(0, 123, True),
# (123, 4096, False),
(123 + 4096, 4096, True),
# (123+8192, 4096, False),
]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
# because we left out the '_' ranges from the fmap, we will not get them at all!
self.assert_equal(parts, [data[0:123], data[123 + 4096 : 123 + 8192]])
class ChunkerTestCase(BaseTestCase):
def test_chunkify(self):
data = b"0" * int(1.5 * (1 << CHUNK_MAX_EXP)) + b"Y"

View file

@ -4,7 +4,7 @@ import tempfile
import pytest
from .chunker_test import cf
from . import cf
from ...chunkers import (
Chunker,
ChunkerFixed,

View file

@ -1,7 +1,7 @@
from hashlib import sha256
from io import BytesIO
from .chunker_test import cf
from . import cf
from ...chunkers import Chunker
from ...constants import * # NOQA
from ...helpers import hex_to_bin

View file

@ -0,0 +1,59 @@
from io import BytesIO
from ...chunkers.fixed import ChunkerFixed
from ...constants import * # NOQA
from .. import BaseTestCase
from . import cf
class ChunkerFixedTestCase(BaseTestCase):
def test_chunkify_just_blocks(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096)
parts = cf(chunker.chunkify(BytesIO(data)))
self.assert_equal(parts, [data[0:4096], data[4096:8192], data[8192:]])
def test_chunkify_header_and_blocks(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096, 123)
parts = cf(chunker.chunkify(BytesIO(data)))
self.assert_equal(
parts, [data[0:123], data[123 : 123 + 4096], data[123 + 4096 : 123 + 8192], data[123 + 8192 :]]
)
def test_chunkify_just_blocks_fmap_complete(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096)
fmap = [(0, 4096, True), (4096, 8192, True), (8192, 99999999, True)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
self.assert_equal(parts, [data[0:4096], data[4096:8192], data[8192:]])
def test_chunkify_header_and_blocks_fmap_complete(self):
data = b"foobar" * 1500
chunker = ChunkerFixed(4096, 123)
fmap = [(0, 123, True), (123, 4096, True), (123 + 4096, 4096, True), (123 + 8192, 4096, True)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
self.assert_equal(
parts, [data[0:123], data[123 : 123 + 4096], data[123 + 4096 : 123 + 8192], data[123 + 8192 :]]
)
def test_chunkify_header_and_blocks_fmap_zeros(self):
data = b"H" * 123 + b"_" * 4096 + b"X" * 4096 + b"_" * 4096
chunker = ChunkerFixed(4096, 123)
fmap = [(0, 123, True), (123, 4096, False), (123 + 4096, 4096, True), (123 + 8192, 4096, False)]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
# because we marked the '_' ranges as holes, we will get hole ranges instead!
self.assert_equal(parts, [data[0:123], 4096, data[123 + 4096 : 123 + 8192], 4096])
def test_chunkify_header_and_blocks_fmap_partial(self):
data = b"H" * 123 + b"_" * 4096 + b"X" * 4096 + b"_" * 4096
chunker = ChunkerFixed(4096, 123)
fmap = [
(0, 123, True),
# (123, 4096, False),
(123 + 4096, 4096, True),
# (123+8192, 4096, False),
]
parts = cf(chunker.chunkify(BytesIO(data), fmap=fmap))
# because we left out the '_' ranges from the fmap, we will not get them at all!
self.assert_equal(parts, [data[0:123], data[123 + 4096 : 123 + 8192]])