diff --git a/qiskit_quantuminspire/qi_jobs.py b/qiskit_quantuminspire/qi_jobs.py index f82fd50..81555e0 100644 --- a/qiskit_quantuminspire/qi_jobs.py +++ b/qiskit_quantuminspire/qi_jobs.py @@ -16,7 +16,9 @@ class CircuitExecutionData: """Class for bookkeping of individual jobs.""" - def __init__(self, circuit: QuantumCircuit, job_id: int = None, results: List[RawJobResult] = None) -> None: + def __init__( + self, circuit: QuantumCircuit, job_id: Union[int, None] = None, results: Union[List[RawJobResult], None] = None + ) -> None: self.job_id = job_id self.circuit = circuit self.results = [] if results is None else results @@ -77,7 +79,7 @@ async def _fetch_job_results(self) -> None: for circuit_data, result_item in zip(self.circuits_run_data, result_items): circuit_data.results = result_item - + def result(self) -> Result: """Return the results of the job.""" if not self.done(): diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..409e1ea --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ +from unittest.mock import AsyncMock + +import pytest +from pytest_mock import MockFixture + +from qiskit_quantuminspire.api.pagination import PageReader + + +@pytest.fixture +def page_reader_mock(mocker: MockFixture) -> AsyncMock: + # Simply calling mocker.patch() doesn't work because PageReader is a generic class + page_reader_mock = AsyncMock() + page_reader_mock.get_all = AsyncMock() + mocker.patch.object(PageReader, "get_all", page_reader_mock.get_all) + return page_reader_mock \ No newline at end of file diff --git a/tests/test_jobs.py b/tests/test_jobs.py index 01ba870..478a913 100644 --- a/tests/test_jobs.py +++ b/tests/test_jobs.py @@ -48,7 +48,7 @@ def test_result_raises_error_when_status_not_done(mocker: MockerFixture) -> None ) def test_fetch_job_result( mocker: MockerFixture, - page_reader_mock: MockerFixture, + page_reader_mock: AsyncMock, circuits: Union[QuantumCircuit, List[QuantumCircuit]], expected_n_jobs: int, ) -> None: diff --git a/tests/test_qi_provider.py b/tests/test_qi_provider.py index b0bd36d..0edd954 100644 --- a/tests/test_qi_provider.py +++ b/tests/test_qi_provider.py @@ -4,7 +4,6 @@ import pytest from pytest_mock import MockFixture -from qiskit_quantuminspire.api.pagination import PageReader from qiskit_quantuminspire.qi_backend import QIBackend from qiskit_quantuminspire.qi_provider import QIProvider from tests.helpers import create_backend_type @@ -17,15 +16,6 @@ def mock_api(mocker: MockFixture) -> None: mocker.patch("qiskit_quantuminspire.qi_provider.BackendTypesApi") -@pytest.fixture -def page_reader_mock(mocker: MockFixture) -> AsyncMock: - # Simply calling mocker.patch() doesn't work because PageReader is a generic class - page_reader_mock = AsyncMock() - page_reader_mock.get_all = AsyncMock() - mocker.patch.object(PageReader, "get_all", page_reader_mock.get_all) - return page_reader_mock - - def test_qi_provider_construct(mock_api: Any, page_reader_mock: AsyncMock) -> None: # Arrange page_reader_mock.get_all.return_value = [