-
Notifications
You must be signed in to change notification settings - Fork 268
feat(python): Add wire tests #10760
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
Open
tjb9dc
wants to merge
13
commits into
main
Choose a base branch
from
tb/python-wire-testss
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(python): Add wire tests #10760
+1,833
−38
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds pytest-based wire test generation that validates SDK methods against WireMock. Each test creates a client, makes an API call, and verifies the request was properly sent. - Implements generateServiceTestFile() with autouse fixture for test setup - Generates helper functions for WireMock interaction (reset, verify) - Creates test functions for each endpoint with examples - Adds enable_wire_tests config option to both Python v1 and v2 - Includes seed test fixtures for exhaustive validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Wire test files were missing imports for pytest, requests, typing, and the generated client. This was because: - The Python AST only supports "from X import Y" style imports - References with empty modulePath are skipped by the import generator - Simple "import X" statements need to be added as raw code blocks Solution: - Added raw code blocks for pytest and requests imports - Used reference tracking for typing and client imports - Created helper to register references for AST-managed imports All test files now have complete import statements at the top. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…type issues Fixed mypy errors in wire tests by: - Adding types-requests as dev dependency only when enable_wire_tests is true - Properly typing request_body as Dict[str, Any] to handle nested dicts - Converting JSON boolean 'true/false' to Python 'True/False' in test data - Added jsonToPython() helper to properly convert JSON to Python syntax Implementation: - Plumbed enable_wire_tests flag through Project -> PyProjectToml -> DependenciesBlock - Conditionally adds types-requests = "^2.31.0" only when wire tests are enabled - Fixed formatValue() to handle booleans correctly (True/False not true/false) - Added proper type annotations for all variables 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Fixed two issues in generated wire tests:
1. Import path: Changed from `from seed.exhaustive import SeedExhaustive`
to `from seed import SeedExhaustive` (correct module path)
2. Service access: Now properly navigates service hierarchy
(e.g., `client.endpoints.container.method()` instead of `client.method()`)
Implementation:
- Updated getClientModulePath() to return just [organization] instead of [org, workspace]
- Added service parameter to test generation functions
- Build service path from service.name.fernFilepath.allParts using snake_case
- Construct proper client accessor path: "client.{servicePath}.{methodName}()"
Examples of generated paths:
- Top-level service: client.no_auth.post_with_no_auth()
- Nested service: client.endpoints.container.get_and_return_list_of_primitives()
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Wire tests import and use the requests library to communicate with WireMock's admin API for resetting request journals and verifying request counts. Previously only added types-requests (type stubs), but need the actual library too. Changed: Added `requests = "^2.31.0"` alongside `types-requests = "^2.31.0"` in dev dependencies when enable_wire_tests is true. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Added automatic Docker container management using docker-compose healthchecks and pytest session fixtures. **docker-compose.test.yml**: - Added healthcheck that tests WireMock admin health endpoint - Checks every 2s with 15 retries (30s total wait time) - 5s start period before first health check **conftest.py**: - Session-scoped pytest fixture manages container lifecycle - Uses `docker compose up -d --wait` to wait for healthcheck to pass - Automatically starts WireMock before any tests run - Cleans up container with `docker compose down -v` after all tests complete - Proper error handling with stderr output This eliminates manual polling and ensures WireMock is fully ready before tests begin. Docker handles all the retry logic and timeout management. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…decorators Fixes wire test generation to properly map request parameters and headers: - Remove @pytest.mark.asyncio decorators from synchronous test functions - Use IR property definitions to map wire names to SDK parameter names (e.g., uuid -> uuid_, base64 -> base_64) - Distinguish between flattened object types and single request parameters - Add header parameter support with proper name conversion (X-TEST-HEADER -> x_test_header) - Use discriminated union visitor pattern for request body types All 49 wire tests now pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
…e tests Updates the Python seed Dockerfile to use docker:dind base image: - Enables wire tests to spin up WireMock containers via docker compose - Follows same pattern as Go seed Dockerfile - Installs Python 3.12, Poetry, Node.js on Alpine Linux - Starts dockerd in background via entrypoint script 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
570bdfa to
a75fe93
Compare
b8d3f5b to
a75fe93
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Very initial version of wire tests in python behind a feature flag. Utilizes the wiremock approach to testing. Enabled for the exhaustive no-custom-config feature.
Needs some reworking on how we are utilizing examples.