Skip to content

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Jan 23, 2026

Overview

This change introduces a new module, gdi_helper.py, to encapsulate Windows GDI (Graphics Device Interface) related helper functions and adds a new test for the IViewObject::Draw method.
This enhancement aims to robustly verify the drawing capabilities of COM objects.

Benefits

Improved Reliability for Visual COM Interactions

The addition of a dedicated test for the IViewObject::Draw method ensures that this project correctly wraps the drawing functionalities of COM objects..
This test uses a real COM object (InkEdit) and validates rendering results at the pixel data level, offering high confidence in practical accuracy.

Enhanced Modularity and Maintainability

Extracting GDI-related implementation details from test_stream.py into gdi_helper.py significantly improves code modularity and separation of concerns.
This makes the test code more concise, enhances the reusability of GDI-related logic across different test files, and improves the overall readability and maintainability of the codebase.
The refactoring of create_image_rendering_dc to utilize create_dib_section as an independent context manager further reduces nesting, making complex GDI resource setup easier to understand and extend.

Move GDI-related ctypes definitions from `test/test_stream.py` to a new
dedicated module, `test/gdi_helper.py`. This improves modularity and
reusability of GDI helper functions across tests.
Further enhance `test/gdi_helper.py` by introducing context managers (`get_dc`,
`create_compatible_dc`, `select_object`, `create_image_rendering_dc`) and
utility functions and constants (`create_24bitmap_info`, `BI_RGB`,
`DIB_RGB_COLORS`). These additions centralize GDI object management and
simplify off-screen rendering setup for tests.
Update type hints for `get_dc` and `create_compatible_dc` in
`test/gdi_helper.py` to explicitly accept `Optional[int]`.
Introduce `create_dib_section` as a dedicated context manager in
`test/gdi_helper.py` to handle the creation and destruction of DIB sections.
Refactor `create_image_rendering_dc` to utilize this new manager, reducing
nesting and improving readability. Additionally, update the return type hint
of `create_image_rendering_dc` to use `int` for the bitmap bits pointer
address, ensuring consistency with the handle types.
Introduce `test_Draw` in `test_viewobject.py` to validate the `Draw`
method of the `IViewObject` interface. This test creates an off-screen
rendering context using helpers from `gdi_helper.py`.

An `InkEdit` COM object is created, placed into a running state via
`OleRun`, and then instructed to draw itself onto the device context.
The test verifies the operation's success by asserting that the pixel
data in the resulting bitmap matches the color set on the object.
@junkmd junkmd added this to the 1.4.16 milestone Jan 23, 2026
@junkmd junkmd added the tests enhance or fix tests label Jan 23, 2026
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.45%. Comparing base (267e13d) to head (d8eaa1c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #911      +/-   ##
==========================================
+ Coverage   86.40%   86.45%   +0.04%     
==========================================
  Files         132      133       +1     
  Lines       12397    12428      +31     
==========================================
+ Hits        10712    10745      +33     
+ Misses       1685     1683       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd junkmd merged commit 526af9a into enthought:main Jan 23, 2026
52 checks passed
@junkmd junkmd deleted the viewobj_more_tests branch January 23, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant