Skip to content

Commit 3228ecc

Browse files
committed
mypy + fixes
1 parent 1e8d3f9 commit 3228ecc

6 files changed

Lines changed: 137 additions & 127 deletions

File tree

autotest/test_dfns_registry.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,25 @@ def test_mapping_protocol(self, dfn_dir):
9393
# Test __len__
9494
assert len(spec) > 100 # Should have many components
9595

96-
# Test __iter__
97-
names = list(spec)
96+
# Test components iteration
97+
names = list(spec.components)
9898
assert "sim-nam" in names
9999
assert "gwf-nam" in names
100100
assert "gwf-chd" in names
101101

102-
# Test __getitem__
103-
gwf_chd = spec["gwf-chd"]
102+
# Test components access
103+
gwf_chd = spec.components["gwf-chd"]
104104
assert gwf_chd.name == "gwf-chd"
105105
assert gwf_chd.parent == "gwf-nam"
106106

107-
# Test __contains__
108-
assert "gwf-chd" in spec
109-
assert "nonexistent" not in spec
107+
# Test components containment
108+
assert "gwf-chd" in spec.components
109+
assert "nonexistent" not in spec.components
110110

111-
# Test keys(), values(), items()
112-
assert "gwf-wel" in spec.keys()
113-
assert any(d.name == "gwf-wel" for d in spec.values())
114-
assert any(n == "gwf-wel" for n, d in spec.items())
111+
# Test components keys(), values(), items()
112+
assert "gwf-wel" in spec.components.keys()
113+
assert any(d.name == "gwf-wel" for d in spec.components.values())
114+
assert any(n == "gwf-wel" for n, d in spec.components.items())
115115

116116
def test_getitem_raises_keyerror(self, dfn_dir):
117117
"""Test that __getitem__ raises KeyError for missing components."""
@@ -120,7 +120,7 @@ def test_getitem_raises_keyerror(self, dfn_dir):
120120
spec = DfnSpec.load(dfn_dir)
121121

122122
with pytest.raises(KeyError, match="nonexistent"):
123-
_ = spec["nonexistent"]
123+
_ = spec.components["nonexistent"]
124124

125125
def test_hierarchical_access(self, dfn_dir):
126126
"""Test accessing components through the hierarchical tree."""

autotest/test_dfns_schema.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _dim_block(*names: str) -> Block:
3232
"""Build a dimensions Block with the named Integer dimension fields."""
3333
return Block(
3434
name="dimensions",
35-
fields={n: Integer(name=n, dimension=True) for n in names},
35+
fields={n: Integer(name=n, dimension="component") for n in names},
3636
)
3737

3838

@@ -252,7 +252,7 @@ def test_dfnspec_construction_validates_dims():
252252
derived_dims={"nodes": "nlay * nrow * ncol"},
253253
)
254254
spec = DfnSpec(components={"gwf-dis": pkg})
255-
assert "gwf-dis" in spec
255+
assert "gwf-dis" in spec.components
256256

257257

258258
def test_dfnspec_construction_cycle_raises():
@@ -270,7 +270,7 @@ def test_dfnspec_construction_unknown_operand_raises():
270270
def test_dfnspec_no_derived_dims_constructs_fine():
271271
pkg = _pkg("gwf-chd", blocks=None, derived_dims=None)
272272
spec = DfnSpec(components={"gwf-chd": pkg})
273-
assert "gwf-chd" in spec
273+
assert "gwf-chd" in spec.components
274274

275275

276276
# ── DfnSpec.explicit_dims_for ─────────────────────────────────────────────────
@@ -359,29 +359,29 @@ def test_dfnspec_grid_dims_for_non_dis_siblings_excluded():
359359
# ── DfnSpec Mapping protocol ──────────────────────────────────────────────────
360360

361361

362-
def test_dfnspec_mapping_getitem():
362+
def test_dfnspec_components_getitem():
363363
pkg = _pkg("gwf-chd", parent="gwf-nam")
364364
spec = DfnSpec(components={"gwf-chd": pkg})
365-
assert spec["gwf-chd"] is pkg
365+
assert spec.components["gwf-chd"] is pkg
366366

367367

368-
def test_dfnspec_mapping_iter():
368+
def test_dfnspec_components_iter():
369369
pkg = _pkg("gwf-chd", parent="gwf-nam")
370370
spec = DfnSpec(components={"gwf-chd": pkg})
371-
assert list(spec) == ["gwf-chd"]
371+
assert list(spec.components) == ["gwf-chd"]
372372

373373

374-
def test_dfnspec_mapping_len():
374+
def test_dfnspec_components_len():
375375
pkgs = {f"gwf-p{i}": _pkg(f"gwf-p{i}") for i in range(3)}
376376
spec = DfnSpec(components=pkgs)
377-
assert len(spec) == 3
377+
assert len(spec.components) == 3
378378

379379

380-
def test_dfnspec_mapping_contains():
380+
def test_dfnspec_components_contains():
381381
pkg = _pkg("gwf-chd")
382382
spec = DfnSpec(components={"gwf-chd": pkg})
383-
assert "gwf-chd" in spec
384-
assert "gwf-rch" not in spec
383+
assert "gwf-chd" in spec.components
384+
assert "gwf-rch" not in spec.components
385385

386386

387387
# ── DfnSpec.schema_version ────────────────────────────────────────────────────
@@ -666,7 +666,7 @@ def test_dfnspec_valid_top_level_array_shape():
666666
)
667667
gwf = Model(name="gwf-nam", blocks=None)
668668
spec = DfnSpec(components={"gwf-nam": gwf, "gwf-dis": dis})
669-
assert "gwf-dis" in spec
669+
assert "gwf-dis" in spec.components
670670

671671

672672
def test_dfnspec_valid_array_in_record():
@@ -775,7 +775,7 @@ def _fk_pkg_and_spec(fk_val, pk_on_item=True, fk_ref=None):
775775
def test_validate_fk_fields_valid():
776776
lak, gwf = _fk_pkg_and_spec("packagedata", pk_on_item=True)
777777
spec = DfnSpec(components={"gwf-nam": gwf, "gwf-lak": lak})
778-
assert "gwf-lak" in spec
778+
assert "gwf-lak" in spec.components
779779

780780

781781
def test_validate_fk_fields_unknown_block_raises():
@@ -793,7 +793,7 @@ def test_validate_fk_fields_no_pk_on_item_raises():
793793
def test_validate_fk_fields_fk_ref_valid():
794794
lak, gwf = _fk_pkg_and_spec("packagedata", pk_on_item=True, fk_ref="gwf-nam")
795795
spec = DfnSpec(components={"gwf-nam": gwf, "gwf-lak": lak})
796-
assert "gwf-lak" in spec
796+
assert "gwf-lak" in spec.components
797797

798798

799799
def test_validate_fk_fields_fk_ref_unknown_raises():
@@ -809,7 +809,7 @@ def test_validate_fk_fields_no_fk_set_passes():
809809
pkg = Package(name="gwf-test", blocks={"data": block})
810810
gwf = Model(name="gwf-nam", blocks=None)
811811
spec = DfnSpec(components={"gwf-nam": gwf, "gwf-test": pkg})
812-
assert "gwf-test" in spec
812+
assert "gwf-test" in spec.components
813813

814814

815815
def test_validate_fk_fields_called_directly():

0 commit comments

Comments
 (0)