Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WingCode committed May 31, 2024
1 parent 24f1a37 commit f649fdf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/providers/test_braket_quantum_task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for AWS Braket job."""

from unittest import TestCase
from unittest.mock import Mock
from unittest.mock import Mock, patch

import pytest
from braket.aws.aws_quantum_task import AwsQuantumTask
Expand All @@ -13,12 +13,17 @@
BraketLocalBackend,
BraketQuantumTask,
)
from qiskit_braket_provider.providers.braket_quantum_task import retry_if_result_none
from tests.providers.mocks import MOCK_LOCAL_QUANTUM_TASK


class TestBraketTask(TestCase):
"""Tests BraketTask."""

def test_retry_if_result_none(self):
"""Test when result is None"""
assert retry_if_result_none(None) == True

def _get_task(self):
return BraketQuantumTask(
backend=BraketLocalBackend(name="default"),
Expand All @@ -32,6 +37,7 @@ def test_task(self):
task = self._get_task()

self.assertTrue(isinstance(task, BraketQuantumTask))
self.assertEqual(None, task.submit())
self.assertEqual(task.shots, 10)

self.assertEqual(task.status(), JobStatus.DONE)
Expand All @@ -46,6 +52,21 @@ def test_result(self):
self.assertEqual(task.result().results[0].status, "COMPLETED")
self.assertEqual(task.result().results[0].shots, 3)
self.assertEqual(task.result().get_memory(), ["10", "10", "01"])

@patch('qiskit_braket_provider.providers.braket_quantum_task.AwsQuantumTaskBatch._retrieve_results')
def test_task_result_is_none(self, mock_retrieve_results):
"""Tests result."""
mock_retrieve_results.return_value = [None, None]

task = BraketQuantumTask(
backend=BraketLocalBackend(name="default"),
task_id="AwesomeId",
tasks=[MOCK_LOCAL_QUANTUM_TASK, MOCK_LOCAL_QUANTUM_TASK],
shots=10,
)
task.result()

mock_retrieve_results.assert_called_once()

def test_queue_position_for_local_quantum_task(self):
"""Tests job status when multiple task status is present."""
Expand Down

0 comments on commit f649fdf

Please sign in to comment.