Commit eea9c0d
authored
Enhance
* test: Simplify BMP generation in `test_stream.py` by removing DPI calculation.
Removed GDI-based DPI calculation (`get_screen_dpi`, `_GetDeviceCaps`, etc.)
because the DPI was fixed to 0, eliminating the need to determine screen
resolution and thereby streamlining the BMP generation logic.
The `create_pixel_data` function was renamed to `create_24bit_pixel_data`.
It now exclusively generates 24-bit BGR pixel data with 0 DPI, ensuring
consistent bitmap output independent of system settings. This includes
the addition of row padding for 24-bit BMP format compliance.
* test: Use variables for width and height in `create_24bit_pixel_data` call.
In `test_stream.py`, within `test_ole_load_picture`, the `width` and
`height` arguments passed to the `create_24bit_pixel_data` function
were replaced from direct literals with dedicated variables. This change
enhances readability by explicitly naming the dimensions, improving
the clarity of the test's intent.
* test: Add `test_save_created_bitmap_picture` for OLE picture saving.
Introduces a new test case `test_save_created_bitmap_picture` in
`test_stream.py` to verify the saving of OLE picture objects created
from bitmaps.
* refactor: Use `get_dc` context manager in `test_save_created_bitmap_picture`.
Refactors the `test_save_created_bitmap_picture` in `test_stream.py` to
utilize the `get_dc` context manager for acquiring and releasing
device contexts. This change improves code readability and ensures
proper resource management within the test.
* refactor: Use `select_object` context manager for GDI object handling
Introduces a `select_object` context manager to encapsulate the selection and
restoration of GDI objects in a device context.
* refactor: Use `create_compatible_dc` context manager for GDI DC handling
Introduces a `create_compatible_dc` context manager to encapsulate the
creation and deletion of compatible device contexts.
* refactor: Use `create_image_rendering_dc` context manager for GDI rendering
Introduces a `create_image_rendering_dc` context manager to encapsulate
the creation and management of a device context for off-screen image
rendering. This refactors `test_ole_load_picture` to utilize the new
context manager, improving resource handling and test clarity.
* test: Add `test_load_from_buffer_stream` for OLE picture loading and saving.
Introduces a new test case `test_load_from_buffer_stream` in
`test_stream.py`. This test verifies the functionality of loading an OLE
picture from a `bytearray` stream, rendering it into a GDI device
context, and then saving it back to a stream, ensuring data integrity
throughout the process.
* fix: Ensure GDI operations are flushed before reading pixel data.
Introduces a call to `_GdiFlush()` after `pic.Render()` in
`test_load_from_buffer_stream` within `comtypes/test/test_stream.py`.
This ensures that all GDI drawing commands are executed and memory is
updated before attempting to read pixel data, preventing potential data
inconsistencies.
* refactor: Rename `test_ole_load_picture` to `test_load_from_handle_stream`.
Renames the test method `test_ole_load_picture` to
`test_load_from_handle_stream` in `comtypes/test/test_stream.py`. This
change provides a more descriptive and accurate name for the test,
reflecting its functionality of loading an OLE picture from a handle-
based stream.stdole.IPicture stream and bitmap handling tests. (#893)1 parent afc1fc5 commit eea9c0d
1 file changed
+322
-33
lines changed
0 commit comments