def build_sequence(self, sequencer: Sequencer, parameters: Dict[str, Parameter], instruction_block: InstructionBlock) -> None:
     self.build_call_counter += 1
     self.target_block = instruction_block
     self.parameters = parameters
     if self.push_elements is not None:
         for element in self.push_elements[1]:
             sequencer.push(element, parameters, self.push_elements[0])
    def test_build_path_o2_m1_i2_tf_m2_i1_f_i1_f_two_elements_main_block_last_requires_stop_add_one_element_requires_stop_new_block(self) -> None:
        dummy_hardware = DummySequencingHardware()
        sequencer = Sequencer(dummy_hardware)
    
        ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
        
        new_block = InstructionBlock()
        new_elem = DummySequencingElement(True)
        
        elem1 = DummySequencingElement(False, (new_block, [new_elem]))
        elem2 = DummySequencingElement(True)
        sequencer.push(elem2, ps)
        sequencer.push(elem1, ps)

        block = sequencer.build()
        
        self.assertFalse(sequencer.has_finished())
        self.assertIs(block, elem1.target_block)
        self.assertEqual(ps, elem1.parameters)
        self.assertEqual(1, elem1.requires_stop_call_counter)
        self.assertEqual(1, elem1.build_call_counter)
        self.assertEqual(ps, elem2.parameters)
        self.assertEqual(2, elem2.requires_stop_call_counter)
        self.assertEqual(0, elem2.build_call_counter)
        self.assertEqual(ps, new_elem.parameters)
        self.assertEqual(1, new_elem.requires_stop_call_counter)
        self.assertEqual(0, new_elem.build_call_counter)
 def test_push(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
     
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     elem = DummySequencingElement()
     
     sequencer.push(elem, ps)
     self.assertFalse(sequencer.has_finished())
 def test_build_path_o2_m2_i1_t_i2_tt_m2_i0_i0_two_elements_custom_block_one_element_main_block(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
             
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     
     target_block = InstructionBlock()
     elem2 = DummySequencingElement(False)
     sequencer.push(elem2, ps, target_block)
     
     elem1 = DummySequencingElement(False)
     sequencer.push(elem1, ps, target_block)
     
     elem_main = DummySequencingElement(False)
     sequencer.push(elem_main, ps)
     
     block = sequencer.build()
     
     self.assertTrue(sequencer.has_finished())
     self.assertIs(target_block, elem1.target_block)
     self.assertEqual(ps, elem1.parameters)
     self.assertEqual(1, elem1.requires_stop_call_counter)
     self.assertEqual(1, elem1.build_call_counter)
     self.assertIs(target_block, elem2.target_block)
     self.assertEqual(ps, elem2.parameters)
     self.assertEqual(1, elem2.requires_stop_call_counter)
     self.assertEqual(1, elem2.build_call_counter)
     self.assertIs(block, elem_main.target_block)
     self.assertEqual(ps, elem_main.parameters)
     self.assertEqual(1, elem_main.requires_stop_call_counter)
     self.assertEqual(1, elem_main.build_call_counter)
 def test_build_path_o1_m1_i1_f_single_element_requires_stop_main_block(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
 
     elem = DummySequencingElement(True)
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     sequencer.push(elem, ps)
     block = sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem.parameters)
     self.assertEqual(1, elem.requires_stop_call_counter)
     self.assertEqual(0, elem.build_call_counter)
 def test_build_path_o1_m2_i1_f_i0_one_element_custom_block_requires_stop(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
 
     elem = DummySequencingElement(True)
     ps = {'foo': ConstantParameter(1), 'bar': ConstantParameter(7.3)}
     target_block = InstructionBlock()
     sequencer.push(elem, ps, target_block)
     block = sequencer.build()
     
     self.assertFalse(sequencer.has_finished())
     self.assertEqual(ps, elem.parameters)
     self.assertEqual(1, elem.requires_stop_call_counter)
     self.assertEqual(0, elem.build_call_counter)
    def test_register_waveform(self) -> None:
        dummy_hardware = DummySequencingHardware()
        sequencer = Sequencer(dummy_hardware)

        w1 = DummyWaveform()
        sequencer.register_waveform(w1)
        
        w2 = DummyWaveform()
        sequencer.register_waveform(w2)

        sequencer.register_waveform(w1)

        self.assertEqual([w1, w2], dummy_hardware.waveforms)
        self.assertTrue(sequencer.has_finished())
    def test_push_float_params(self) -> None:
        dummy_hardware = DummySequencingHardware()
        sequencer = Sequencer(dummy_hardware)

        ps = {'foo': 1, 'bar': 7.3}
        elem = DummySequencingElement()
        sequencer.push(elem, ps)
        self.assertFalse(sequencer.has_finished())
        sequencer.build()
        self.assertIsInstance(elem.parameters['foo'], ConstantParameter)
        self.assertIsInstance(elem.parameters['bar'], ConstantParameter)
 def test_build_path_no_loop_nothing_to_do(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
     
     block = sequencer.build()
     self.assertTrue(sequencer.has_finished())
 def test_initialization(self) -> None:
     dummy_hardware = DummySequencingHardware()
     sequencer = Sequencer(dummy_hardware)
     self.assertTrue(sequencer.has_finished())
     self.assertFalse(dummy_hardware.waveforms)