Skip to content

Commit b433d8f

Browse files
authored
test: add tests for new intrinsic field name (#988)
Assisted-by: CLAUDE:OPUS Signed-off-by: Jake LoRocco <jake.lorocco@ibm.com>
1 parent 0f95f84 commit b433d8f

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

test/formatters/granite/test_intrinsics_formatters.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,66 @@ def test_read_yaml():
405405
IntrinsicsRewriter(config_file=local_path)
406406

407407

408+
def test_name_field_accepted_by_make_config_dict():
409+
"""make_config_dict accepts 'name' as an optional field without error."""
410+
config_with_name = {
411+
"model": None,
412+
"response_format": None,
413+
"transformations": None,
414+
"name": "my_intrinsic_display_name",
415+
}
416+
result = intrinsics_util.make_config_dict(config_dict=config_with_name)
417+
assert result is not None
418+
assert result["name"] == "my_intrinsic_display_name"
419+
# Other optional fields are filled with None
420+
assert result["parameters"] is None
421+
assert result["sentence_boundaries"] is None
422+
assert result["instruction"] is None
423+
424+
# Without name, it defaults to None
425+
config_without_name = {
426+
"model": None,
427+
"response_format": None,
428+
"transformations": None,
429+
}
430+
result2 = intrinsics_util.make_config_dict(config_dict=config_without_name)
431+
assert result2 is not None
432+
assert result2["name"] is None
433+
434+
435+
def test_rewriter_transform_with_name_field():
436+
"""IntrinsicsRewriter.transform() produces identical output with or without 'name'."""
437+
config_with_name = {
438+
"model": None,
439+
"response_format": None,
440+
"transformations": None,
441+
"name": "answerability_v2",
442+
"parameters": {"max_completion_tokens": 64},
443+
"sentence_boundaries": None,
444+
"instruction": None,
445+
}
446+
config_without_name = {
447+
"model": None,
448+
"response_format": None,
449+
"transformations": None,
450+
"parameters": {"max_completion_tokens": 64},
451+
"sentence_boundaries": None,
452+
"instruction": None,
453+
}
454+
455+
rewriter_with = IntrinsicsRewriter(config_dict=config_with_name)
456+
rewriter_without = IntrinsicsRewriter(config_dict=config_without_name)
457+
458+
json_data = _read_file(_INPUT_JSON_DIR / "simple.json")
459+
before = ChatCompletion.model_validate_json(json_data)
460+
461+
after_with = rewriter_with.transform(before)
462+
after_without = rewriter_without.transform(before)
463+
464+
# Both should produce identical output (name is metadata-only)
465+
assert after_with.model_dump_json() == after_without.model_dump_json()
466+
467+
408468
_CANNED_INPUT_EXPECTED_DIR = _TEST_DATA_DIR / "test_canned_input"
409469

410470

0 commit comments

Comments
 (0)