Skip to content

Add unit test for surface.convert_alpha argument check (#599) - #3908

Open
sudeeps-projects wants to merge 2 commits into
pygame-community:mainfrom
sudeeps-projects:fix-issue-599
Open

Add unit test for surface.convert_alpha argument check (#599)#3908
sudeeps-projects wants to merge 2 commits into
pygame-community:mainfrom
sudeeps-projects:fix-issue-599

Conversation

@sudeeps-projects

Copy link
Copy Markdown

Hi! This PR adds an automated unit test to verify the behavior of surface.convert_alpha when passed an explicit surface argument. It ensures the framework safely processes the parameter format without crashing and behaves identically to an empty parameter call. Closes #599.

@sudeeps-projects
sudeeps-projects requested a review from a team as a code owner August 9, 2026 09:02
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b78a811a-ef7e-40ac-9380-b0fda1ce57b5

📥 Commits

Reviewing files that changed from the base of the PR and between 31d6b5b and 32a552a.

📒 Files selected for processing (1)
  • test/surface_test.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/surface_test.py

📝 Walkthrough

Walkthrough

The test suite adds regression coverage for Surface.convert_alpha(target_surface). It initializes a hidden display, suppresses the expected deprecation warning, compares surface formats and boundary pixels, and ensures display cleanup.

Changes

Surface alpha conversion

Layer / File(s) Summary
Target-surface conversion coverage
test/surface_test.py
Adds a test that compares target-surface conversion with default conversion. The test checks size, flags, bit depth, boundary pixels, warning handling, and display cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The linked issue concerns character origin coordinates, but this pull request tests surface.convert_alpha argument handling. Link the pull request to an issue about surface.convert_alpha, or update the implementation and tests to satisfy issue #599.
Out of Scope Changes check ⚠️ Warning The convert_alpha test is unrelated to the linked issue's character-origin requirements. Remove the unrelated test or provide a correctly scoped linked issue for the surface.convert_alpha behavior.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the added unit test and the surface.convert_alpha argument under test.
Description check ✅ Passed The description accurately explains the convert_alpha regression test and its expected behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
test/surface_test.py (1)

983-998: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Strengthen the regression assertion.

base_surf and target_surf use the same format. The assertions compare only size and flags. A regression that changes pixel data or incorrectly uses the target format can pass.

Use a target surface with a different format. Fill base_surf with non-default RGBA data. Compare pixel content and relevant format metadata between both results.

Suggested test improvement
             base_surf = pygame.Surface((10, 10), pygame.SRCALPHA)
-            target_surf = pygame.Surface((10, 10), pygame.SRCALPHA)
+            base_surf.fill((17, 34, 51, 127))
+            target_surf = pygame.Surface((10, 10), 0, 16)

             self.assertIsInstance(res_with_arg, pygame.Surface)
             self.assertEqual(res_no_arg.get_size(), res_with_arg.get_size())
             self.assertEqual(res_no_arg.get_flags(), res_with_arg.get_flags())
+            self.assertEqual(res_no_arg.get_bitsize(), res_with_arg.get_bitsize())
+            for point in ((0, 0), (9, 9)):
+                self.assertEqual(res_no_arg.get_at(point), res_with_arg.get_at(point))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/surface_test.py` around lines 983 - 998, Strengthen the convert_alpha
regression test around base_surf and target_surf by creating the target with a
different pixel format, filling base_surf with non-default RGBA data, and
comparing the resulting pixel content plus relevant format metadata. Retain the
existing size and flags checks and warning suppression, ensuring
convert_alpha(target_surf) matches the no-argument result rather than adopting
the target format or altering pixels.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/surface_test.py`:
- Around line 983-998: Strengthen the convert_alpha regression test around
base_surf and target_surf by creating the target with a different pixel format,
filling base_surf with non-default RGBA data, and comparing the resulting pixel
content plus relevant format metadata. Retain the existing size and flags checks
and warning suppression, ensuring convert_alpha(target_surf) matches the
no-argument result rather than adopting the target format or altering pixels.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b730f3b-1d5b-4316-bbce-9413df93d103

📥 Commits

Reviewing files that changed from the base of the PR and between d194055 and 31d6b5b.

📒 Files selected for processing (1)
  • test/surface_test.py

@sudeeps-projects

Copy link
Copy Markdown
Author

Hi, I have strengthened convert_alpha regression test assertions as per review

@shaurya-sharma-dev

Copy link
Copy Markdown
Contributor

Not a maintainer, but I think you have a typo in your PR description. Issue #599 is a completely unrelated issue that relates to pygame.font.Font, while your PR is dealing with pygame.Surface.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

how can i get each character's origin? (887)

2 participants