Skip to content

test(label-file): cover the shape JSON codec directly - #2404

Merged
wkentaro merged 1 commit into
mainfrom
test/label-file-shape-codec
Aug 4, 2026
Merged

test(label-file): cover the shape JSON codec directly#2404
wkentaro merged 1 commit into
mainfrom
test/label-file-shape-codec

Conversation

@wkentaro

Copy link
Copy Markdown
Owner

The shape JSON codec (_load_shape_json_obj / _dump_shape_to_json_obj in
labelme/_label_file.py) was only exercised indirectly, through file-I/O-heavy
read_label_file / write_label_file round-trips. The malformed-field error
branches are already covered directly by
test_read_label_file_raises_on_malformed_shape_field, but the happy-path parse
contract was not: nothing asserted the optional-field defaults (description ->
"", group_id -> None, flags -> {}), unknown-key bucketing into
other_data, the falsy-but-valid group_id: 0 case, or the mask base64
encode/decode, so a regression in any default would pass the whole suite.

These direct unit tests pin that contract with no filesystem access, building
mask input via the production img_arr_to_b64 encoder rather than hand-rolled
base64.

Test plan

  • uv run pytest tests/unit/_label_file_test.py -q (56 passed)
  • uv run ruff check / ruff format --check / ty check on the file

@wkentaro wkentaro self-assigned this Jul 24, 2026
@wkentaro

Copy link
Copy Markdown
Owner Author

This was generated by AI during PR processing.

Verdict: recommend-merge

Test-only PR adding direct unit coverage of the shape JSON codec (_load_shape_json_obj / _dump_shape_to_json_obj).

  • Rebase: skipped. main advanced 4 commits since the merge-base, all in files disjoint from this PR (_config, its test, CHANGELOG.md), and merge state is CLEAN, so the existing green still reflects the merged result.
  • Review (/code-review, both axes): clean. Standards found no hard violations (plain test_ functions, full -> None annotations, fixture-backed, kwargs at call sites). Spec review confirmed every assertion faithfully matches the source behavior, including the non-obvious group_id=0 falsy-but-not-None branch and the lossless PNG mask round-trip. No passing-but-wrong assertions.
  • CI: all 11 checks green.

Minor, non-blocking: the codec's error branches (missing/mistyped fields) are exercised only indirectly via the pre-existing test_read_label_file_raises_on_malformed_shape_field, not directly against _load_shape_json_obj. Not worth blocking on.

@wkentaro wkentaro added the recommend-merge pr: Agent finalized and endorses it: review and merge label Jul 24, 2026
@wkentaro
wkentaro force-pushed the test/label-file-shape-codec branch from 9555772 to 632f877 Compare August 4, 2026 04:56
@wkentaro wkentaro added this to the next milestone Aug 4, 2026
@wkentaro
wkentaro merged commit 595fe1b into main Aug 4, 2026
12 checks passed
@wkentaro
wkentaro deleted the test/label-file-shape-codec branch August 4, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

recommend-merge pr: Agent finalized and endorses it: review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant