Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi committed May 30, 2024
1 parent f99e434 commit a04d6c7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 19 additions & 1 deletion test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,15 @@ def make_test_sampler_pubs(self):
pubs.append(pub)
return pubs

def make_test_pub_results(self):
"""Generates test data for PubResult test"""
pub_results = []
pub_result = PubResult(DataBin(a=1.0, b=2))
pub_results.append(pub_result)
pub_result = PubResult(DataBin(a=1.0, b=2), {"x": 1})
pub_results.append(pub_result)
return pub_results

def make_test_sampler_pub_results(self):
"""Generates test data for SamplerPubResult test"""
pub_results = []
Expand Down Expand Up @@ -505,11 +514,20 @@ def test_sampler_pub(self):

def test_pub_result(self):
"""Test encoding and decoding PubResult"""
for pub_result in self.make_test_pub_results():
payload = {"pub_result": pub_result}
encoded = json.dumps(payload, cls=RuntimeEncoder)
decoded = json.loads(encoded, cls=RuntimeDecoder)["pub_result"]
self.assertIsInstance(decoded, PubResult)
self.assert_pub_results_equal(pub_result, decoded)

def test_sampler_pub_result(self):
"""Test encoding and decoding SamplerPubResult"""
for pub_result in self.make_test_sampler_pub_results():
payload = {"sampler_pub_result": pub_result}
encoded = json.dumps(payload, cls=RuntimeEncoder)
decoded = json.loads(encoded, cls=RuntimeDecoder)["sampler_pub_result"]
self.assertIsInstance(decoded, PubResult)
self.assertIsInstance(decoded, SamplerPubResult)
self.assert_pub_results_equal(pub_result, decoded)

def test_primitive_result(self):
Expand Down
8 changes: 7 additions & 1 deletion test/unit/test_local_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
from ddt import data, ddt

from qiskit_aer import AerSimulator
from qiskit.primitives import EstimatorResult, SamplerResult, PrimitiveResult, PubResult, SamplerPubResult
from qiskit.primitives import (
EstimatorResult,
SamplerResult,
PrimitiveResult,
PubResult,
SamplerPubResult,
)
from qiskit.primitives.containers.data_bin import DataBin

from qiskit_ibm_runtime.fake_provider import FakeManila, FakeManilaV2
Expand Down

0 comments on commit a04d6c7

Please sign in to comment.