Skip to content

Commit

Permalink
Merge issues/250_serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Jul 6, 2018
2 parents b49b943 + bbfeabe commit 345a676
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion qctoolkit/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def overwrite(self, identifier: str, serializable: Serializable) -> None:
if is_transaction_begin:
self._transaction_storage = dict()

encoder = JSONSerializableEncoder(self)
encoder = JSONSerializableEncoder(self, sort_keys=True, indent=4)

serialization_data = serializable.get_serialization_data()
serialized = encoder.encode(serialization_data)
Expand Down
20 changes: 19 additions & 1 deletion tests/serialization_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def test_write_through_does_not_overwrite_subpulses(self) -> None:
self.assertNotIn('my_id_2', self.backend)
self.assertIs(previous_inner, self.storage['my_id_1'])

enc = JSONSerializableEncoder(None)
enc = JSONSerializableEncoder(None, sort_keys=True, indent=4)
expected = enc.encode(previous_inner.get_serialization_data())
self.assertEqual(expected, self.backend['my_id_1'])

Expand Down Expand Up @@ -572,6 +572,24 @@ def test_set_to_default_registry(self) -> None:
import qctoolkit.serialization
qctoolkit.serialization.default_pulse_registry = previous_default_registry

def test_beautified_json(self) -> None:
data = {'e': 89, 'b': 151, 'c': 123515, 'a': 123, 'h': 2415}
template = DummySerializable(data=data)
pulse_storage = PulseStorage(DummyStorageBackend())
pulse_storage['foo'] = template

expected = """{
\"#type\": \"""" + DummySerializable.get_type_identifier() + """\",
\"data\": {
\"a\": 123,
\"b\": 151,
\"c\": 123515,
\"e\": 89,
\"h\": 2415
}
}"""
self.assertEqual(expected, pulse_storage._storage_backend['foo'])


class JSONSerializableDecoderTests(unittest.TestCase):
def test_filter_serializables(self):
Expand Down

0 comments on commit 345a676

Please sign in to comment.