|
3 | 3 | from unittest.mock import Mock |
4 | 4 |
|
5 | 5 | import pytest |
| 6 | +from _pytest.monkeypatch import MonkeyPatch |
6 | 7 |
|
| 8 | +import pyjelly.options as op |
7 | 9 | from pyjelly import jelly |
8 | | -from pyjelly.errors import JellyAssertionError |
9 | | -from pyjelly.options import StreamParameters, StreamTypes |
| 10 | +from pyjelly.errors import JellyAssertionError, JellyConformanceError |
| 11 | +from pyjelly.options import ( |
| 12 | + MIN_NAME_LOOKUP_SIZE, |
| 13 | + MIN_VERSION, |
| 14 | + LookupPreset, |
| 15 | + StreamParameters, |
| 16 | + StreamTypes, |
| 17 | +) |
10 | 18 | from pyjelly.parse.decode import options_from_frame |
11 | 19 |
|
12 | 20 |
|
|
54 | 62 | jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, |
55 | 63 | jelly.LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS, |
56 | 64 | ), |
| 65 | + (jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED, jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED), |
57 | 66 | ], |
58 | 67 | ) |
59 | 68 | def test_stream_types_ok( |
@@ -151,3 +160,42 @@ def test_stream_parameters(generalized_statements: int, rdf_star: int) -> None: |
151 | 160 | ) |
152 | 161 | assert params.generalized_statements == mock_options.generalized_statements |
153 | 162 | assert params.rdf_star == mock_options.rdf_star |
| 163 | + |
| 164 | + |
| 165 | +def test_lookup_preset_validation() -> None: |
| 166 | + with pytest.raises(JellyConformanceError): |
| 167 | + LookupPreset(max_names=MIN_NAME_LOOKUP_SIZE - 1) |
| 168 | + p = LookupPreset.small() |
| 169 | + assert (p.max_names, p.max_prefixes, p.max_datatypes) == (128, 32, 32) |
| 170 | + |
| 171 | + |
| 172 | +def test_stream_types_flat_and_repr() -> None: |
| 173 | + st = StreamTypes( |
| 174 | + physical_type=jelly.PHYSICAL_STREAM_TYPE_TRIPLES, |
| 175 | + logical_type=jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES, |
| 176 | + ) |
| 177 | + assert st.flat |
| 178 | + expected = ( |
| 179 | + f"StreamTypes(" |
| 180 | + f"{jelly.PhysicalStreamType.Name(st.physical_type)}, " |
| 181 | + f"{jelly.LogicalStreamType.Name(st.logical_type)})" |
| 182 | + ) |
| 183 | + assert str(st) == expected |
| 184 | + |
| 185 | + |
| 186 | +def test_stream_parameters_version() -> None: |
| 187 | + s1 = StreamParameters(namespace_declarations=False) |
| 188 | + assert s1.version == MIN_VERSION |
| 189 | + s2 = StreamParameters(namespace_declarations=True) |
| 190 | + assert s2.version == 2 |
| 191 | + |
| 192 | + |
| 193 | +def test_stream_options_invalid_version(monkeypatch: MonkeyPatch) -> None: |
| 194 | + monkeypatch.setattr(op, "MIN_VERSION", 10) |
| 195 | + monkeypatch.setattr(op, "MAX_VERSION", 5) |
| 196 | + |
| 197 | + with pytest.raises(JellyConformanceError) as excinfo: |
| 198 | + StreamParameters(namespace_declarations=True) |
| 199 | + |
| 200 | + msg = str(excinfo.value) |
| 201 | + assert "Version must be between 10 and 5" in msg |
0 commit comments