Skip to content

test: cover docling-tools CLI, profiling and debug visualization - #4046

Open
dolfim-ibm wants to merge 3 commits into
mainfrom
coverage/p1-debug-and-cli
Open

test: cover docling-tools CLI, profiling and debug visualization#4046
dolfim-ibm wants to merge 3 commits into
mainfrom
coverage/p1-debug-and-cli

Conversation

@dolfim-ibm

Copy link
Copy Markdown
Member

Second iteration of the coverage work started in #4044. Targets three modules that had no test reaching them at all, and fixes one bug the new tests surfaced.

Coverage

Measured in the core lane with --cov-branch:

module line branch
utils/visualization.py 12.7% → 100% 100%
utils/profiling.py 37.4% → 99.2% 97.2%
cli/models.py never imported → 88.0% 96.2%
cli/tools.py 0% → 39.1% → 50%

cli/tools.py cannot go much higher: 14 of its 21 statements are an ImportError fallback that only runs when typer is absent, which never happens in CI.

Why these were dark

  • utils/profiling.py and utils/visualization.py sit behind settings.debug.* flags that default to False, and no test enables them.
  • docling-tools (cli/tools.pycli/models.py) was never imported by any test in the core lane.

The fix

docling-tools models download-hf-repo --quiet printed a per-repo progress line even though --quiet documents "no extra output is generated, the CLI prints only the directory with the cached models". The sibling download command already behaved correctly, so quiet output could not be consumed as a plain path.

Approach

The CLI tests replace the downloader entry points with recorders and assert which model selection the CLI derives from a given set of flags — the option-plumbing contract — rather than asserting on the calls themselves. No model is downloaded.

The visualization tests render synthetic clusters onto a real page image and assert on resulting pixels, the region-label split between the two halves, scale factors, inverted-box normalisation, and the debug output paths. The profiling tests drive the TimeIntervalRecorder state machine and its error paths in both the enabled and disabled states.

Notes

  • Two commits: the fix: ships via semantic-release, the test: commit does not.
  • No pyproject.toml or uv.lock changes.

🤖 Generated with Claude Code

dolfim-ibm and others added 2 commits August 21, 2026 17:12
The --quiet flag documents that "no extra output is generated, the CLI
prints only the directory with the cached models", and the sibling
`download` command behaves that way. `download-hf-repo` printed a
per-repo progress line regardless, so its quiet output could not be
consumed as a plain path.

Adds tests for the `docling-tools models` option surface, which had no
coverage at all: the downloaders are replaced with recorders so the tests
assert which model selection the CLI derives from a given set of flags,
rather than asserting on the calls themselves.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
Both modules sit behind settings.debug flags that no test enables, so
neither was exercised: utils/profiling.py at 37% and
utils/visualization.py at 13% line coverage.

The profiling tests drive the TimeIntervalRecorder state machine and its
error paths in both the enabled and disabled states. The visualization
tests render synthetic clusters onto a real page image and assert on the
resulting pixels, the region-label split between the two halves, and the
debug output paths.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @dolfim-ibm, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The CLI tests normalised Rich's box drawing and line wrapping but not its
colour codes. Rich only emits those when the output stream is a terminal,
so the tests passed locally and failed under CI, where an escape sequence
lands between the wrapped halves of the message and keeps the expected
phrase from ever matching:

    requires the 'easyocr' \x1b[31m \x1b[0m \x1b[31m \x1b[0m model

Strips the escapes before collapsing whitespace, and routes the offline
usage hint through the same helper -- it wraps for the same reason.
Verified with colour forced on at 80 and 50 columns as well as with
colour off.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
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