Skip to content

Commit

Permalink
Merge 01aa987 into dcfdd33
Browse files Browse the repository at this point in the history
  • Loading branch information
lumip committed Jul 5, 2018
2 parents dcfdd33 + 01aa987 commit c7e2ec4
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 @@ -679,7 +679,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 @@ -522,7 +522,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 @@ -554,6 +554,24 @@ def test_clear(self):

self.assertFalse(self.storage.temporary_storage)

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 c7e2ec4

Please sign in to comment.