Beispiel #1
0
 def _make_icon_label(self):
     block_type = self.block_name.rstrip("0123456789")
     svg_name = block_type + ".svg"
     part = call_with_params(IconPart, svg=os.path.join(SVG_DIR, svg_name))
     self._add_part("icon", part)
     part = call_with_params(LabelPart, initialValue=block_type)
     self._add_part("label", part)
Beispiel #2
0
    def setUp(self):
        self.p = Process('process1')
        self.context = Context(self.p)

        # Make a fast child
        c1 = call_with_params(RunnableController, self.p,
                              [WaitingPart("p", 0.01)],
                              mri="fast", configDir="/tmp")
        self.p.add_controller("fast", c1)

        # And a slow one
        c2 = call_with_params(RunnableController,  self.p,
                              [WaitingPart("p", 1.0)],
                              mri="slow", configDir="/tmp")
        self.p.add_controller("slow", c2)

        # And a top level one
        p1 = call_with_params(RunnableChildPart, name="FAST", mri="fast")
        p2 = call_with_params(RunnableChildPart, name="SLOW", mri="slow")
        c3 = call_with_params(RunnableController, self.p, [p1, p2],
                              mri="top", configDir="/tmp")
        self.p.add_controller("top", c3)
        self.b = self.context.block_view("top")
        self.bf = self.context.block_view("fast")
        self.bs = self.context.block_view("slow")

        # start the process off
        self.p.start()
Beispiel #3
0
 def setUp(self):
     self.process = Process("proc")
     self.hello = call_with_params(hello_block, self.process, mri="hello")
     self.server = call_with_params(
         web_server_block, self.process, mri="server", port=self.socket)
     self.result = Queue()
     self.process.start()
    def setUp(self):
        self.p = Process('process1')

        # create a child to client
        self.c_part = MyPart("cp1")
        self.c_child = call_with_params(StatefulController,
                                        self.p, [self.c_part],
                                        mri="childBlock")
        self.p.add_controller("childBlock", self.c_child)

        part1 = MyPart("part1")
        part2 = call_with_params(ChildPart, name='part2', mri='childBlock')

        # create a root block for the ManagerController block to reside in
        parts = [part1, part2]
        self.c = call_with_params(ManagerController,
                                  self.p,
                                  parts,
                                  mri='mainBlock',
                                  configDir="/tmp")
        self.p.add_controller("mainBlock", self.c)

        # check that do_initial_reset works asynchronously
        assert self.c.state.value == "Disabled"
        self.p.start()
        assert self.c.state.value == "Ready"
 def test_save(self):
     self.c._run_git_cmd = MagicMock()
     call_with_params(self.c.save, design="testSaveLayout")
     self.check_expected_save()
     assert self.c.state.value == "Ready"
     assert self.c.design.value == 'testSaveLayout'
     assert self.c.modified.value is False
     os.remove("/tmp/mainBlock/testSaveLayout.json")
     self.c_part.attr.set_value("newv")
     assert self.c.modified.value is True
     assert self.c.modified.alarm.message == \
            "part2.attr.value = 'newv' not 'defaultv'"
     call_with_params(self.c.save, design="")
     self.check_expected_save(attr="newv")
     assert self.c.design.value == 'testSaveLayout'
     assert self.c._run_git_cmd.call_args_list == [
         call('add', '/tmp/mainBlock/testSaveLayout.json'),
         call('commit', '--allow-empty', '-m',
              'Saved mainBlock testSaveLayout',
              '/tmp/mainBlock/testSaveLayout.json'),
         call('add', '/tmp/mainBlock/testSaveLayout.json'),
         call('commit', '--allow-empty', '-m',
              'Saved mainBlock testSaveLayout',
              '/tmp/mainBlock/testSaveLayout.json')
     ]
    def setUp(self):
        self.p = Process('process1')
        self.context = Context(self.p)

        # Make a ticker_block block to act as our child
        self.c_child = call_with_params(ticker_block,
                                        self.p,
                                        mri="childBlock",
                                        configDir="/tmp")
        self.b_child = self.context.block_view("childBlock")

        # Make an empty part for our parent
        part1 = Part("part1")

        # Make a RunnableChildPart to control the ticker_block
        part2 = call_with_params(RunnableChildPart,
                                 mri='childBlock',
                                 name='part2')

        # create a root block for the RunnableController block to reside in
        self.c = call_with_params(RunnableController,
                                  self.p, [part1, part2],
                                  mri='mainBlock',
                                  configDir="/tmp",
                                  axesToMove=["x"])
        self.p.add_controller('mainBlock', self.c)
        self.b = self.context.block_view("mainBlock")
        self.ss = self.c.stateSet

        # start the process off
        self.checkState(self.ss.DISABLED)
        self.p.start()
        self.checkState(self.ss.READY)
Beispiel #7
0
 def test_server_hello_with_malcolm_client(self):
     call_with_params(
         proxy_block, self.process2, mri="hello", comms="client")
     block2 = self.process2.block_view("hello")
     ret = block2.greet("me2")
     assert ret == dict(greeting="Hello me2")
     with self.assertRaises(ResponseError):
         block2.error()
    def set_completed_steps(self, completed_steps):
        """Seek a Armed or Paused scan back to another value

        Normally it will return in the state it started in. If the user aborts
        then it will return in Aborted state. If something goes wrong it will
        return in Fault state. If the user disables then it will return in
        Disabled state.
        """
        call_with_params(self.pause, completedSteps=completed_steps)
Beispiel #9
0
 def makeChildBlock(self, blockMri):
     controller = call_with_params(
         BasicController,
         self.p, [PortsPart(name='Connector%s' % blockMri[-1])],
         mri=blockMri)
     part = call_with_params(ChildPart,
                             mri=blockMri,
                             name='part%s' % blockMri)
     self.p.add_controller(blockMri, controller)
     return part, controller
 def test_set_export_parts(self):
     context = Context(self.p)
     b = context.block_view("mainBlock")
     assert list(b) == [
         'meta', 'health', 'state', 'layout', 'design', 'exports',
         'modified', 'disable', 'reset', 'save', 'attr'
     ]
     new_exports = Table(self.c.exports.meta)
     new_exports.append(('part2.attr', 'childAttr'))
     new_exports.append(('part2.reset', 'childReset'))
     self.c.set_exports(new_exports)
     assert self.c.modified.value == True
     assert self.c.modified.alarm.message == "exports changed"
     call_with_params(self.c.save, design='testSaveLayout')
     assert self.c.modified.value == False
     # block has changed, get a new view
     b = context.block_view("mainBlock")
     assert list(b) == [
         'meta', 'health', 'state', 'layout', 'design', 'exports',
         'modified', 'disable', 'reset', 'save', 'attr', 'childAttr',
         'childReset'
     ]
     assert self.c.state.value == "Ready"
     assert b.childAttr.value == "defaultv"
     assert self.c.modified.value == False
     m = MagicMock()
     f = b.childAttr.subscribe_value(m)
     # allow a subscription to come through
     context.sleep(0.1)
     m.assert_called_once_with("defaultv")
     m.reset_mock()
     self.c_part.attr.set_value("newv")
     assert b.childAttr.value == "newv"
     assert self.c_part.attr.value == "newv"
     assert self.c.modified.value == True
     assert self.c.modified.alarm.message == \
            "part2.attr.value = 'newv' not 'defaultv'"
     # allow a subscription to come through
     context.sleep(0.1)
     m.assert_called_once_with("newv")
     b.childAttr.put_value("again")
     assert b.childAttr.value == "again"
     assert self.c_part.attr.value == "again"
     assert self.c.modified.value == True
     assert self.c.modified.alarm.message == \
            "part2.attr.value = 'again' not 'defaultv'"
     # remove the field
     new_exports = Table(self.c.exports.meta)
     self.c.set_exports(new_exports)
     assert self.c.modified.value == True
     call_with_params(self.c.save)
     assert self.c.modified.value == False
     # block has changed, get a new view
     b = context.block_view("mainBlock")
     assert "childAttr" not in b
Beispiel #11
0
 def test_server_counter_with_malcolm_client(self):
     call_with_params(
         proxy_block, self.process2, mri="counter", comms="client")
     block2 = self.process2.block_view("counter")
     assert block2.counter.value == 0
     block2.increment()
     assert block2.counter.value == 1
     block2.zero()
     assert block2.counter.value == 0
     assert self.client.remote_blocks.value == (
         "hello", "counter", "server")
Beispiel #12
0
 def prepare_half_run(self):
     line1 = LineGenerator('AxisOne', 'mm', 0, 2, 3)
     line2 = LineGenerator('AxisTwo', 'mm', 0, 2, 2)
     compound = CompoundGenerator([line1, line2], [], [], 1.0)
     compound.prepare()
     call_with_params(self.o.configure,
                      ANY,
                      0,
                      2,
                      MagicMock(),
                      generator=compound,
                      axesToMove=['AxisTwo'])
Beispiel #13
0
 def setUp(self):
     self.process = Process("proc")
     self.hello = call_with_params(hello_block, self.process, mri="hello")
     self.counter = call_with_params(
         counter_block, self.process, mri="counter")
     self.server = call_with_params(
         web_server_block, self.process, mri="server", port=self.socket)
     self.process.start()
     self.process2 = Process("proc2")
     self.client = call_with_params(
         websocket_client_block, self.process2, mri="client",
         port=self.socket)
     self.process2.start()
Beispiel #14
0
 def s_server_hello_with_malcolm_client(self):
     from malcolm.core import call_with_params, Context, ResponseError
     from malcolm.blocks.builtin import proxy_block
     call_with_params(proxy_block,
                      self.process2,
                      mri="hello",
                      comms="client")
     context = Context(self.process2)
     context.when_matches(["hello", "health", "value"], "OK", timeout=2)
     block2 = self.process2.block_view("hello")
     ret = block2.greet(name="me2")
     assert ret == dict(greeting="Hello me2")
     with self.assertRaises(ResponseError):
         block2.error()
 def _make_child_controller(self, parts, mri):
     # Add some extra parts to determine the dataset name and type for
     # any CAPTURE field part
     new_parts = []
     for existing_part in parts:
         new_parts.append(existing_part)
         if existing_part.name.endswith(".CAPTURE"):
             # Add capture dataset name and type
             part_name = existing_part.name.replace(".CAPTURE",
                                                    ".DATASET_NAME")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             new_parts.append(
                 call_with_params(
                     StringPart,
                     name=attr_name,
                     widget="textinput",
                     description="Name of the captured dataset in HDF file",
                     writeable=True,
                     config=True))
             # Make a choice part to hold the type of the dataset
             part_name = existing_part.name.replace(".CAPTURE",
                                                    ".DATASET_TYPE")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             if "INENC" in mri:
                 initial = "position"
             else:
                 initial = "monitor"
             new_parts.append(
                 call_with_params(
                     ChoicePart,
                     name=attr_name,
                     widget="combo",
                     description="Type of the captured dataset in HDF file",
                     writeable=True,
                     choices=attribute_dataset_types,
                     initialValue=initial))
     if mri.endswith("PCAP"):
         new_parts += call_with_params(
             adbase_parts,
             self.process,
             prefix=self.params.areaDetectorPrefix)
         controller = call_with_params(StatefulController,
                                       self.process,
                                       new_parts,
                                       mri=mri)
     else:
         controller = super(PandABlocksRunnableController, self).\
             _make_child_controller(new_parts, mri)
     return controller
 def _make_corresponding_part(self, block_name, mri):
     if block_name == "PCAP":
         part_cls = PandABlocksDriverPart
     else:
         part_cls = PandABlocksChildPart
     part = call_with_params(part_cls, name=block_name, mri=mri)
     return part
Beispiel #17
0
 def setUp(self):
     svg_name = "/tmp/test_icon.svg"
     self.svg_text = '<svg><rect width="300" height="100"/></svg>'
     with open(svg_name, "w") as f:
         f.write(self.svg_text)
     self.o = call_with_params(IconPart, svg=svg_name)
     list(self.o.create_attribute_models())
Beispiel #18
0
    def create_child_block(self, child_block, process, **params):
        """Creates an instance of child_block with CA calls mocked out.

        Args:
            child_block (callable): The function to call to get the block
            process (Process): The process to run under
            **params: Parameters to pass to child_block()

        Returns:
            child: The child object with an attribute mock_requests that will
                have a call.put(attr_name, value) or
                a call.post(method_name, params) for anything the child is
                asked to handle
        """
        child = call_with_params(child_block, process, **params)
        child.handled_requests = Mock(return_value=None)

        def handle_put(request):
            attr_name = request.path[1]
            child.handled_requests.put(attr_name, request.value)
            return [request.return_response()]

        def handle_post(request):
            method_name = request.path[1]
            child.handled_requests.post(method_name, **request.parameters)
            return [request.return_response()]

        child._handle_put = handle_put
        child._handle_post = handle_post
        return child
Beispiel #19
0
    def instantiate(self, substitutions, *args):
        """Keep recursing down from base using dotted name, then call it with
        self.params and args

        Args:
            substitutions (dict): Substitutions to make to self.param_dict
            *args: Any other args to pass to the callable

        Returns:
            object: The found object called with (*args, map_from_d)

        E.g. if ob is malcolm.parts, and name is "ca.CADoublePart", then the
        object will be malcolm.parts.ca.CADoublePart
        """
        param_dict = self.substitute_params(substitutions)
        pkg, ident = self.name.rsplit(".", 1)
        pkg = "malcolm.modules.%s" % pkg
        try:
            ob = importlib.import_module(pkg)
        except ImportError:
            raise ImportError("%s:%d:\nCan't import %r" %
                              (self.filename, self.lineno, pkg))
        try:
            ob = getattr(ob, ident)
        except AttributeError:
            raise ImportError("%s:%d:\nPackage %r has no ident %r" %
                              (self.filename, self.lineno, pkg, ident))
        try:
            ret = call_with_params(ob, *args, **param_dict)
        except YamlError as e:
            raise YamlError("%s:%d:\n%s" % (self.filename, self.lineno, e))
        else:
            return ret
Beispiel #20
0
 def setUp(self):
     self.o = call_with_params(Float64Part,
                               name="fp",
                               description="desc",
                               initialValue=2.3,
                               writeable=True,
                               widget="textinput")
     self.setter = list(self.o.create_attribute_models())[0][2]
Beispiel #21
0
 def setUp(self):
     self.o = call_with_params(ChoicePart,
                               name="cp",
                               description="desc",
                               choices=["a", "b"],
                               initialValue="a",
                               writeable=True)
     self.setter = list(self.o.create_attribute_models())[0][2]
 def test_proxy_block(self):
     process = Mock()
     controller = call_with_params(
         proxy_block, process, comms="comms_mri", mri="my_mri", publish=True)
     process.add_controller.assert_called_once_with(
         "my_mri", controller, True)
     process.get_controller.assert_called_once_with("comms_mri")
     assert controller.client_comms == process.get_controller.return_value
 def setUp(self):
     self.process = Process("proc")
     self.o = call_with_params(MQTTServerComms,
                               self.process, (),
                               mri="mri",
                               block="block",
                               attribute="attribute",
                               topic_prefix="prefix")
 def setUp(self):
     self.process = Process("Process")
     self.context = Context(self.process)
     self.child = self.create_child_block(
         xmap_detector_driver_block, self.process,
         mri="mri", prefix="prefix")
     self.o = call_with_params(XmapDriverPart, name="m", mri="mri")
     list(self.o.create_attribute_models())
     self.process.start()
Beispiel #25
0
 def _make_group(self, attr_name):
     if attr_name not in self.parts:
         part = call_with_params(GroupPart,
                                 name=attr_name,
                                 description="All %s attributes" %
                                 attr_name)
         self._add_part(attr_name, part)
     group_tag = group(attr_name)
     return group_tag
Beispiel #26
0
 def setUp(self):
     self.o = call_with_params(LabelPart,
                               initialValue="My label",
                               group="mygroup")
     self.p = Process("proc")
     self.c = Controller(self.p, "mri", [self.o])
     self.p.add_controller("mri", self.c)
     self.p.start()
     self.b = self.c.block_view()
Beispiel #27
0
 def setUp(self):
     self.process = Process("Process")
     self.context = Context(self.process)
     self.child = self.create_child_block(reframe_plugin_block,
                                          self.process,
                                          mri="mri",
                                          prefix="prefix")
     self.o = call_with_params(ReframePluginPart, name="m", mri="mri")
     list(self.o.create_attribute_models())
     self.process.start()
Beispiel #28
0
 def setUp(self):
     self.process = Process("Process")
     self.context = Context(self.process)
     self.child = self.create_child_block(hdf_writer_block,
                                          self.process,
                                          mri="BLOCK-HDF5",
                                          prefix="prefix")
     self.o = call_with_params(HDFWriterPart, name="m", mri="BLOCK-HDF5")
     list(self.o.create_attribute_models())
     self.process.start()
Beispiel #29
0
    def create_part(self, params=None):
        if params is None:
            params = dict(
                name="mname",
                description="desc",
                pv="pv",
            )

        p = call_with_params(CAActionPart, **params)
        self.yielded = list(p.create_method_models())
        return p
Beispiel #30
0
 def setUp(self):
     self.mp_q = multiprocessing.Queue()
     self.mp = multiprocessing.Process(target=p1, args=(self.mp_q, ))
     self.mp.start()
     from malcolm.core import Process, call_with_params
     from malcolm.blocks.pva import pva_client_block
     self.process2 = Process("proc2")
     self.client = call_with_params(pva_client_block,
                                    self.process2,
                                    mri="client")
     self.process2.start()