def test_compiling_A_pulse_not_selecting(self):
        self.context.select_after_transfer = False
        self.context.run_after_transfer = False
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Analogical',
                      shape=SquareShape(amplitude='1.0'),
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_A')
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert sorted(infos) == sorted(self.context.list_sequence_infos())
        assert not self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert self.driver.channels[1].array is None

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1001:2] += 2**4 + 2**3 + 4 + 2 + 1
        sequence[200:1000:2] += 255
        np.testing.assert_array_equal(self.driver.sequences['Test_Ch1'],
                                      to_bytes(sequence))
    def test_nearly_overlapping_M2(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse1 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.5',
                       channel='Ch1_M2')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.5',
                       def_2='0.6',
                       channel='Ch1_M2')
        self.root.add_child_item(0, pulse1)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1201:2] += 2**7
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))
    def test_compiling_M1_pulse_selecting_but_not_clearing(self):
        self.context.clear_unused_channels = False
        self.driver.channels[2].array = np.zeros(10)
        self.context.run_after_transfer = False
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M1')
        pulse2 = Pulse(kind='Logical',
                       def_1='0.1',
                       def_2='0.1',
                       channel='Ch1_M1')
        self.root.add_child_item(0, pulse)
        self.root.add_child_item(1, pulse2)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert not self.driver.running
        assert self.driver.channels[2].array is not None
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[201:1001:2] += 2**6
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))
    def test_compiling_variable_length(self):
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M1')
        self.context.sampling_frequency = 1e8
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(100, dtype=np.uint8)
        sequence[1::2] = 2**5
        sequence[21:101:2] += 2**6
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))
    def test_compiling_inverted_logical_pulses_and_running(self):
        self.root.time_constrained = True
        self.root.sequence_duration = '1'
        pulse = Pulse(kind='Logical',
                      def_1='0.1',
                      def_2='0.5',
                      channel='Ch1_M2')
        self.context.inverted_log_channels = ['Ch1_M1', 'Ch1_M2']
        self.root.add_child_item(0, pulse)

        res, infos, errors = self.compile(self.root, self.driver)
        print(errors)
        assert res
        assert self.driver.running
        assert 'Test_Ch1' in self.driver.sequences
        assert len(self.driver.sequences) == 1
        assert (self.driver.channels[1].array is
                self.driver.sequences['Test_Ch1'])

        sequence = np.zeros(2000, dtype=np.uint8)
        sequence[1::2] = 2**7 + 2**6 + 2**5
        sequence[201:1001:2] -= 2**7
        np.testing.assert_array_equal(self.driver.channels[1].array,
                                      to_bytes(sequence))