Skip to content

test: raise coverage of ImageIO from 55% to 88% and ImageTensor from 76% to 90% - #222

Merged
petercorke merged 1 commit into
mainfrom
test/image-coverage-io-tensor
Nov 22, 2026
Merged

petercorke merged 1 commit into
mainfrom
test/image-coverage-io-tensor

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

First of three changes lifting coverage of the last Image*.py modules. ImageIO.py goes from 55% to 88% and ImageTensor.py from 76% to 90%.

The tests are in two new files, tests/test_image_io_extra.py and tests/test_image_tensor_extra.py. They use synthetic images, files in a temporary folder with known EXIF values, and simulated mouse events, so the expected answers are exact:

  • Image.Read: the alpha and rgb options, the color order, the argument check, and a wildcard.
  • metadata: JPEGs written with known EXIF tags, so int, text, text that holds a number, and float values each come back as the right type.
  • showpixels and showwindow: the label at each pixel for int, float and bool images, NaN pixels, the grid, colormaps, and the window moving over the image and returning its pixels.
  • disp with an image domain, anaglyph with each disparity sign, and stdisp.
  • tensor and Image.Tensor: the ImageNet and custom normalisation, dictionary input, the type and batch errors, and the error when PyTorch is missing.

Three bugs found while writing these are recorded as strict xfail tests, not fixed here, so whoever fixes one has to remove its marker:

  1. Image.Read with a wildcard that matches files raises a bare AssertionError, not its own ValueError("wildcard read not supported"). iread returns (images, paths) for a wildcard, which Image.Read takes for one image.
  2. stdisp: clicking in the left image raises RuntimeError: y must be a sequence, because the click handler passes scalars to Line2D.set_xdata and set_ydata, which Matplotlib 3.11 refuses.
  3. stdisp keeps its cursor only in a local variable, and Matplotlib holds callbacks weakly, so where plt.show(block=True) returns at once (a notebook, or a non-interactive backend) the clicks do nothing.

Testing

pytest tests: 1800 passed, 33 skipped, 9 xfailed. black, ruff check and mypy report no issues. The only stand-in is for the native file-chooser dialogue in Image.Read() and for plt.show(block=True) in the stdisp test, which plays the part of the user clicking. The tensor tests are skipped where PyTorch is not installed. Not run: CI on Windows or OpenCV 4 (CI will).

This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.

🤖 Generated with Claude Code

…76% to 90%

The tests use synthetic images, temporary files with known EXIF values, and
simulated mouse events. The only stand-in is for the native file-chooser
dialogue in Image.Read().

Three bugs are recorded as strict xfail tests: Image.Read() with a wildcard that
matches files raises a bare AssertionError, the stdisp click handler passes
scalars to Line2D.set_xdata which Matplotlib 3.11 refuses, and stdisp keeps its
cursor only in a local variable so it is lost when show() does not block.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 72 complexity · 0 duplication

Metric Results
Complexity 72
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit b4f03e5 into main Nov 22, 2026
32 checks passed
@petercorke
petercorke deleted the test/image-coverage-io-tensor branch November 22, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant