From e7da4298c85387245a4604afccda00ecaa588960 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Tue, 22 Jul 2025 16:33:55 +0200 Subject: [PATCH 1/8] Init commit, add tests --- .../test_lookup/test_lookup_object.py | 100 ++++++++++++++++++ tests/unit_tests/test_options/test_options.py | 71 +++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 tests/unit_tests/test_lookup/test_lookup_object.py create mode 100644 tests/unit_tests/test_options/test_options.py diff --git a/tests/unit_tests/test_lookup/test_lookup_object.py b/tests/unit_tests/test_lookup/test_lookup_object.py new file mode 100644 index 00000000..ff2c841c --- /dev/null +++ b/tests/unit_tests/test_lookup/test_lookup_object.py @@ -0,0 +1,100 @@ +import pytest + +from pyjelly.parse.lookup import ( + MAX_LOOKUP_SIZE, + JellyAssertionError, + JellyConformanceError, + LookupDecoder, +) +from pyjelly.serialize.lookup import Lookup, LookupEncoder + + +def test_lookup_core_functionality() -> None: + lk = Lookup(2) + with pytest.raises(IndexError): + Lookup(0).insert("x") + + a = lk.insert("a") + b = lk.insert("b") + with pytest.raises(AssertionError): + lk.insert("a") + + lk.make_last_to_evict("a") + c = lk.insert("c") + + assert (a, b, c) == (1, 2, 2) + assert list(lk.data.items()) == [("a", 1), ("c", 2)] + + +def test_lookup_repr() -> None: + lk = Lookup(1) + lk.insert("a") + assert str(lk) == f"Lookup(max_size={lk.max_size!r}, data={lk.data!r})" + + +def test_encode_entry() -> None: + enc = LookupEncoder(lookup_size=3) + assert enc.encode_entry_index("a") == 0 + assert enc.encode_entry_index("b") == 0 + assert enc.encode_entry_index("a") is None + assert enc.encode_entry_index("c") == 0 + assert enc.encode_entry_index("d") == 2 + + +def test_prefix_term_index_all() -> None: + enc = LookupEncoder(lookup_size=3) + assert enc.encode_prefix_term_index("") == 0 + enc.encode_entry_index("a") + first = enc.encode_prefix_term_index("a") + second = enc.encode_prefix_term_index("a") + assert (first, second) == (1, 0) + + +def test_datatype_term_zero_lookup() -> None: + enc = LookupEncoder(lookup_size=0) + assert enc.encode_datatype_term_index("x") == 0 + + +def test_name_term_index_zero_next() -> None: + enc = LookupEncoder(lookup_size=3) + enc.encode_entry_index("a") # id 1 + enc.encode_term_index("a") + enc.encode_entry_index("b") # id 2 + assert enc.encode_name_term_index("b") == 0 + enc.encode_entry_index("c") # id 3 + enc.encode_term_index("c") + enc.encode_entry_index("x") + result = enc.encode_name_term_index("c") + assert result in (1, 2, 3) + assert result != 0 + + +def test_lookup_decoder_size_error() -> None: + with pytest.raises(JellyAssertionError): + LookupDecoder(lookup_size=MAX_LOOKUP_SIZE + 1) + + +def test_lookup_decoder_flow() -> None: + dec = LookupDecoder(lookup_size=3) + + assert dec.decode_prefix_term_index(0) == "" + dec.assign_entry(0, "a") + dec.assign_entry(0, "b") + + assert dec.at(1) == "a" + assert dec.decode_prefix_term_index(1) == "a" + assert dec.decode_name_term_index(0) == "b" + + with pytest.raises(JellyConformanceError): + dec.decode_datatype_term_index(0) + assert dec.decode_datatype_term_index(2) == "b" + + with pytest.raises(IndexError): + dec.at(3) + + +def test_decode_zero_error() -> None: + dec = LookupDecoder(lookup_size=1) + dec.last_reused_index = -1 + with pytest.raises(JellyConformanceError): + dec.decode_name_term_index(0) diff --git a/tests/unit_tests/test_options/test_options.py b/tests/unit_tests/test_options/test_options.py new file mode 100644 index 00000000..c89aa466 --- /dev/null +++ b/tests/unit_tests/test_options/test_options.py @@ -0,0 +1,71 @@ +import mimetypes + +import pytest + +from pyjelly import jelly +from pyjelly.errors import JellyAssertionError, JellyConformanceError +from pyjelly.options import ( + MAX_VERSION, + MIMETYPES, + MIN_NAME_LOOKUP_SIZE, + MIN_VERSION, + LookupPreset, + register_mimetypes, + validate_type_compatibility, +) +from pyjelly.serialize.streams import StreamParameters, StreamTypes + + +def test_register_mimetypes() -> None: + register_mimetypes() + assert mimetypes.guess_type("x.jelly")[0] == MIMETYPES[0] + + +def test_lookup_preset_validation() -> None: + with pytest.raises(JellyConformanceError): + LookupPreset(max_names=MIN_NAME_LOOKUP_SIZE - 1) + p = LookupPreset.small() + assert (p.max_names, p.max_prefixes, p.max_datatypes) == (128, 32, 32) + + +def test_stream_types_flat_and_repr() -> None: + st = StreamTypes( + physical_type=jelly.PHYSICAL_STREAM_TYPE_TRIPLES, + logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, + ) + assert st.flat + expected = ( + f"StreamTypes(" + f"{jelly.PhysicalStreamType.Name(st.physical_type)}, " + f"{jelly.LogicalStreamType.Name(st.logical_type)})" + ) + assert str(st) == expected + + +def test_stream_types_incompatible_raises() -> None: + with pytest.raises(JellyAssertionError): + StreamTypes( + physical_type=jelly.PHYSICAL_STREAM_TYPE_QUADS, + logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, + ) + + +def test_validate_type_unspecified() -> None: + validate_type_compatibility( + jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, + jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED, + ) + + +def test_stream_parameters_version() -> None: + s1 = StreamParameters(namespace_declarations=False) + assert s1.version == MIN_VERSION + s2 = StreamParameters(namespace_declarations=True) + assert s2.version == MAX_VERSION + + +def test_stream_types_repr_supress() -> None: + physical_val = 9999 + logical_val = 8888 + st = StreamTypes(physical_type=physical_val, logical_type=logical_val) + assert str(st) == f"StreamTypes({physical_val}, {logical_val})" From 665ffbff745fa83823fbf372d1097e3c08fdc2c7 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Tue, 22 Jul 2025 16:51:35 +0200 Subject: [PATCH 2/8] Mypy fix --- tests/unit_tests/test_lookup/test_lookup_object.py | 9 +++------ tests/unit_tests/test_options/test_options.py | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/unit_tests/test_lookup/test_lookup_object.py b/tests/unit_tests/test_lookup/test_lookup_object.py index ff2c841c..c59c68bf 100644 --- a/tests/unit_tests/test_lookup/test_lookup_object.py +++ b/tests/unit_tests/test_lookup/test_lookup_object.py @@ -1,11 +1,8 @@ import pytest -from pyjelly.parse.lookup import ( - MAX_LOOKUP_SIZE, - JellyAssertionError, - JellyConformanceError, - LookupDecoder, -) +from pyjelly.errors import JellyAssertionError, JellyConformanceError +from pyjelly.options import MAX_LOOKUP_SIZE +from pyjelly.parse.lookup import LookupDecoder from pyjelly.serialize.lookup import Lookup, LookupEncoder diff --git a/tests/unit_tests/test_options/test_options.py b/tests/unit_tests/test_options/test_options.py index c89aa466..50674198 100644 --- a/tests/unit_tests/test_options/test_options.py +++ b/tests/unit_tests/test_options/test_options.py @@ -10,10 +10,11 @@ MIN_NAME_LOOKUP_SIZE, MIN_VERSION, LookupPreset, + StreamParameters, + StreamTypes, register_mimetypes, validate_type_compatibility, ) -from pyjelly.serialize.streams import StreamParameters, StreamTypes def test_register_mimetypes() -> None: @@ -67,5 +68,5 @@ def test_stream_parameters_version() -> None: def test_stream_types_repr_supress() -> None: physical_val = 9999 logical_val = 8888 - st = StreamTypes(physical_type=physical_val, logical_type=logical_val) + st = StreamTypes(physical_type=physical_val, logical_type=logical_val) # type: ignore[arg-type] assert str(st) == f"StreamTypes({physical_val}, {logical_val})" From 299241f7d1bebdc8c3a8f9cd4751272b49495330 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Tue, 29 Jul 2025 09:49:48 +0200 Subject: [PATCH 3/8] Apply patch --- codecov.yml | 1 + pyjelly/options.py | 4 ++ .../test_lookup/test_lookup_object.py | 9 ++--- tests/unit_tests/test_options/test_options.py | 38 +++++++------------ 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/codecov.yml b/codecov.yml index 75e0b701..ac4713c0 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,3 +2,4 @@ ignore: - "docs" - "tests" - "examples" + - "jelly" \ No newline at end of file diff --git a/pyjelly/options.py b/pyjelly/options.py index 64ee8b00..2e05893c 100644 --- a/pyjelly/options.py +++ b/pyjelly/options.py @@ -76,6 +76,10 @@ def flat(self) -> bool: ) def __repr__(self) -> str: + ''' + >>> repr(StreamTypes(9999, 8888)) + 'StreamTypes(9999, 8888)' + ''' with suppress(ValueError): physical_type_name = jelly.PhysicalStreamType.Name(self.physical_type) logical_type_name = jelly.LogicalStreamType.Name(self.logical_type) diff --git a/tests/unit_tests/test_lookup/test_lookup_object.py b/tests/unit_tests/test_lookup/test_lookup_object.py index c59c68bf..f340e336 100644 --- a/tests/unit_tests/test_lookup/test_lookup_object.py +++ b/tests/unit_tests/test_lookup/test_lookup_object.py @@ -1,7 +1,6 @@ import pytest -from pyjelly.errors import JellyAssertionError, JellyConformanceError -from pyjelly.options import MAX_LOOKUP_SIZE +from pyjelly.errors import JellyConformanceError from pyjelly.parse.lookup import LookupDecoder from pyjelly.serialize.lookup import Lookup, LookupEncoder @@ -66,9 +65,9 @@ def test_name_term_index_zero_next() -> None: assert result != 0 -def test_lookup_decoder_size_error() -> None: - with pytest.raises(JellyAssertionError): - LookupDecoder(lookup_size=MAX_LOOKUP_SIZE + 1) +# def test_lookup_decoder_size_error() -> None: +# with pytest.raises(JellyAssertionError): +# LookupDecoder(lookup_size=MAX_LOOKUP_SIZE + 1) def test_lookup_decoder_flow() -> None: diff --git a/tests/unit_tests/test_options/test_options.py b/tests/unit_tests/test_options/test_options.py index 50674198..752c207a 100644 --- a/tests/unit_tests/test_options/test_options.py +++ b/tests/unit_tests/test_options/test_options.py @@ -3,24 +3,17 @@ import pytest from pyjelly import jelly -from pyjelly.errors import JellyAssertionError, JellyConformanceError +from pyjelly.errors import JellyConformanceError from pyjelly.options import ( - MAX_VERSION, - MIMETYPES, MIN_NAME_LOOKUP_SIZE, MIN_VERSION, + MAX_VERSION, LookupPreset, StreamParameters, StreamTypes, - register_mimetypes, validate_type_compatibility, ) - - -def test_register_mimetypes() -> None: - register_mimetypes() - assert mimetypes.guess_type("x.jelly")[0] == MIMETYPES[0] - +import pyjelly.options as op def test_lookup_preset_validation() -> None: with pytest.raises(JellyConformanceError): @@ -42,15 +35,6 @@ def test_stream_types_flat_and_repr() -> None: ) assert str(st) == expected - -def test_stream_types_incompatible_raises() -> None: - with pytest.raises(JellyAssertionError): - StreamTypes( - physical_type=jelly.PHYSICAL_STREAM_TYPE_QUADS, - logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, - ) - - def test_validate_type_unspecified() -> None: validate_type_compatibility( jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, @@ -62,11 +46,15 @@ def test_stream_parameters_version() -> None: s1 = StreamParameters(namespace_declarations=False) assert s1.version == MIN_VERSION s2 = StreamParameters(namespace_declarations=True) - assert s2.version == MAX_VERSION + assert s2.version == 2 + +def test_stream_options_invalid_version(monkeypatch) -> None: + # Force MIN_VERSION > MAX_VERSION to trigger validation error + monkeypatch.setattr(op, 'MIN_VERSION', 10) + monkeypatch.setattr(op, 'MAX_VERSION', 5) + with pytest.raises(JellyConformanceError) as excinfo: + StreamParameters(namespace_declarations=True) -def test_stream_types_repr_supress() -> None: - physical_val = 9999 - logical_val = 8888 - st = StreamTypes(physical_type=physical_val, logical_type=logical_val) # type: ignore[arg-type] - assert str(st) == f"StreamTypes({physical_val}, {logical_val})" + msg = str(excinfo.value) + assert 'Version must be between 10 and 5' in msg From 28d39cc08b58cde987c6fc501b0e5f80a9fee006 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Wed, 30 Jul 2025 12:21:48 +0200 Subject: [PATCH 4/8] Move file + trim PR to 2 --- .../test_lookup/test_lookup_object.py | 96 ------------------- tests/unit_tests/test_options.py | 52 +++++++++- tests/unit_tests/test_options/test_options.py | 60 ------------ 3 files changed, 50 insertions(+), 158 deletions(-) delete mode 100644 tests/unit_tests/test_lookup/test_lookup_object.py delete mode 100644 tests/unit_tests/test_options/test_options.py diff --git a/tests/unit_tests/test_lookup/test_lookup_object.py b/tests/unit_tests/test_lookup/test_lookup_object.py deleted file mode 100644 index f340e336..00000000 --- a/tests/unit_tests/test_lookup/test_lookup_object.py +++ /dev/null @@ -1,96 +0,0 @@ -import pytest - -from pyjelly.errors import JellyConformanceError -from pyjelly.parse.lookup import LookupDecoder -from pyjelly.serialize.lookup import Lookup, LookupEncoder - - -def test_lookup_core_functionality() -> None: - lk = Lookup(2) - with pytest.raises(IndexError): - Lookup(0).insert("x") - - a = lk.insert("a") - b = lk.insert("b") - with pytest.raises(AssertionError): - lk.insert("a") - - lk.make_last_to_evict("a") - c = lk.insert("c") - - assert (a, b, c) == (1, 2, 2) - assert list(lk.data.items()) == [("a", 1), ("c", 2)] - - -def test_lookup_repr() -> None: - lk = Lookup(1) - lk.insert("a") - assert str(lk) == f"Lookup(max_size={lk.max_size!r}, data={lk.data!r})" - - -def test_encode_entry() -> None: - enc = LookupEncoder(lookup_size=3) - assert enc.encode_entry_index("a") == 0 - assert enc.encode_entry_index("b") == 0 - assert enc.encode_entry_index("a") is None - assert enc.encode_entry_index("c") == 0 - assert enc.encode_entry_index("d") == 2 - - -def test_prefix_term_index_all() -> None: - enc = LookupEncoder(lookup_size=3) - assert enc.encode_prefix_term_index("") == 0 - enc.encode_entry_index("a") - first = enc.encode_prefix_term_index("a") - second = enc.encode_prefix_term_index("a") - assert (first, second) == (1, 0) - - -def test_datatype_term_zero_lookup() -> None: - enc = LookupEncoder(lookup_size=0) - assert enc.encode_datatype_term_index("x") == 0 - - -def test_name_term_index_zero_next() -> None: - enc = LookupEncoder(lookup_size=3) - enc.encode_entry_index("a") # id 1 - enc.encode_term_index("a") - enc.encode_entry_index("b") # id 2 - assert enc.encode_name_term_index("b") == 0 - enc.encode_entry_index("c") # id 3 - enc.encode_term_index("c") - enc.encode_entry_index("x") - result = enc.encode_name_term_index("c") - assert result in (1, 2, 3) - assert result != 0 - - -# def test_lookup_decoder_size_error() -> None: -# with pytest.raises(JellyAssertionError): -# LookupDecoder(lookup_size=MAX_LOOKUP_SIZE + 1) - - -def test_lookup_decoder_flow() -> None: - dec = LookupDecoder(lookup_size=3) - - assert dec.decode_prefix_term_index(0) == "" - dec.assign_entry(0, "a") - dec.assign_entry(0, "b") - - assert dec.at(1) == "a" - assert dec.decode_prefix_term_index(1) == "a" - assert dec.decode_name_term_index(0) == "b" - - with pytest.raises(JellyConformanceError): - dec.decode_datatype_term_index(0) - assert dec.decode_datatype_term_index(2) == "b" - - with pytest.raises(IndexError): - dec.at(3) - - -def test_decode_zero_error() -> None: - dec = LookupDecoder(lookup_size=1) - dec.last_reused_index = -1 - with pytest.raises(JellyConformanceError): - dec.decode_name_term_index(0) diff --git a/tests/unit_tests/test_options.py b/tests/unit_tests/test_options.py index 762946fc..99399e1e 100644 --- a/tests/unit_tests/test_options.py +++ b/tests/unit_tests/test_options.py @@ -3,10 +3,18 @@ from unittest.mock import Mock import pytest +from _pytest.monkeypatch import MonkeyPatch +import pyjelly.options as op from pyjelly import jelly -from pyjelly.errors import JellyAssertionError -from pyjelly.options import StreamParameters, StreamTypes +from pyjelly.errors import JellyAssertionError, JellyConformanceError +from pyjelly.options import ( + MIN_NAME_LOOKUP_SIZE, + MIN_VERSION, + LookupPreset, + StreamParameters, + StreamTypes, +) from pyjelly.parse.decode import options_from_frame @@ -54,6 +62,7 @@ jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, jelly.LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS, ), + (jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED), ], ) def test_stream_types_ok( @@ -151,3 +160,42 @@ def test_stream_parameters(generalized_statements: int, rdf_star: int) -> None: ) assert params.generalized_statements == mock_options.generalized_statements assert params.rdf_star == mock_options.rdf_star + + +def test_lookup_preset_validation() -> None: + with pytest.raises(JellyConformanceError): + LookupPreset(max_names=MIN_NAME_LOOKUP_SIZE - 1) + p = LookupPreset.small() + assert (p.max_names, p.max_prefixes, p.max_datatypes) == (128, 32, 32) + + +def test_stream_types_flat_and_repr() -> None: + st = StreamTypes( + physical_type=jelly.PHYSICAL_STREAM_TYPE_TRIPLES, + logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, + ) + assert st.flat + expected = ( + f"StreamTypes(" + f"{jelly.PhysicalStreamType.Name(st.physical_type)}, " + f"{jelly.LogicalStreamType.Name(st.logical_type)})" + ) + assert str(st) == expected + + +def test_stream_parameters_version() -> None: + s1 = StreamParameters(namespace_declarations=False) + assert s1.version == MIN_VERSION + s2 = StreamParameters(namespace_declarations=True) + assert s2.version == 2 + + +def test_stream_options_invalid_version(monkeypatch: MonkeyPatch) -> None: + monkeypatch.setattr(op, "MIN_VERSION", 10) + monkeypatch.setattr(op, "MAX_VERSION", 5) + + with pytest.raises(JellyConformanceError) as excinfo: + StreamParameters(namespace_declarations=True) + + msg = str(excinfo.value) + assert "Version must be between 10 and 5" in msg diff --git a/tests/unit_tests/test_options/test_options.py b/tests/unit_tests/test_options/test_options.py deleted file mode 100644 index 752c207a..00000000 --- a/tests/unit_tests/test_options/test_options.py +++ /dev/null @@ -1,60 +0,0 @@ -import mimetypes - -import pytest - -from pyjelly import jelly -from pyjelly.errors import JellyConformanceError -from pyjelly.options import ( - MIN_NAME_LOOKUP_SIZE, - MIN_VERSION, - MAX_VERSION, - LookupPreset, - StreamParameters, - StreamTypes, - validate_type_compatibility, -) -import pyjelly.options as op - -def test_lookup_preset_validation() -> None: - with pytest.raises(JellyConformanceError): - LookupPreset(max_names=MIN_NAME_LOOKUP_SIZE - 1) - p = LookupPreset.small() - assert (p.max_names, p.max_prefixes, p.max_datatypes) == (128, 32, 32) - - -def test_stream_types_flat_and_repr() -> None: - st = StreamTypes( - physical_type=jelly.PHYSICAL_STREAM_TYPE_TRIPLES, - logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, - ) - assert st.flat - expected = ( - f"StreamTypes(" - f"{jelly.PhysicalStreamType.Name(st.physical_type)}, " - f"{jelly.LogicalStreamType.Name(st.logical_type)})" - ) - assert str(st) == expected - -def test_validate_type_unspecified() -> None: - validate_type_compatibility( - jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, - jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED, - ) - - -def test_stream_parameters_version() -> None: - s1 = StreamParameters(namespace_declarations=False) - assert s1.version == MIN_VERSION - s2 = StreamParameters(namespace_declarations=True) - assert s2.version == 2 - -def test_stream_options_invalid_version(monkeypatch) -> None: - # Force MIN_VERSION > MAX_VERSION to trigger validation error - monkeypatch.setattr(op, 'MIN_VERSION', 10) - monkeypatch.setattr(op, 'MAX_VERSION', 5) - - with pytest.raises(JellyConformanceError) as excinfo: - StreamParameters(namespace_declarations=True) - - msg = str(excinfo.value) - assert 'Version must be between 10 and 5' in msg From 34bd800452cfd5effb888e92535a4b17f23f0d25 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Wed, 30 Jul 2025 12:28:01 +0200 Subject: [PATCH 5/8] Lint --- pyjelly/options.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pyjelly/options.py b/pyjelly/options.py index 2e05893c..2320393b 100644 --- a/pyjelly/options.py +++ b/pyjelly/options.py @@ -76,22 +76,18 @@ def flat(self) -> bool: ) def __repr__(self) -> str: - ''' + """ + Return the representation of StreamTypes. + >>> repr(StreamTypes(9999, 8888)) 'StreamTypes(9999, 8888)' - ''' + """ with suppress(ValueError): physical_type_name = jelly.PhysicalStreamType.Name(self.physical_type) logical_type_name = jelly.LogicalStreamType.Name(self.logical_type) return f"StreamTypes({physical_type_name}, {logical_type_name})" return f"StreamTypes({self.physical_type}, {self.logical_type})" - def __post_init__(self) -> None: - validate_type_compatibility( - physical_type=self.physical_type, - logical_type=self.logical_type, - ) - @dataclass(frozen=True) class StreamParameters: From 2d37cf3c844d5abdef8615cd08bc404759df57b3 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Wed, 30 Jul 2025 12:39:28 +0200 Subject: [PATCH 6/8] Deleted _post_init_ by accident --- pyjelly/options.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyjelly/options.py b/pyjelly/options.py index 2320393b..e1a1cdd9 100644 --- a/pyjelly/options.py +++ b/pyjelly/options.py @@ -88,6 +88,12 @@ def __repr__(self) -> str: return f"StreamTypes({physical_type_name}, {logical_type_name})" return f"StreamTypes({self.physical_type}, {self.logical_type})" + def __post_init__(self) -> None: + validate_type_compatibility( + physical_type=self.physical_type, + logical_type=self.logical_type, + ) + @dataclass(frozen=True) class StreamParameters: From 3d2cc0b062f3f6a15299697465c5c949edf1200e Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Wed, 30 Jul 2025 14:11:46 +0200 Subject: [PATCH 7/8] Tweaks --- tests/unit_tests/test_options.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/unit_tests/test_options.py b/tests/unit_tests/test_options.py index 99399e1e..cda285f3 100644 --- a/tests/unit_tests/test_options.py +++ b/tests/unit_tests/test_options.py @@ -28,6 +28,7 @@ (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_FLAT_QUADS), (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_DATASETS), (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_NAMED_GRAPHS), + (jelly.PHYSICAL_STREAM_TYPE_TRIPLES, jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES), ( jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS, @@ -62,7 +63,6 @@ jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, jelly.LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS, ), - (jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED), ], ) def test_stream_types_ok( @@ -169,20 +169,6 @@ def test_lookup_preset_validation() -> None: assert (p.max_names, p.max_prefixes, p.max_datatypes) == (128, 32, 32) -def test_stream_types_flat_and_repr() -> None: - st = StreamTypes( - physical_type=jelly.PHYSICAL_STREAM_TYPE_TRIPLES, - logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, - ) - assert st.flat - expected = ( - f"StreamTypes(" - f"{jelly.PhysicalStreamType.Name(st.physical_type)}, " - f"{jelly.LogicalStreamType.Name(st.logical_type)})" - ) - assert str(st) == expected - - def test_stream_parameters_version() -> None: s1 = StreamParameters(namespace_declarations=False) assert s1.version == MIN_VERSION From b5f848d3a3ea6cbdc472671090a74c42b9e39036 Mon Sep 17 00:00:00 2001 From: JA-GK-00 Date: Wed, 30 Jul 2025 14:45:31 +0200 Subject: [PATCH 8/8] Tweaks --- codecov.yml | 3 +-- tests/unit_tests/test_options.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/codecov.yml b/codecov.yml index ac4713c0..b6065253 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,4 @@ ignore: - "docs" - "tests" - - "examples" - - "jelly" \ No newline at end of file + - "examples" \ No newline at end of file diff --git a/tests/unit_tests/test_options.py b/tests/unit_tests/test_options.py index cda285f3..64688e2d 100644 --- a/tests/unit_tests/test_options.py +++ b/tests/unit_tests/test_options.py @@ -28,7 +28,6 @@ (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_FLAT_QUADS), (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_DATASETS), (jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_NAMED_GRAPHS), - (jelly.PHYSICAL_STREAM_TYPE_TRIPLES, jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES), ( jelly.PHYSICAL_STREAM_TYPE_QUADS, jelly.LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS,