diff options
| author | natsuoto <[email protected]> | 2026-07-16 17:31:49 +0530 |
|---|---|---|
| committer | natsuoto <[email protected]> | 2026-07-16 17:31:49 +0530 |
| commit | 1b43c8dc09adb9b54609cc8a1916c99eb6fe75c9 (patch) | |
| tree | 7731af50ed9117f8ac3d200591c3be23818d7b19 /tests/serialize | |
| parent | b7ae2f3885d5ff84237c9da8bc0c64fe1a509465 (diff) | |
| download | edify-1b43c8dc09adb9b54609cc8a1916c99eb6fe75c9.tar.xz edify-1b43c8dc09adb9b54609cc8a1916c99eb6fe75c9.zip | |
chore: enforce fully strict static typing across library, tests, and tooling with zero suppressions
Diffstat (limited to 'tests/serialize')
| -rw-r--r-- | tests/serialize/errors.test.py | 14 | ||||
| -rw-r--r-- | tests/serialize/roundtrip.test.py | 17 |
2 files changed, 18 insertions, 13 deletions
diff --git a/tests/serialize/errors.test.py b/tests/serialize/errors.test.py index 1b7dd39..cc5ec30 100644 --- a/tests/serialize/errors.test.py +++ b/tests/serialize/errors.test.py @@ -11,6 +11,7 @@ from edify.errors.serialize import ( NonObjectJSONPayloadError, UnknownElementKindError, ) +from edify.serialize import JSONValue def test_missing_edify_key_raises(): @@ -24,7 +25,7 @@ def test_missing_pattern_key_raises(): def test_missing_kind_on_nested_node_raises(): - document = { + document: dict[str, JSONValue] = { "edify": 0, "pattern": {"kind": "root", "children": [{"value": "x"}]}, } @@ -33,13 +34,13 @@ def test_missing_kind_on_nested_node_raises(): def test_incompatible_schema_version_raises(): - document = {"edify": 999, "pattern": {"kind": "root", "children": []}} + document: dict[str, JSONValue] = {"edify": 999, "pattern": {"kind": "root", "children": []}} with pytest.raises(IncompatibleSchemaVersionError): Pattern.from_dict(document) def test_unknown_kind_raises(): - document = { + document: dict[str, JSONValue] = { "edify": 0, "pattern": {"kind": "root", "children": [{"kind": "mystery"}]}, } @@ -58,12 +59,15 @@ def test_non_object_json_payload_raises_non_object_json_payload_error(): def test_incompatible_schema_version_with_composite_value_stringifies_it(): - document = {"edify": [1, 2, 3], "pattern": {"kind": "root", "children": []}} + document: dict[str, JSONValue] = { + "edify": [1, 2, 3], + "pattern": {"kind": "root", "children": []}, + } with pytest.raises(IncompatibleSchemaVersionError): Pattern.from_dict(document) def test_pattern_key_not_a_root_element_produces_empty_pattern(): - document = {"edify": 0, "pattern": {"kind": "digit"}} + document: dict[str, JSONValue] = {"edify": 0, "pattern": {"kind": "digit"}} restored = Pattern.from_dict(document) assert restored.to_regex_string() == "(?:)" diff --git a/tests/serialize/roundtrip.test.py b/tests/serialize/roundtrip.test.py index a3d7ea0..cc8c762 100644 --- a/tests/serialize/roundtrip.test.py +++ b/tests/serialize/roundtrip.test.py @@ -1,6 +1,7 @@ """Round-trip tests for Pattern.to_dict/from_dict and to_json/from_json.""" from edify import END, START, Pattern +from edify.serialize import JSONValue def _roundtrip_dict(pattern: Pattern) -> Pattern: @@ -28,8 +29,8 @@ def test_anchored_pattern_roundtrips(): original = Pattern().start_of_input().one_or_more().digit().end_of_input() restored = _roundtrip_json(original) assert restored == original - assert restored._state.has_defined_start - assert restored._state.has_defined_end + assert restored.state.has_defined_start + assert restored.state.has_defined_end def test_char_class_pattern_roundtrips(): @@ -55,15 +56,15 @@ def test_anything_but_string_roundtrips(): def test_capture_group_roundtrips(): original = Pattern().capture().digit().end() assert _roundtrip_dict(original) == original - assert _roundtrip_dict(original)._state.total_capture_groups == 1 + assert _roundtrip_dict(original).state.total_capture_groups == 1 def test_named_capture_roundtrips_with_names_and_count(): original = Pattern().named_capture("year").exactly(4).digit().end() restored = _roundtrip_dict(original) assert restored == original - assert restored._state.named_groups == ("year",) - assert restored._state.total_capture_groups == 1 + assert restored.state.named_groups == ("year",) + assert restored.state.total_capture_groups == 1 def test_backreference_roundtrips(): @@ -189,8 +190,8 @@ def test_flags_survive_roundtrip(): original = Pattern().ignore_case().multi_line().digit() restored = _roundtrip_dict(original) assert restored == original - assert restored._state.flags.ignore_case - assert restored._state.flags.multiline + assert restored.state.flags.ignore_case + assert restored.state.flags.multiline def test_string_element_roundtrips(): @@ -230,7 +231,7 @@ def test_flags_key_omitted_when_no_flags_set(): def test_unknown_element_field_is_ignored_for_forward_compatibility(): - document = { + document: dict[str, JSONValue] = { "edify": 0, "pattern": { "kind": "root", |
