Skip to content

Commit 343a8ef

Browse files
committed
test: Update the range list element tests for openjd-model 0.16
Rebasing onto the bindings bump to openjd-expr 0.15, openjd-model 0.16 and openjd-sessions 0.10 changed three of these tests' outcomes: - Expression Language §1.2.3 now has string-to-number coercion ignore white space around the number (Template Schemas §7.5), and §1.3.12 gives a STRING value " 7 " as an INT range element as the example. openjd-expr 0.15 does this, so with EXPR v0 now resolves such an element as it does without EXPR. The test that pinned the old error now pins 7 for INT and "2.50" for FLOAT, and new cases pin that white space inside the number, "1 000", is still an error, with and without EXPR. - openjd.model._v1 now accepts a format string in an INT range list and flattens a list in a FLOAT one, so both strict xfails in test_known_gaps.py passed. The INT case is already covered by TestIntRangeListFormatStringElements in test_create_job.py, which the bump added, so it is removed. The FLOAT case moves to TestRangeListElementsAsListItems there, and asserts the values. Signed-off-by: Mark Wiebe <399551+mwiebe@users.noreply.github.com>
1 parent 7347bbf commit 343a8ef

3 files changed

Lines changed: 53 additions & 82 deletions

File tree

‎test/openjd/model_v0/test_range_list_items.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_int_elements_resolve(self, tmp_path, task_param, extensions) -> None:
105105
pytest.param({"type": "CHUNK[INT]", "chunks": _CHUNKS}, ["TASK_CHUNKING"], id="CHUNK"),
106106
],
107107
)
108-
@pytest.mark.parametrize("value", ["abc", "2.5", ""])
108+
@pytest.mark.parametrize("value", ["abc", "2.5", "", "1 000"])
109109
def test_int_element_not_an_integer(self, tmp_path, task_param, extensions, value) -> None:
110110
error = _range_error(
111111
tmp_path,
@@ -263,14 +263,29 @@ def test_list_of_wrong_type_rejected(self, tmp_path, task_param, extensions, tar
263263
" Param.L\n ~~~~~~^."
264264
)
265265

266-
def test_padded_string_does_not_coerce(self, tmp_path) -> None:
267-
# Expression Language §1.2.3 coercion does not trim, unlike the
268-
# <intstring> parse without EXPR.
266+
def test_white_space_around_the_number_is_ignored(self, tmp_path) -> None:
267+
# Expression Language §1.2.3 and §1.3.12: string-to-number coercion
268+
# ignores white space around the number (Template Schemas §7.5), so an
269+
# element resolves as it does without EXPR (test_int_elements_resolve,
270+
# test_float_elements_resolve_and_keep_their_spelling). The white space
271+
# is not part of a float's spelling (§1.3.4).
272+
params = [{"name": "S", "type": "STRING"}, {"name": "T", "type": "STRING"}]
273+
values = {"S": " 7\n", "T": "\t2.50 "}
274+
int_range = _range(
275+
tmp_path, {"type": "INT", "range": [1, "{{Param.S}}"]}, params, values, ["EXPR"]
276+
)
277+
float_range = _range(
278+
tmp_path, {"type": "FLOAT", "range": [1.5, "{{Param.T}}"]}, params, values, ["EXPR"]
279+
)
280+
assert int_range == [1, 7]
281+
assert float_range == [Decimal("1.5"), "2.50"]
282+
283+
def test_white_space_inside_the_number_does_not_coerce(self, tmp_path) -> None:
269284
error = _range_error(
270285
tmp_path,
271286
{"type": "INT", "range": [1, "{{Param.S}}"]},
272287
_STRING_S,
273-
{"S": " 7 "},
288+
{"S": "1 000"},
274289
["EXPR"],
275290
)
276291
assert error == _ELEMENT_1 + (

‎test/openjd/model_v1/test_create_job.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,39 @@ def test_a_value_that_is_not_an_integer_fails(self, value: str) -> None:
30193019
)
30203020

30213021

3022+
class TestRangeListElementsAsListItems:
3023+
"""With EXPR, a range list element that is exactly one expression is a list
3024+
item (Expression Language §1.3.2): a list it evaluates to flattens into one
3025+
element per member. Since openjd-model 0.15.0 (openjd-rs#486); before, a
3026+
FLOAT element resolved to text and failed to parse.
3027+
``test_range_list_items.py`` in model_v0 covers v0."""
3028+
3029+
def test_float_list_flattens(self) -> None:
3030+
decoded = decode_job_template(
3031+
template={
3032+
"specificationVersion": "jobtemplate-2023-09",
3033+
"extensions": ["EXPR"],
3034+
"name": "T",
3035+
"steps": [
3036+
{
3037+
"name": "S",
3038+
"parameterSpace": {
3039+
"taskParameterDefinitions": [
3040+
{"name": "X", "type": "FLOAT", "range": [1.5, "{{ [2, 2.5] }}"]}
3041+
]
3042+
},
3043+
"script": {"actions": {"onRun": {"command": "echo"}}},
3044+
}
3045+
],
3046+
},
3047+
supported_extensions=["EXPR"],
3048+
)
3049+
job = create_job(job_template=decoded, job_parameter_values={})
3050+
space = job.steps[0].parameterSpace
3051+
assert space is not None
3052+
assert space.taskParameterDefinitions["X"].range == [1.5, 2.0, 2.5]
3053+
3054+
30223055
def _preprocess(parameter_definitions: list[dict], values: dict, tmp_path: Path) -> dict:
30233056
"""Decode a one-step template with ``parameter_definitions`` (with EXPR, for
30243057
the list types) and return ``preprocess_job_parameters``' values as text."""

‎test/openjd/model_v1/test_known_gaps.py‎

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -137,80 +137,3 @@ def test_v0_range_string_renders_in_canonical_form(text: str, expected: str) ->
137137
from openjd.model._range_expr import IntRangeExpr
138138

139139
assert str(IntRangeExpr.from_str(text)) == expected
140-
141-
142-
# ── v1 rejects format string elements in INT range lists ──
143-
#
144-
# Template Schemas §3.4.1.1 allows a <TaskParameterStringValue> element in an
145-
# INT (and CHUNK[INT]) range list, and v0 accepts one. The bindings build
146-
# against openjd-model 0.13.0, whose `IntRange::List` holds integers only, so v1
147-
# fails to decode the template. The openjd-rs fix changes `IntRange::List` to
148-
# `Vec<IntOrFormatString>`; this resolves when the bindings move to an
149-
# openjd-model release with it, and `int_range_to_py` handles the new element
150-
# type. ``test_range_list_items.py`` in model_v0 covers the v0 behavior.
151-
152-
153-
@pytest.mark.xfail(strict=True, reason="bindings pin openjd-model 0.13.0 (IntRange::List of i64)")
154-
def test_v1_accepts_format_string_in_int_range_list() -> None:
155-
import openjd.model._v1 as v1
156-
157-
v1.decode_job_template(
158-
{
159-
"specificationVersion": "jobtemplate-2023-09",
160-
"name": "T",
161-
"parameterDefinitions": [{"name": "I", "type": "INT", "default": 10}],
162-
"steps": [
163-
{
164-
"name": "S",
165-
"parameterSpace": {
166-
"taskParameterDefinitions": [
167-
{"name": "X", "type": "INT", "range": [1, "{{Param.I}}"]}
168-
]
169-
},
170-
"script": {"actions": {"onRun": {"command": "echo"}}},
171-
}
172-
],
173-
}
174-
)
175-
176-
177-
# With EXPR, v0 resolves a FLOAT range list element as a list item (Expression
178-
# Language §1.3.2), so a list flattens. v1's openjd-model 0.13.0 resolves it to
179-
# text and fails to parse it. Same resolution as the test above.
180-
181-
182-
@pytest.mark.xfail(strict=True, reason="bindings pin openjd-model 0.13.0 (FLOAT elements as text)")
183-
def test_v1_flattens_list_in_float_range_list() -> None:
184-
from pathlib import Path
185-
186-
import openjd.model._v1 as v1
187-
188-
template = v1.decode_job_template(
189-
{
190-
"specificationVersion": "jobtemplate-2023-09",
191-
"extensions": ["EXPR"],
192-
"name": "T",
193-
"steps": [
194-
{
195-
"name": "S",
196-
"parameterSpace": {
197-
"taskParameterDefinitions": [
198-
{"name": "X", "type": "FLOAT", "range": [1.5, "{{ [2, 2.5] }}"]}
199-
]
200-
},
201-
"script": {"actions": {"onRun": {"command": "echo"}}},
202-
}
203-
],
204-
},
205-
supported_extensions=["EXPR"],
206-
)
207-
params = v1.preprocess_job_parameters(
208-
job_template=template,
209-
job_parameter_values={},
210-
job_template_dir=Path.cwd(),
211-
current_working_dir=Path.cwd(),
212-
)
213-
job = v1.create_job(job_template=template, job_parameter_values=params)
214-
space = job.steps[0].parameter_space
215-
assert space is not None
216-
assert len(space.task_parameter_definitions["X"].range) == 3

0 commit comments

Comments
 (0)