def test_build_sequence(self) -> None:
     sequencer = DummySequencer(DummySequencingHardware())
     instruction_block = DummyInstructionBlock()
     block = DummyInstructionBlock()
     element1 = DummySequencingElement(push_elements=(block, [self.square]))
     element2 = DummySequencingElement()
     mapping = {}
     subtemplates = [(self.square, self.mapping1),
                     (element2, mapping)]
     sequence = SequencePulseTemplate(subtemplates, self.parameters.keys())
     sequence.build_sequence(sequencer, self.parameters, instruction_block)
    def test_deserialize(self) -> None:
        data = dict(
            external_parameters={'ilse', 'albert', 'voltage'},
            is_interruptable=True,
            subtemplates = [
                dict(template=str(id(self.table_foo)), mappings=self.foo_mappings),
                dict(template=str(id(self.table)), mappings=dict())
            ],
            identifier='foo'
        )

        # prepare dependencies for deserialization
        self.serializer.subelements[str(id(self.table_foo))] = self.table_foo
        self.serializer.subelements[str(id(self.table))] = self.table

        # deserialize
        sequence = SequencePulseTemplate.deserialize(self.serializer, **data)

        # compare!
        self.assertEqual(data['external_parameters'], sequence.parameter_names)
        self.assertEqual({ParameterDeclaration('ilse'), ParameterDeclaration('albert'), ParameterDeclaration('voltage')},
                         sequence.parameter_declarations)
        self.assertIs(self.table_foo, sequence.subtemplates[0][0])
        self.assertIs(self.table, sequence.subtemplates[1][0])
        self.assertEqual(self.foo_mappings, {k: m.string for k,m in sequence.subtemplates[0][1].items()})
        self.assertEqual(dict(), sequence.subtemplates[1][1])
        self.assertEqual(data['identifier'], sequence.identifier)
    def test_get_serialization_data(self) -> None:
        sequence = SequencePulseTemplate([(self.table_foo, self.foo_mappings), (self.table, {})],
                                         ['ilse', 'albert', 'voltage'],
                                         identifier='foo')

        expected_data = dict(
            type=self.serializer.get_type_identifier(sequence),
            external_parameters=['albert', 'ilse', 'voltage'],
            is_interruptable=True,
            subtemplates = [
                dict(template=str(id(self.table_foo)), mappings=self.foo_mappings),
                dict(template=str(id(self.table)), mappings=dict())
            ]
        )
        data = sequence.get_serialization_data(self.serializer)
        self.assertEqual(expected_data, data)