Ejemplo n.º 1
0
class TestAttribute(unittest.TestCase):
    def setUp(self):
        self.data = StringMeta().create_attribute_model()
        self.data.set_notifier_path(Mock(), ["block", "attr"])
        self.controller = Mock()
        self.context = Mock()
        self.o = Attribute(self.controller, self.context, self.data)

    def test_init(self):
        self.assertIsInstance(self.o, Attribute)
        assert hasattr(self.o, "meta")
        assert hasattr(self.o, "value")
        assert hasattr(self.o, "subscribe_value")

    def test_put(self):
        self.o.put_value(32)
        self.context.put.assert_called_once_with(["block", "attr", "value"],
                                                 32,
                                                 timeout=None)

    def test_put_async(self):
        f = self.o.put_value_async(32)
        self.context.put_async.assert_called_once_with(
            ["block", "attr", "value"], 32)
        assert f == self.context.put_async.return_value

    def test_repr(self):
        self.context.make_view.return_value = "foo"
        assert repr(self.o) == "<Attribute value='foo'>"
        self.context.make_view.assert_called_once_with(self.controller,
                                                       self.data, "value")
Ejemplo n.º 2
0
    def _fill_sequencer(self, seq_table: Attribute) -> None:
        assert self.generator, "No generator"
        points = self.generator.get_points(self.loaded_up_to, self.scan_up_to)

        if points is None or len(points) == 0:
            table = SequencerTable.from_rows([])
            seq_table.put_value(table)
            return

        rows = []

        if not self.axis_mapping:
            # No position compare or row triggering required
            rows.extend(self._generate_immediate_rows(points.duration))

            # one last dead frame signal
            rows.append(seq_row(half_duration=LAST_PULSE, dead=1))

            if len(rows) > SEQ_TABLE_ROWS:
                raise Exception("Seq table: {} rows with {} maximum".format(
                    len(rows), SEQ_TABLE_ROWS))

            table = SequencerTable.from_rows(rows)
            seq_table.put_value(table)
            return

        start_indices, end_indices = self._get_row_indices(points)

        point = points[0]
        first_point_static = point.positions == point.lower == point.upper
        end = start_indices[0] if start_indices.size else len(points)
        if not first_point_static:
            # If the motors are moving during this point then
            # wait for triggers
            rows.extend(self._generate_triggered_rows(points, 0, end, False))
        else:
            # This first row should not wait, and will trigger immediately
            rows.extend(self._generate_immediate_rows(points.duration[0:end]))

        for start, end in zip(start_indices, end_indices):
            # First row handled outside of loop
            self.last_point = points[start - 1]

            rows.extend(self._generate_triggered_rows(points, start, end,
                                                      True))

        # one last dead frame signal
        rows.append(seq_row(half_duration=LAST_PULSE, dead=1))

        if len(rows) > SEQ_TABLE_ROWS:
            raise Exception("Seq table: {} rows with {} maximum".format(
                len(rows), SEQ_TABLE_ROWS))

        table = SequencerTable.from_rows(rows)
        seq_table.put_value(table)