Skip to content

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Dec 29, 2025

Added test_ole_load_picture to validate the creation of a new stdole.IPicture object by passing a pre-filled IStream (containing bitmap data) to OleLoadPicture.
This test specifically ensures that CreateStreamOnHGlobal is invoked with a non-NULL hGlobal and fDeleteOnRelease set to False.

Imports `comtypes.gen.stdole` in `test_stream.py` and adds a new
test class `Test_Picture` with a placeholder test `test_ole_load_picture`.
This is a preliminary step to implement comprehensive testing for the
`stdole.IPicture` interface.
This includes setting its argument types and return type using `ctypes` to
allow for loading `stdole.IPicture` objects from a `IStream`.
Introduces a new function `create_pixel_data` in `test_stream.py` to
generate 32-bit BGRA BMP binary data. This utility function allows for
creating synthetic image data with specified dimensions, color, and DPI.
This test validates the loading of a `stdole.IPicture` object from a
stream containing bitmap data using `_OleLoadPicture`. It involves
Windows API calls for device context, global memory management,
and stream operations, ensuring the correct instantiation of the
`IPicture` interface.
…ting.

The `_create_stream` helper function in `test_stream.py` is refactored
to accept `handle` and `delete_on_release` parameters. This allows for
more controlled stream creation, particularly for testing scenarios
involving `stdole.IPicture` where the underlying global memory management
needs to be externalized.
A new `get_dc` context manager is added to `test_stream.py` to encapsulate
the acquisition and release of device contexts (DC) via `_GetDC` and
`_ReleaseDC`. This improves the test for `stdole.IPicture` by:

- Reducing the number of variables within the main test logic, enhancing
  readability.
- Separating setup (DC acquisition) and teardown (DC release) processes
  from the core test assertions, making the test cleaner and more
  maintainable.
…le.IPicture` testing.

Two new context managers, `global_alloc` and `global_lock`, are introduced
in `test_stream.py`. These encapsulate `_GlobalAlloc`/`_GlobalFree` and
`_GlobalLock`/`_GlobalUnlock` Windows API calls respectively.
…e` testing.

The logic for retrieving screen DPI is extracted into a new helper function,
`get_screen_dpi`, in `test_stream.py`. This function utilizes the
`get_dc` context manager to safely obtain and release the device context.
This is a direct validation of the `stdole.IPicture` interface's behavior.
@junkmd junkmd added this to the 1.4.15 milestone Dec 29, 2025
@junkmd junkmd self-assigned this Dec 29, 2025
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.16%. Comparing base (86d39f5) to head (d56f9c6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #892      +/-   ##
==========================================
+ Coverage   85.04%   85.16%   +0.12%     
==========================================
  Files         126      126              
  Lines       11728    11826      +98     
==========================================
+ Hits         9974    10072      +98     
  Misses       1754     1754              

☔ 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 removed their assignment Dec 29, 2025
@junkmd junkmd added the tests enhance or fix tests label Dec 29, 2025
@junkmd junkmd merged commit afc1fc5 into enthought:main Dec 29, 2025
101 of 103 checks passed
@junkmd junkmd deleted the stream_loadpicture branch December 29, 2025 11:47
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