-
Notifications
You must be signed in to change notification settings - Fork 23
Add test for enum-based overload resolution #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add test coverage to verify that overloaded methods with different enum parameter types dispatch correctly. This confirms that the existing scoped enum handling already supports overload resolution via isinstance() type checks. Changes: - Add overloaded process(MyEnum) and process(MyEnum2) to enums.hpp - Declare process methods in enums.pxd - Add tests verifying correct dispatch and rejection of wrong enum types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds test cases and implementation for enum overload resolution. Introduces overloaded Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/test_code_generator.py (1)
121-123: Use a more specific exception type instead of bareException.Catching bare
Exceptioncan mask unexpected errors. Based on Test 4 (line 110), autowrap appears to raiseAssertionErrorfor type validation failures. Consider usingpytest.raises(AssertionError)or verify the actual exception type raised when no overload matches.🔎 Verify the actual exception type raised
Run this test to determine the specific exception:
# Temporarily modify test to capture exception try: foo.process(mod.Foo2.MyEnum.A) assert False, "Expected exception was not raised" except Exception as e: print(f"Exception type: {type(e).__name__}, Message: {e}") raiseThen update the test to use the specific exception type:
- with pytest.raises(Exception): + with pytest.raises(AssertionError): # or TypeError, depending on actual behavior foo.process(mod.Foo2.MyEnum.A)
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tests/test_code_generator.pytests/test_files/enums.hpptests/test_files/enums.pxd
🧰 Additional context used
🪛 Ruff (0.14.10)
tests/test_code_generator.py
122-122: Do not assert blind exception: Exception
(B017)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: test (==3.1.0, 3.13)
- GitHub Check: test (==3.1.0, 3.10)
- GitHub Check: test (==3.1.0, 3.11)
- GitHub Check: test (==3.2.0, 3.10)
- GitHub Check: test (==3.2.0, 3.11)
- GitHub Check: test (==3.2.0, 3.12)
- GitHub Check: test (==3.2.0, 3.13)
- GitHub Check: test (==3.1.0, 3.12)
🔇 Additional comments (3)
tests/test_code_generator.py (1)
113-119: LGTM! Overload resolution test correctly validates enum-based dispatch.The test correctly verifies that the overloaded
process()methods dispatch to the appropriate implementation based on the enum type passed, confirming the core functionality described in PR #234.tests/test_files/enums.hpp (1)
18-18: LGTM! Clean implementation of enum-based overload resolution.The addition of
#include <string>and the two overloadedprocess()methods correctly demonstrate C++ overload resolution based on enum type. The return values match the test expectations.Also applies to: 48-52
tests/test_files/enums.pxd (1)
2-2: LGTM! Cython declarations correctly map the C++ overloads.The import of
libcpp.stringand the declarations of the two overloadedprocess()methods properly expose the C++ functionality to Python, enabling enum-based overload resolution.Also applies to: 48-50
|
hmm seems to work right? |
|
Yes looks correct |
Summary
isinstance()type checksChanges
process(MyEnum)andprocess(MyEnum2)methods toenums.hppenums.pxdTest plan
pytest tests/test_code_generator.py::test_enums -vpassespytest tests/test_code_generator.py::test_enum_class_forward_declaration -vpassesFixes #233
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
New Features
✏️ Tip: You can customize this high-level summary in your review settings.