Introduce GDI test helper module and test IViewObject.Draw.#911
Merged
junkmd merged 5 commits intoenthought:mainfrom Jan 23, 2026
Merged
Introduce GDI test helper module and test IViewObject.Draw.#911junkmd merged 5 commits intoenthought:mainfrom
IViewObject.Draw.#911junkmd merged 5 commits intoenthought:mainfrom
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theIViewObject::Drawmethod.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::Drawmethod 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.pyintogdi_helper.pysignificantly 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_dcto utilizecreate_dib_sectionas an independent context manager further reduces nesting, making complex GDI resource setup easier to understand and extend.