Skip to content

Commit

Permalink
Add test for initial CRC32CHash value
Browse files Browse the repository at this point in the history
Additionally, remove the empty values given to the several constructors
in the other tests, since they are the same as the default value for the
data parameter.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Aug 11, 2024
1 parent c531af5 commit 9f46efa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/test_crc32c.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,24 @@ class CRCTestValue(NamedTuple):
@pytest.mark.skipif(crc32c is None, reason="no crc32c support in this platform")
class TestCRC32CHash:
def test_misc(self) -> None:
crc32c_hash = crc32c.CRC32CHash(b"")
crc32c_hash = crc32c.CRC32CHash()

assert crc32c_hash.digest_size == 4
assert crc32c_hash.name == "crc32c"
assert len(crc32c_hash.digest()) == crc32c_hash.digest_size
assert len(crc32c_hash.hexdigest()) == crc32c_hash.digest_size * 2

def test_initial_value(self) -> None:
crc32c_hash = crc32c.CRC32CHash()
crc32c_hash.update(b"hello world")
expected = crc32c_hash.digest()

crc32c_hash = crc32c.CRC32CHash(b"hello")
crc32c_hash.update(b" world")
assert expected == crc32c_hash.digest()

def test_copy(self) -> None:
crc32c_hash = crc32c.CRC32CHash(b"")
crc32c_hash = crc32c.CRC32CHash()
crc32c_hash_copy = crc32c_hash.copy()

assert crc32c_hash.digest() == crc32c_hash_copy.digest()
Expand Down Expand Up @@ -172,7 +181,7 @@ def _check_values(crc32c_hash: crc32c.CRC32CHash, crc: int) -> None:
assert len(crc32c_hash.hexdigest()) == 8

def test_piece_by_piece(self, data: bytes, crc: int) -> None:
crc32c_hash = crc32c.CRC32CHash(b"")
crc32c_hash = crc32c.CRC32CHash()
for x in as_individual_bytes(data):
crc32c_hash.update(x)
self._check_values(crc32c_hash, crc)
Expand Down

0 comments on commit 9f46efa

Please sign in to comment.