Skip to content

Commit

Permalink
Fixed DummySerializable and tests.
Browse files Browse the repository at this point in the history
DummySerializable's constructor now also passes on the registry argument.
Fixed all failing tests.
  • Loading branch information
lumip committed Jul 5, 2018
1 parent a5c0074 commit c799fcd
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/serialization_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from abc import ABCMeta, abstractmethod

from tempfile import TemporaryDirectory
from typing import Optional, Any
from typing import Optional, Any, Dict

from qctoolkit.serialization import FilesystemBackend, CachingBackend, Serializable, JSONSerializableEncoder,\
ZipFileBackend, AnonymousSerializable, DictBackend, PulseStorage, JSONSerializableDecoder, Serializer,\
Expand All @@ -22,8 +22,8 @@

class DummySerializable(Serializable):

def __init__(self, identifier: Optional[str]=None, **kwargs) -> None:
super().__init__(identifier)
def __init__(self, identifier: Optional[str]=None, registry: Optional[Dict]=None, **kwargs) -> None:
super().__init__(identifier, registry=registry)
for name in kwargs:
setattr(self, name, kwargs[name])

Expand Down Expand Up @@ -740,15 +740,15 @@ def test_serialize_subpulse_no_identifier(self) -> None:
self.assertEqual(expected, serialized)

def test_serialize_subpulse_identifier(self) -> None:
serializable = DummySerializable(identifier='bar')
serializable = DummySerializable(identifier='bar', registry=dict())
serialized = self.serializer.dictify(serializable)
self.assertEqual(serializable.identifier, serialized)

def test_serialize_subpulse_duplicate_identifier(self) -> None:
serializable = DummySerializable(identifier='bar')
serializable = DummySerializable(identifier='bar', registry=dict())
self.serializer.dictify(serializable)
self.serializer.dictify(serializable)
serializable = DummySerializable(data='this is other data than before', identifier='bar')
serializable = DummySerializable(data='this is other data than before', identifier='bar', registry=dict())
with self.assertRaises(Exception):
self.serializer.dictify(serializable)

Expand Down Expand Up @@ -866,15 +866,18 @@ def test_deserialize_identifier(self) -> None:
self.assertEqual(self.deserialization_data['data'], deserialized.data)

def test_serialization_and_deserialization_combined(self) -> None:
registry = dict()
table_foo = TablePulseTemplate(identifier='foo', entries={'default': [('hugo', 2),
('albert', 'voltage')]},
parameter_constraints=['albert<9.1'])
parameter_constraints=['albert<9.1'],
registry=registry)
table = TablePulseTemplate({'default': [('t', 0)]})

foo_mappings = dict(hugo='ilse', albert='albert', voltage='voltage')
sequence = SequencePulseTemplate((table_foo, foo_mappings, dict()),
(table, dict(t=0), dict()),
identifier=None)
identifier=None,
registry=registry)
self.assertEqual({'ilse', 'albert', 'voltage'}, sequence.parameter_names)

storage = DummyStorageBackend()
Expand Down

0 comments on commit c799fcd

Please sign in to comment.