Skip to content

test: raise coverage of base/color.py from 67% to 88% - #219

Merged
petercorke merged 2 commits into
mainfrom
test/base-coverage-color
Nov 22, 2026
Merged

petercorke merged 2 commits into
mainfrom
test/base-coverage-color

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Last of the changes to bring every file in machinevisiontoolbox/base to at least 80% coverage. base/color.py goes from 67% to 88%, and the lowest file in base is now graphics.py at 84% (base overall: 82% to 88%).

Adds two test files:

  • tests/base/test_color_shadow.py tests shadow_invariant and esttheta on a synthetic image whose invariant angle is known: pixels of one material that are lit or in shadow differ only along one direction in the log-chromaticity plane, so projecting at the right angle gives one grey value everywhere, and esttheta must find that angle again (to its 0.02 rad search step). It covers the angle, exp, the green-channel denominator, sharpening, the default camera filters, bad input and zero pixels. Only the mouse clicks in esttheta are supplied.
  • tests/base/test_color_convertflag.py checks every colorspace name to OpenCV conversion code in _convertflag, including case, colons, aliases and the unsupported pairs, and the Lab chromaticity diagram background.

While writing these tests I found a bug, which is not fixed here: shadow_invariant(image, primaries=...) without θ raises UnboundLocalError, because the projection direction is only worked out when primaries is None. It is recorded as a strict xfail test, so the test that fixes it has to remove the marker.

Testing

pytest tests: 1640 passed, 33 skipped, 1 xfailed. ruff and mypy report no issues. Nothing is mocked except Figure.ginput in the esttheta tests. 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

Tests shadow_invariant and esttheta on a synthetic image whose invariant
angle is known, with only the mouse clicks supplied for esttheta; the
table of colorspace names to OpenCV conversion codes, including the
error cases; and the Lab chromaticity diagram background. With this every
file in machinevisiontoolbox/base is at least 84% covered.

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 30 complexity · 0 duplication

Metric Results
Complexity 30
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 62b2b22 into main Nov 22, 2026
32 checks passed
@petercorke
petercorke deleted the test/base-coverage-color branch November 22, 2026 06:53
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