diff --git a/codecov.yml b/codecov.yml index 75e0b701..b6065253 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,4 +1,4 @@ ignore: - "docs" - "tests" - - "examples" + - "examples" \ No newline at end of file diff --git a/pyjelly/options.py b/pyjelly/options.py index 64ee8b00..e1a1cdd9 100644 --- a/pyjelly/options.py +++ b/pyjelly/options.py @@ -76,6 +76,12 @@ 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) diff --git a/tests/unit_tests/test_options.py b/tests/unit_tests/test_options.py index 762946fc..64688e2d 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 @@ -151,3 +159,28 @@ 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_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