Skip to content

Commit e5b9b2c

Browse files
committed
test: Promote the two chunking gaps openjd-model 0.6.0 closes
openjd-rs#355 closed both divergences that `test/openjd/model_v1/test_known_gaps.py` recorded as strict xfails, so with `xfail_strict = true` they now fail as xpasses. That file's own rule is to promote a resolved gap to its proper home rather than drop the marker in place, so both move to `test_step_param_space_iter.py` beside the rest of `TestChunksTaskCountOverride`. - A CONTIGUOUS chunked space supports random access. `it[0]`, `it[1]` and `it[-1]` answer, indexing observes `chunks_task_count_override`, and one past the end is still an IndexError. This replaces `test_a_contiguous_space_refuses_indexing_with_or_without_the_override`, which asserted the refusal and named this exact swap as its counterpart. - `chunks_parameter_name` and `chunks_default_task_count` report for any chunked space, not only an adaptive one, which is what v0 has always done. Added `test_an_adaptive_space_still_refuses_indexing` as the negative control and the remaining limitation: an adaptive space has no knowable count, so `len()` raises ValueError and every index is out of range, while iteration still yields. Measured, along with everything asserted above, against openjd-model 0.6.0 before the assertions were written. Both promoted assertions are falsifiable by the version alone: they were strict xfails passing on mainline at openjd-model 0.5.4, so they failed there, and the CI run on 007f212 reports them xpassing at 0.6.0. `specs/python-model-interface.md` claimed both limitations and pointed at the xfails by name; it now states the random access that works and the one adaptive limitation that remains. The `Optional[str]`/`Optional[int]` signatures are unchanged -- both getters still answer None for a space that is not chunked. Verified: 5551 passed, 24 skipped, 3 xfailed with the 94% coverage gate enforced; ruff, black and mypy clean. `test_known_gaps.py` is now down to one test, which is a passing regression test rather than a gap. Left where it is rather than widen this change. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent 007f212 commit e5b9b2c

3 files changed

Lines changed: 82 additions & 148 deletions

File tree

‎specs/python-model-interface.md‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,20 +1176,16 @@ least 1, so 0 would otherwise silently mean 1, and the
11761176
`chunks_default_task_count` setter already rejects it. The pure-Python
11771177
reference does not validate this argument.
11781178

1179-
Two current-implementation limitations, both divergences from the v0
1180-
reference rather than intended behaviour. Each has a `strict` xfail in
1181-
`test/openjd/model_v1/test_known_gaps.py`, so clearing either will fail
1182-
CI until this text is updated with it.
1183-
1184-
- Indexing observes the override only for a space that supports random
1185-
access. A `CONTIGUOUS` chunked space requires sequential iteration, so
1186-
`it[i]` raises `IndexError` for any index — with or without the
1187-
override — even though `len(it)` reports a count. See
1188-
`test_a_contiguous_chunked_space_supports_indexing`.
1189-
- `chunks_parameter_name` and `chunks_default_task_count` both return
1190-
`None` once the space is non-adaptive, which supplying the override
1191-
makes it. v0 reports the parameter name and the override value. See
1192-
`test_chunk_metadata_is_reported_for_a_non_adaptive_space`.
1179+
Indexing observes the override. `openjd-model` 0.6.0 gave a `CONTIGUOUS`
1180+
chunked space random access, so `it[i]` answers there as it does for a
1181+
`NONCONTIGUOUS` one, and reports the overridden granularity rather than
1182+
the template's.
1183+
1184+
One current-implementation limitation remains. An *adaptive* space has no
1185+
knowable count until it is walked, so `len(it)` raises `ValueError` and
1186+
every index — including `-1` — raises `IndexError`. Iteration still
1187+
yields, which is what distinguishes an unknown count from an empty space.
1188+
Supplying the override makes the space static and lifts both.
11931189

11941190
### `StepDependencyGraph`
11951191

‎test/openjd/model_v1/test_known_gaps.py‎

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
from __future__ import annotations
2121

22-
from typing import Any
23-
2422
# ── Top-level package no longer leaks typing imports ──
2523
#
2624
# An earlier draft of ``openjd.model._v1`` imported ``Any``,
@@ -43,121 +41,3 @@ def test_no_internal_imports_leak_at_top_level(name: str) -> None:
4341
import openjd.model._v1 as v1
4442

4543
assert not hasattr(v1, name), f"{name} leaks as a public attribute on openjd.model._v1"
46-
47-
48-
# ── Chunked parameter spaces: two divergences from the v0 reference ──
49-
#
50-
# Found while adding `chunks_task_count_override` to
51-
# `StepParameterSpaceIterator`. Neither is caused by that argument — both
52-
# reproduce without it — so they are recorded here rather than fixed in
53-
# passing.
54-
55-
56-
def _chunked_step(constraint: str) -> Any:
57-
from openjd.model._v1 import create_job, decode_job_template
58-
59-
template = {
60-
"specificationVersion": "jobtemplate-2023-09",
61-
"name": "T",
62-
"extensions": ["TASK_CHUNKING"],
63-
"steps": [
64-
{
65-
"name": "S",
66-
"parameterSpace": {
67-
"taskParameterDefinitions": [
68-
{
69-
"name": "Frame",
70-
"type": "CHUNK[INT]",
71-
"range": "1-10",
72-
"chunks": {"defaultTaskCount": 5, "rangeConstraint": constraint},
73-
}
74-
]
75-
},
76-
"script": {
77-
"actions": {"onRun": {"command": "echo", "args": ["{{Task.Param.Frame}}"]}}
78-
},
79-
}
80-
],
81-
}
82-
job_template = decode_job_template(template=template, supported_extensions=["TASK_CHUNKING"])
83-
return create_job(job_template=job_template, job_parameter_values={}).steps[0]
84-
85-
86-
@pytest.mark.xfail(
87-
reason="v1 derives chunks_parameter_name and chunks_default_task_count from adaptive "
88-
"detection, so both are None for any non-adaptive chunked space. v0 reports them for "
89-
"any chunked space. See openjd-model step_param_space.rs: chunks_param_name and "
90-
"adaptive_chunk_size are both built from adaptive_info.",
91-
strict=True,
92-
)
93-
@pytest.mark.parametrize(
94-
"chunks,override,expected_count",
95-
[
96-
# Statically chunked: no override involved, v0 reports the template's size.
97-
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, None, 5),
98-
# Statically chunked, re-chunked by the override.
99-
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, 1, 1),
100-
# Adaptive, turned static by the override. v0 reports the override as the size.
101-
(
102-
{"defaultTaskCount": 5, "targetRuntimeSeconds": 60, "rangeConstraint": "CONTIGUOUS"},
103-
1,
104-
1,
105-
),
106-
],
107-
ids=["static", "static-overridden", "adaptive-overridden"],
108-
)
109-
def test_chunk_metadata_is_reported_for_a_non_adaptive_space(
110-
chunks: dict, override: int | None, expected_count: int
111-
) -> None:
112-
"""v0 returns ``"Frame"`` and the chunk size for each of these. v1 returns ``None``.
113-
114-
Neither value is unknowable — both are in the template, or are the override the caller
115-
just passed — so a consumer inspecting a non-adaptive chunked space through v1 cannot
116-
learn which parameter chunks, or at what size. One root cause, three ways to reach it:
117-
anything that leaves the space non-adaptive drops both getters.
118-
"""
119-
from openjd.model._v1 import create_job, decode_job_template
120-
from openjd.model._v1.job import StepParameterSpaceIterator
121-
122-
template = {
123-
"specificationVersion": "jobtemplate-2023-09",
124-
"name": "T",
125-
"extensions": ["TASK_CHUNKING"],
126-
"steps": [
127-
{
128-
"name": "S",
129-
"parameterSpace": {
130-
"taskParameterDefinitions": [
131-
{"name": "Frame", "type": "CHUNK[INT]", "range": "1-10", "chunks": chunks}
132-
]
133-
},
134-
"script": {
135-
"actions": {"onRun": {"command": "echo", "args": ["{{Task.Param.Frame}}"]}}
136-
},
137-
}
138-
],
139-
}
140-
job_template = decode_job_template(template=template, supported_extensions=["TASK_CHUNKING"])
141-
step = create_job(job_template=job_template, job_parameter_values={}).steps[0]
142-
143-
it = StepParameterSpaceIterator(step=step, chunks_task_count_override=override)
144-
assert it.chunks_adaptive is False
145-
assert it.chunks_parameter_name == "Frame"
146-
assert it.chunks_default_task_count == expected_count
147-
148-
149-
@pytest.mark.xfail(
150-
reason="v1 refuses random access whenever the space needs sequential iteration, and "
151-
"contiguous chunking always does. v0 supports indexing the same space.",
152-
strict=True,
153-
)
154-
def test_a_contiguous_chunked_space_supports_indexing() -> None:
155-
"""v0 answers ``it[0]`` with ``1-5``. v1 raises ``IndexError``.
156-
157-
``len()`` works on this space, so the count is known; only ``get`` declines.
158-
"""
159-
from openjd.model._v1.job import StepParameterSpaceIterator
160-
161-
it = StepParameterSpaceIterator(step=_chunked_step("CONTIGUOUS"))
162-
assert len(it) == 2
163-
assert it[0]["Frame"].value == "1-5"

‎test/openjd/model_v1/test_step_param_space_iter.py‎

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
``{type, range, [chunks]}`` matching the YAML/JSON template syntax.
1515
"""
1616

17-
from typing import Any, Callable
17+
from typing import Any, Callable, Optional
1818

1919
import pytest
2020

@@ -741,21 +741,79 @@ def test_indexing_observes_the_override(self) -> None:
741741
assert fresh[9]["Frame"].value == yielded[-1]
742742
assert fresh[-1]["Frame"].value == yielded[-1]
743743

744-
def test_a_contiguous_space_refuses_indexing_with_or_without_the_override(self) -> None:
745-
"""Pre-existing behaviour the override does not change: openjd-model requires
746-
sequential iteration for contiguous chunking, so ``get`` always declines.
747-
Pinned here so a future change to random access is a deliberate one. Its
748-
counterpart is ``test_known_gaps.py::test_a_contiguous_chunked_space_supports_indexing``,
749-
a strict xfail asserting the opposite: closing that gap fails there as an xpass
750-
*and* here as a hard assertion, so both move together, along with the
751-
limitation noted in ``specs/python-model-interface.md``."""
752-
for override in (None, 1):
753-
it = StepParameterSpaceIterator(
754-
step=self._step(self._STATIC), chunks_task_count_override=override
755-
)
744+
def test_a_contiguous_space_supports_indexing_with_or_without_the_override(self) -> None:
745+
"""openjd-model 0.6.0 (openjd-rs#355) gave a contiguous chunked space random
746+
access, so ``get`` now answers where it used to decline. Promoted from
747+
``test_known_gaps.py::test_a_contiguous_chunked_space_supports_indexing``,
748+
which pinned the v0 reading as a strict xfail.
749+
750+
Indexing observes the override, same as the NONCONTIGUOUS case above, and the
751+
end of the space is still an ``IndexError``.
752+
"""
753+
it = StepParameterSpaceIterator(step=self._step(self._STATIC))
754+
assert [it[0]["Frame"].value, it[1]["Frame"].value, it[-1]["Frame"].value] == [
755+
"1-5",
756+
"6-10",
757+
"6-10",
758+
]
759+
with pytest.raises(IndexError) as excinfo:
760+
_ = it[2]
761+
assert str(excinfo.value) == "index out of range"
762+
763+
overridden = StepParameterSpaceIterator(
764+
step=self._step(self._STATIC), chunks_task_count_override=1
765+
)
766+
assert [overridden[0]["Frame"].value, overridden[-1]["Frame"].value] == ["1-1", "10-10"]
767+
768+
def test_an_adaptive_space_still_refuses_indexing(self) -> None:
769+
"""The negative control for the test above, and the remaining limitation
770+
recorded in ``specs/python-model-interface.md``: an adaptive space has no
771+
knowable count, so ``len()`` raises and every index is out of range. Iteration
772+
still yields, which is what distinguishes "unknown count" from "empty"."""
773+
it = StepParameterSpaceIterator(step=self._step(self._ADAPTIVE))
774+
assert it.chunks_adaptive is True
775+
for index in (0, -1):
756776
with pytest.raises(IndexError) as excinfo:
757-
_ = it[0]
777+
_ = it[index]
758778
assert str(excinfo.value) == "index out of range"
779+
assert self._frames(StepParameterSpaceIterator(step=self._step(self._ADAPTIVE))) == [
780+
"1-5",
781+
"6-10",
782+
]
783+
784+
@pytest.mark.parametrize(
785+
"chunks,override,expected_count",
786+
[
787+
# Statically chunked: no override involved, the template's own size.
788+
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, None, 5),
789+
# Statically chunked, re-chunked by the override.
790+
({"defaultTaskCount": 5, "rangeConstraint": "CONTIGUOUS"}, 1, 1),
791+
# Adaptive, turned static by the override, which becomes the size.
792+
(
793+
{
794+
"defaultTaskCount": 5,
795+
"targetRuntimeSeconds": 60,
796+
"rangeConstraint": "CONTIGUOUS",
797+
},
798+
1,
799+
1,
800+
),
801+
],
802+
ids=["static", "static-overridden", "adaptive-overridden"],
803+
)
804+
def test_chunk_metadata_is_reported_for_a_non_adaptive_space(
805+
self, chunks: dict[str, Any], override: Optional[int], expected_count: int
806+
) -> None:
807+
"""openjd-model 0.6.0 (openjd-rs#355) reports ``chunks_parameter_name`` and
808+
``chunks_default_task_count`` for any chunked space, not only an adaptive one,
809+
which is what the v0 reference has always done. Promoted from
810+
``test_known_gaps.py``, where it was a strict xfail."""
811+
it = StepParameterSpaceIterator(
812+
step=self._step(chunks), chunks_task_count_override=override
813+
)
814+
assert it.chunks_adaptive is False
815+
assert it.chunks_parameter_name == "Frame"
816+
assert it.chunks_default_task_count == expected_count
759817

760818
def test_an_intermediate_override_regroups_the_chunks(self) -> None:
761819
"""Not just 1: any positive size regroups the space."""

0 commit comments

Comments
 (0)