Commit 144a0c0
authored
Expand integration tests, fix transport response reading bug (#10)
* Reapply "Expand integration tests, fix transport response reading bug"
This reverts commit edf974f.
* Address review: fix async transport, simplify tests
Transport:
- Move response.read()/aread() before _should_retry so exhausted
retries also have a read body for error parsing
- Add await response.aread() in async transport (was sync-only)
- Remove response.read() from _parse_error_body (caller's job)
Tests:
- Consolidate redundant API calls via shared fixtures
- Fix session tests: status() returns a string, not Session object
- Actually test context manager protocol with `with` statement
- Use itertools.islice instead of zip(range())
- Remove redundant warnings.catch_warnings blocks (conftest handles it)
- Extract _submit() helper for repeated job creation
- Add docstring explaining why async_client fixture exists separately
* Simplify integration tests: flatten classes, use fixtures
- Flatten TestListBackends into plain functions with a shared fixture
- Flatten single-test classes (cancel, delete, estimate, poll)
- Add assert to _submit helper for clearer failures
- Use context manager in test_session_lifecycle instead of manual cleanup
* Polish: scope fixtures, deduplicate submit helper, drop redundant test
- scope="module" on backends fixture (1 API call instead of 3)
- scope="class" on completed_job_id fixture (1 call instead of 3)
- _submit accepts **overrides, simplifying dry_run test
- Remove test_session_context_manager (covered by test_session_lifecycle)
* Add comment on unauthenticated fixture, fix trailing blank line
* Scope warning suppression to fixture, add track_job to delete test
- Move SSL warning filters from module-level to session-scoped
autouse fixture so they don't leak into unit test collection
- Add track_job to test_delete_job for cleanup if delete fails
* style: fix ruff formatting in integration conftest
Add missing blank line between fixture and module-level variable.
* feat: add optional-dependencies alongside dependency-groups for pip compat
pip install -e '.[dev]' only works with [project.optional-dependencies],
not [dependency-groups] (PEP 735). Add the dev extra so both pip and uv
workflows work. This matches the pattern used by pypa/build.
* refactor: simplify pagination and client factory
Extract _paginate/_apaginate helpers to eliminate duplicated cursor-
following logic across 4 pagination functions. Extract _ext() helper
in IonQClient to consolidate the repeated extension-or-default
precedence pattern and group sync/async transport chain construction.
Net reduction: ~25 lines with improved readability.
* refactor: replace misleading _ext() helper and simplify session settings
Replace the _ext() closure in IonQClient with direct attribute access.
The closure's docstring claimed extension-or-default precedence, but its
implementation couldn't actually resolve extension attributes when a
default was provided.
Change _build_settings() to return UNSET instead of None, matching the
auto-generated model's field type and eliminating conditional dict-splat
at both sync and async call sites.
* refactor: replace hand-written retry transport with httpx-retries
Replace the custom RetryTransport/AsyncRetryTransport (192 lines) with
httpx-retries, a lightweight library (8.9kB) that provides the same
retry logic out of the box: exponential backoff, jitter, Retry-After
header support, status code filtering, and idempotent method awareness.
What changed:
- _transport.py: Remove 7 helper functions and 2 transport classes,
replace with build_retry/build_sync_transport/build_async_transport
that configure httpx-retries, plus thin ErrorRaisingTransport that
converts error responses to structured IonQ exceptions.
- _extensions.py: Switch ClientExtension from stdlib dataclasses to
attrs for consistency with the rest of the codebase.
- ionq_client.py: Use new transport builder functions.
Hand-written code reduced from 1,130 to 1,058 lines (-72).
All 221 tests pass with 100% branch coverage.
* refactor: merge sync/async transport pairs, inline helpers, trim imports
Merge ErrorRaisingTransport/AsyncErrorRaisingTransport into a single
dual-inheritance class (same pattern httpx-retries uses). Do the same
for HookTransport, _ErrorMapperTransport, and their async counterparts.
Also inline _parse_error_body and _parse_retry_after into
_raise_for_response, remove unused future annotations imports, unify
build_sync_transport/build_async_transport into build_transport, and
trim docstrings to essential content.
Hand-written code: 1058 -> 966 lines (-92, -8.7%).
All 220 tests pass with 100% branch coverage.
* fix: use Any type for transport field to satisfy ty checker
* refactor: unify build_transport into single call
RetryTransport(retry=retry) with no explicit inner transport auto-
creates both sync and async transports internally (per httpx-retries
docs). Remove the async_ parameter and build a single transport that
serves both the sync Client and AsyncClient.
Hand-written code: 968 -> 965 lines.
* refactor: replace Any with DualTransport Protocol, remove future annotations
Replace typing.Any on the transport parameter with a proper Protocol
that defines both sync and async transport interfaces. Move
ErrorRaisingTransport above build_transport to eliminate the forward
reference, removing the need for from __future__ import annotations.
The remaining files (_session.py, _pagination.py, _polling.py) keep
from __future__ import annotations because they use TYPE_CHECKING
guards to avoid circular imports - the correct pattern for Python
3.12-3.13 per PEP 563/749.
* refactor: simplify hand-written code and deduplicate test helpers
- Remove redundant Retry() params (respect_retry_after_header, allowed_methods)
that matched library defaults
- Use @attrs.frozen shorthand instead of @attrs.define(frozen=True)
- Inline _build_user_agent and use ClientExtension() default to simplify
IonQClient transport chain setup
- Merge sync/async test transport classes using dual-inheritance pattern
- Extract shared make_job_json() helper to conftest, replacing duplicated
20+ line job JSON builders in test_polling and test_pagination
* chore: upgrade dev dependency floors and lock to latest versions
Bump dev dependency floors to match actual major versions in use:
- pytest >=8 -> >=9 (required by pytest-httpx >=0.36)
- pytest-httpx >=0.35 -> >=0.36
- pytest-asyncio >=0.25 -> >=1
- pytest-cov >=6 -> >=7
- ruff >=0.9 -> >=0.15
Lock file upgraded:
- certifi 2026.2.25 -> 2026.4.22
- idna 3.11 -> 3.13
- packaging 26.0 -> 26.1
- pytest-httpx 0.36.0 -> 0.36.2
- ruff 0.15.9 -> 0.15.11
- ty 0.0.29 -> 0.0.32
* fix: handle max_retries=0 correctly and clean up test/config hygiene
- Fix bug where ClientExtension(max_retries=0) was silently ignored
because Python's `or` operator treats 0 as falsy, falling through
to DEFAULT_MAX_RETRIES. Use explicit `is not None` checks instead.
- Remove duplicate [project.optional-dependencies] dev section that
mirrored [dependency-groups] dev; CI uses `uv sync` which reads
dependency-groups.
- Add asyncio_default_fixture_loop_scope to silence pytest-asyncio
deprecation warning about unset default scope.
- Replace 50-iteration response registration loops with pytest-httpx
is_reusable=True in polling timeout tests.
- Remove 11 unnecessary assert_all_responses_were_requested=False
markers from tests where the single registered response is always
consumed.
- Fix pre-existing ruff format violation in build_transport().1 parent edf974f commit 144a0c0
26 files changed
Lines changed: 761 additions & 896 deletions
File tree
- ionq_core
- tests
- integration
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
| |||
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
89 | | - | |
90 | 87 | | |
91 | 88 | | |
92 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 1 | + | |
18 | 2 | | |
19 | 3 | | |
20 | 4 | | |
21 | | - | |
22 | 5 | | |
23 | 6 | | |
| 7 | + | |
24 | 8 | | |
25 | 9 | | |
26 | 10 | | |
27 | 11 | | |
28 | 12 | | |
29 | 13 | | |
30 | 14 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 15 | + | |
41 | 16 | | |
42 | 17 | | |
43 | 18 | | |
| |||
51 | 26 | | |
52 | 27 | | |
53 | 28 | | |
54 | | - | |
| 29 | + | |
55 | 30 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 31 | + | |
64 | 32 | | |
65 | 33 | | |
66 | | - | |
| 34 | + | |
67 | 35 | | |
68 | 36 | | |
69 | 37 | | |
70 | 38 | | |
71 | 39 | | |
72 | 40 | | |
73 | 41 | | |
74 | | - | |
| 42 | + | |
75 | 43 | | |
76 | 44 | | |
77 | 45 | | |
| |||
101 | 69 | | |
102 | 70 | | |
103 | 71 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 72 | + | |
| 73 | + | |
111 | 74 | | |
112 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
113 | 83 | | |
114 | 84 | | |
115 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
116 | 93 | | |
117 | 94 | | |
118 | 95 | | |
119 | 96 | | |
120 | 97 | | |
121 | 98 | | |
122 | 99 | | |
| 100 | + | |
123 | 101 | | |
124 | 102 | | |
125 | 103 | | |
126 | 104 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | 105 | | |
142 | 106 | | |
143 | 107 | | |
144 | 108 | | |
145 | 109 | | |
146 | 110 | | |
| 111 | + | |
147 | 112 | | |
148 | 113 | | |
149 | 114 | | |
150 | 115 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | 116 | | |
172 | 117 | | |
173 | 118 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | 119 | | |
192 | 120 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
0 commit comments