Visitar URL original
Add fetch_pixel(s) method to window for unit testing. · Issue #2473 · pythonarcade/arcade · GitHub
Skip to content

Add fetch_pixel(s) method to window for unit testing. #2473

Description

@DragonMoffon

We currently don't have a concrete way to do pixel testing for unit tests. get_image doesn't play nice with the spoof window. It would hopefully be performant, but it doesn't need to be as aggressively optimized as an official screenshot interface.

Activity

  1. added this to the Future milestone on Dec 17, 2024
  2. einarf commented on Dec 19, 2024

    @einarf
    Member

    I started on this a while ago ..

  3. pushfoo commented on Mar 1, 2025

    @pushfoo
    Member

    I have the following questions:

    • What does "spoof window" mean here? @DragonMoffon
    • Are our windows always assumed to be RGBA buffers?
    • Will all render targets be assumed to be RGBA buffers as well?
    • @einarf When you said "I started on this", did you mean the files below?

    The arcade.screenshot functions

    This file has commits from einarf in June and August of 2024, and two functions:

    def get_pixel(x: int, y: int, components: int = 3) -> tuple[int, ...]:

    def get_image(

    Offscreen in the top-level conftest.py

    This class:

    • is exposed as a top-level test fixture available in all tests via offscreen
    • was created in August of 2024 by einarf before further work by Eruvanos

    It has the following methods of interest

    def get_image(self) -> PIL.Image.Image:

    def read_pixel(self, x, y, components=3) -> tuple[int, int, int, int] | tuple[int, int, int]:

    def read_region(self, rect: Rect) -> list[tuple[int, int, int, int]]:

    def read_region_bytes(self, rect: Rect, components=3) -> bytes:

    def read_region_image(self, rect: Rect, components=3) -> PIL.Image.Image:

  4. self-assigned this
    on Mar 29, 2025
  5. pvcraven commented on Oct 9, 2026

    @pvcraven
    Member

    Closing this, since pixel testing works in unit tests now:

    • arcade.get_pixel() and arcade.get_image() work with the test window. tests/unit/test_screenshot.py tests both, tests/unit/draw/test_drawing_primitives.py checks blended colors with get_pixel, and the reference-scene tests in tests/unit/rendering call get_image().
    • The offscreen fixture in tests/conftest.py has read_pixel, read_region, read_region_image and assert_images_almost_equal. read_pixel and read_region used to decode the bytes wrongly; Fix rand_vec_spread_deg directions, large GL reads, and pixel test helpers #2945 fixed them and added tests/unit/test_offscreen_fixture.py.

    A Window method would do the same thing as arcade.get_pixel(x, y), which already reads from the current window, so we're not adding one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

testsEverything related to testing

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions