Skip to content

Commit db1bb75

Browse files
authored
Expand unit tests to improve code coverage for lookups (#254)
Added tests for the lookup encoder/decoder to expand the overall test coverage.
1 parent 5895738 commit db1bb75

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

tests/unit_tests/test_parse/test_lookup_decoder.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from hypothesis import given
33
from hypothesis import strategies as st
44

5-
from pyjelly.errors import JellyAssertionError
5+
from pyjelly.errors import JellyAssertionError, JellyConformanceError
66
from pyjelly.options import MAX_LOOKUP_SIZE
77
from pyjelly.parse.lookup import LookupDecoder
88

@@ -17,3 +17,25 @@ def test_max_lookup_size_exceeded(size: int) -> None:
1717
with pytest.raises(JellyAssertionError) as excinfo:
1818
LookupDecoder(lookup_size=size)
1919
assert str(excinfo.value) == f"lookup size must be less than {MAX_LOOKUP_SIZE}"
20+
21+
22+
def test_decode_zero_error() -> None:
23+
dec = LookupDecoder(lookup_size=1)
24+
dec.last_reused_index = -1
25+
with pytest.raises(JellyConformanceError):
26+
dec.decode_name_term_index(0)
27+
28+
29+
def test_datatype_index_zero_error() -> None:
30+
decoder = LookupDecoder(lookup_size=0)
31+
with pytest.raises(JellyConformanceError) as excinfo:
32+
decoder.decode_datatype_term_index(0)
33+
assert str(excinfo.value) == "0 is not a valid datatype term index"
34+
35+
36+
def test_at_invalid_index() -> None:
37+
decoder = LookupDecoder(lookup_size=4)
38+
with pytest.raises(IndexError) as excinfo:
39+
decoder.at(2)
40+
assert "invalid resolved index 2" in str(excinfo.value)
41+
assert decoder.last_reused_index == 2

tests/unit_tests/test_serialize/test_lookups/test_lookup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ def test_make_last_to_evict_for_existing_key_raises() -> None:
118118
lookup = Lookup(1)
119119
with pytest.raises(KeyError, match="key1"):
120120
lookup.make_last_to_evict("key1")
121+
122+
123+
def test_lookup_repr() -> None:
124+
lk = Lookup(1)
125+
lk.insert("a")
126+
assert str(lk) == f"Lookup(max_size={lk.max_size!r}, data={lk.data!r})"

0 commit comments

Comments
 (0)