|
1 | | -"""Verify backend listing works against the real API.""" |
| 1 | +"""Integration tests for backend endpoints.""" |
| 2 | + |
| 3 | +import warnings |
2 | 4 |
|
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from ionq_core import Client |
6 | | -from ionq_core.api.backends import get_backends |
| 8 | +from ionq_core.api.backends import get_backend, get_backends |
7 | 9 |
|
8 | 10 | pytestmark = pytest.mark.integration |
9 | 11 |
|
| 12 | +BASE_URL = "https://api.ionq.co/v0.4" |
| 13 | + |
| 14 | + |
| 15 | +def _unauthenticated(): |
| 16 | + """Unauthenticated client (no managed transport, may leak sockets).""" |
| 17 | + return Client(base_url=BASE_URL) |
| 18 | + |
| 19 | + |
| 20 | +class TestListBackends: |
| 21 | + def test_returns_backends(self): |
| 22 | + with warnings.catch_warnings(): |
| 23 | + warnings.simplefilter("ignore", ResourceWarning) |
| 24 | + backends = get_backends.sync(client=_unauthenticated()) |
| 25 | + assert backends is not None |
| 26 | + assert len(backends) > 0 |
| 27 | + |
| 28 | + def test_has_qpu(self): |
| 29 | + with warnings.catch_warnings(): |
| 30 | + warnings.simplefilter("ignore", ResourceWarning) |
| 31 | + backends = get_backends.sync(client=_unauthenticated()) |
| 32 | + names = [b.backend for b in backends] |
| 33 | + assert any("qpu" in n for n in names) |
| 34 | + |
| 35 | + def test_backend_fields(self): |
| 36 | + with warnings.catch_warnings(): |
| 37 | + warnings.simplefilter("ignore", ResourceWarning) |
| 38 | + backends = get_backends.sync(client=_unauthenticated()) |
| 39 | + for b in backends: |
| 40 | + assert b.backend |
| 41 | + assert b.status |
| 42 | + assert b.qubits > 0 |
| 43 | + assert b.average_queue_time is not None |
| 44 | + assert b.last_updated |
| 45 | + |
10 | 46 |
|
11 | | -def test_list_backends(): |
12 | | - """Backends endpoint is unauthenticated - use a plain Client.""" |
13 | | - unauthenticated = Client(base_url="https://api.ionq.co/v0.4") |
14 | | - backends = get_backends.sync(client=unauthenticated) |
15 | | - assert backends is not None |
16 | | - assert len(backends) > 0 |
17 | | - names = [b.backend for b in backends] |
18 | | - assert any("qpu" in n for n in names), f"Expected at least one QPU backend in {names}" |
| 47 | +class TestGetBackend: |
| 48 | + def test_get_qpu(self, client): |
| 49 | + backend = get_backend.sync("qpu.forte-1", client=client) |
| 50 | + assert backend is not None |
| 51 | + assert backend.backend == "qpu.forte-1" |
| 52 | + assert backend.qubits > 0 |
0 commit comments