Ejemplo n.º 1
0
 def test_set_elements(self):
     tm = self.tm
     elements = OrderedDict()
     elements["col1"] = StringArrayMeta()
     elements["col2"] = StringArrayMeta()
     tm.set_elements(elements)
     assert elements == tm.elements
Ejemplo n.º 2
0
 def test_set_elements_from_serialized(self):
     tm = self.tm
     elements = OrderedDict()
     elements["col1"] = StringArrayMeta().to_dict()
     elements["col2"] = StringArrayMeta().to_dict()
     tm.set_elements(elements)
     assert isinstance(tm.elements["col1"], StringArrayMeta)
     assert tm.elements["col1"].to_dict() == elements["col1"]
Ejemplo n.º 3
0
 def setUp(self):
     self.mm = MapMeta()
     self.sam = StringArrayMeta()
     self.sam.label = "C1"
     self.serialized = OrderedDict()
     self.serialized["typeid"] = "malcolm:core/MapMeta:1.0"
     self.serialized["elements"] = dict(c1=self.sam.to_dict())
     self.serialized["required"] = ["c1"]
Ejemplo n.º 4
0
    def __init__(self, name: parts.APartName, ioc: AIoc) -> None:
        super().__init__(name)

        self.dls_ver_pv = ca.util.CAAttribute(
            StringMeta("IOC version"),
            ca.util.catools.DBR_STRING,
            "",
            ioc + ":DLSVER",
            throw=False,
            callback=self.version_updated,
        )
        self.dir1_pv = ca.util.CAAttribute(
            StringMeta("IOC directory pt1"),
            ca.util.catools.DBR_STRING,
            "",
            ioc + ":APP_DIR1",
            widget=Widget.NONE,
            throw=False,
            callback=self.set_dir1,
        )
        self.dir2_pv = ca.util.CAAttribute(
            StringMeta("IOC directory pt2"),
            ca.util.catools.DBR_STRING,
            "",
            ioc + ":APP_DIR2",
            widget=Widget.NONE,
            throw=False,
            callback=self.set_dir2,
        )

        self.autosave_status_pv = ca.util.CAAttribute(
            StringMeta("IOC Status"),
            ca.util.catools.DBR_STRING,
            "",
            ioc + ":STATUS",
            throw=False,
            callback=self.set_procserv_state,
        )

        self.dir1 = None
        self.dir2 = None
        self.dir = ""

        self.has_procserv = False

        elements = OrderedDict()
        elements["module"] = StringArrayMeta("Module", tags=[Widget.TEXTUPDATE.tag()])
        elements["path"] = StringArrayMeta("Path", tags=[Widget.TEXTUPDATE.tag()])

        self.dependencies = TableMeta(
            "Modules which this IOC depends on",
            tags=[Widget.TABLE.tag()],
            writeable=False,
            elements=elements,
        ).create_attribute_model({"module": [], "path": []})
Ejemplo n.º 5
0
 def setUp(self):
     tm = TableMeta("desc")
     self.tm = tm
     self.tm.set_elements(dict(c1=StringArrayMeta()))
     self.sam = StringArrayMeta()
     self.serialized = OrderedDict()
     self.serialized["typeid"] = "malcolm:core/TableMeta:1.0"
     self.serialized["description"] = "desc"
     self.serialized["tags"] = []
     self.serialized["writeable"] = True
     self.serialized["label"] = "Name"
     self.serialized["elements"] = dict(c1=self.sam.to_dict())
Ejemplo n.º 6
0
 def test_to_dict(self):
     elements = OrderedDict()
     elements["foo"] = StringArrayMeta(label="Foo")
     elements["bar"] = StringArrayMeta()
     meta = TableMeta(description="desc", tags=[], writeable=True,
                      label="my label", elements=elements)
     value = meta.table_cls(
         foo=["foo1", "foo2"],
         bar=["bar1", "bar2"])
     o = meta.create_attribute_model(value)
     o.set_ts(self.serialized["timeStamp"])
     assert o.meta.elements["foo"].to_dict() == self.serialized["meta"]["elements"]["foo"]
     assert o.to_dict() == self.serialized
Ejemplo n.º 7
0
 def __init__(self, mri, port=8008):
     # type: (builtin.controllers.AMri, APort) -> None
     super(HTTPServerComms, self).__init__(mri)
     self.port = port
     self._server = None  # type: HTTPServer
     self._server_started = False
     self._application = None  # type: Application
     self._published = []  # type: List[str]
     self.blocks = StringArrayMeta("List of local Blocks to serve up",
                                   tags=[Widget.TEXTUPDATE.tag()
                                         ]).create_attribute_model()
     self.field_registry.add_attribute_model("blocks", self.blocks)
     # Hooks
     self.register_hooked(ProcessPublishHook, self.publish)
Ejemplo n.º 8
0
 def __init__(self,
              name: APartName = "simultaneousAxes",
              value: USimultaneousAxes = None) -> None:
     super().__init__(name)
     self.attr = StringArrayMeta(
         "Set of axes that can be specified in axesToMove at configure",
         tags=[Widget.TEXTINPUT.tag(), config_tag()],
     ).create_attribute_model(value)
Ejemplo n.º 9
0
class TestStringArrayMeta(unittest.TestCase):
    def setUp(self):
        self.meta = StringArrayMeta("test description")

    def test_init(self):
        assert "test description" == self.meta.description
        assert self.meta.label == ""
        assert self.meta.typeid == "malcolm:core/StringArrayMeta:1.0"

    def test_validate_none(self):
        assert self.meta.validate(None) == []

    def test_validate_array(self):
        array = ["test_string", 123, 123.456]
        with self.assertRaises(AssertionError):
            self.meta.validate(array)

    def test_not_iterable_raises(self):
        value = 12346
        with self.assertRaises(AssertionError):
            self.meta.validate(value)

    def test_null_element_raises(self):
        array = ["test", None]
        with self.assertRaises(AssertionError):
            self.meta.validate(array)
Ejemplo n.º 10
0
 def __init__(self, name="simultaneousAxes", value=None):
     # type: (APartName, USimultaneousAxes) -> None
     super(SimultaneousAxesPart, self).__init__(name)
     self.attr = StringArrayMeta(
         "Set of axes that can be specified in axesToMove at configure",
         tags=[Widget.TEXTINPUT.tag(),
               config_tag()]).create_attribute_model(value)
     # Hooks
     self.register_hooked(ValidateHook, self.validate)
Ejemplo n.º 11
0
 def setUp(self):
     elements = OrderedDict()
     elements["foo"] = StringArrayMeta(label="Foo").to_dict()
     elements["bar"] = StringArrayMeta().to_dict()
     meta = OrderedDict()
     meta["typeid"] = "malcolm:core/TableMeta:1.0"
     meta["description"] = "desc"
     meta["tags"] = []
     meta["writeable"] = True
     meta["label"] = "my label"
     meta["elements"] = elements
     value = OrderedDict()
     value["typeid"] = "malcolm:core/Table:1.0"
     value["foo"] = ["foo1", "foo2"]
     value["bar"] = ["bar1", "bar2"]
     self.serialized = OrderedDict()
     self.serialized["typeid"] = "epics:nt/NTTable:1.0"
     self.serialized["labels"] = ["Foo", "bar"]
     self.serialized["value"] = value
     self.serialized["alarm"] = Alarm().to_dict()
     self.serialized["timeStamp"] = TimeStamp().to_dict()
     self.serialized["meta"] = meta
Ejemplo n.º 12
0
class TestMapMeta(unittest.TestCase):

    def test_values_set(self):
        self.assertIsInstance(self.mm.elements, dict)
        assert len(self.mm.elements) == 0
        assert self.mm.typeid == "malcolm:core/MapMeta:1.0"

    def test_set_elements(self):
        els = dict(sam=StringArrayMeta())
        self.mm.set_elements(els)
        assert self.mm.elements == els

    def test_set_required(self):
        self.test_set_elements()
        req = ("sam",)
        self.mm.set_required(req)
        assert self.mm.required == req

    def setUp(self):
        self.mm = MapMeta()
        self.sam = StringArrayMeta()
        self.serialized = OrderedDict()
        self.serialized["typeid"] = "malcolm:core/MapMeta:1.0"
        self.serialized["elements"] = dict(c1=self.sam.to_dict())
        self.serialized["elements"]["c1"]["label"] = "C1"
        self.serialized["required"] = ["c1"]

    def test_to_dict(self):
        tm = MapMeta()
        tm.set_elements(dict(c1=self.sam))
        tm.set_required(["c1"])
        assert tm.to_dict() == self.serialized

    def test_from_dict(self):
        tm = MapMeta.from_dict(self.serialized)
        assert len(tm.elements) == 1
        expected = self.sam.to_dict()
        expected["label"] = "C1"
        assert tm.elements["c1"].to_dict() == expected
Ejemplo n.º 13
0
 def __init__(
     self,
     mri,  # type: builtin.controllers.AMri
     hostname="localhost",  # type: AHostname
     port=8008,  # type: APort
     connect_timeout=DEFAULT_TIMEOUT  # type: AConnectTimeout
 ):
     # type: (...) -> None
     super(WebsocketClientComms, self).__init__(mri)
     self.hostname = hostname
     self.port = port
     self.connect_timeout = connect_timeout
     self._connected_queue = Queue()
     # {new_id: request}
     self._request_lookup = {}  # type: Dict[int, Request]
     self._next_id = 1
     self._conn = None  # type: WebSocketClientConnection
     # Create read-only attribute for the remotely reachable blocks
     self.remote_blocks = StringArrayMeta("Remotely reachable blocks",
                                          tags=[Widget.TEXTINPUT.tag()
                                                ]).create_attribute_model()
     self.field_registry.add_attribute_model("remoteBlocks",
                                             self.remote_blocks)
Ejemplo n.º 14
0
class HTTPServerComms(builtin.controllers.ServerComms):
    """A class for communication between browser and server"""
    def __init__(self, mri, port=8008):
        # type: (builtin.controllers.AMri, APort) -> None
        super(HTTPServerComms, self).__init__(mri)
        self.port = port
        self._server = None  # type: HTTPServer
        self._server_started = False
        self._application = None  # type: Application
        self._published = []  # type: List[str]
        self.blocks = StringArrayMeta("List of local Blocks to serve up",
                                      tags=[Widget.TEXTUPDATE.tag()
                                            ]).create_attribute_model()
        self.field_registry.add_attribute_model("blocks", self.blocks)
        # Hooks
        self.register_hooked(ProcessPublishHook, self.publish)

    def do_init(self):
        super(HTTPServerComms, self).do_init()
        part_info = self.run_hooks(
            ReportHandlersHook(part) for part in self.parts.values())
        handler_infos = HandlerInfo.filter_values(part_info)
        handlers = []
        for handler_info in handler_infos:
            handlers.append((handler_info.regexp, handler_info.request_class,
                             handler_info.kwargs))
        self._application = Application(handlers)
        self._server = HTTPServer(self._application)

    def _start_server(self):
        if not self._server_started:
            IOLoopHelper.call(self._server.listen, int(self.port))
            self._server_started = True

    def _stop_server(self):
        if self._server_started:
            IOLoopHelper.call(self._server.stop)
            self._server_started = False

    def do_disable(self):
        super(HTTPServerComms, self).do_disable()
        self._stop_server()

    def do_reset(self):
        super(HTTPServerComms, self).do_reset()
        self._start_server()

    @add_call_types
    def publish(self, published):
        # type: (APublished) -> None
        self._published = published
        self.blocks.set_value(published)
        # Start server if not already started
        self._start_server()

    def update_request_received(self, part, info):
        # type: (Part, builtin.infos.RequestInfo) -> None
        if info.mri == ".":
            # This is for us
            controller = self
        else:
            controller = self.process.get_controller(info.mri)
        cothread.Callback(controller.handle_request, info.request)
Ejemplo n.º 15
0
class TestTableMeta(unittest.TestCase):
    def test_init(self):
        tm = TableMeta("desc")
        assert "desc" == tm.description
        assert "malcolm:core/TableMeta:1.0" == tm.typeid
        assert [] == tm.tags
        assert False is tm.writeable
        assert "" == tm.label

    def setUp(self):
        tm = TableMeta("desc")
        self.tm = tm
        self.tm.set_elements(dict(c1=StringArrayMeta()))
        self.sam = StringArrayMeta()
        self.serialized = OrderedDict()
        self.serialized["typeid"] = "malcolm:core/TableMeta:1.0"
        self.serialized["description"] = "desc"
        self.serialized["tags"] = []
        self.serialized["writeable"] = True
        self.serialized["label"] = "Name"
        self.serialized["elements"] = dict(c1=self.sam.to_dict())

    def test_set_elements(self):
        tm = self.tm
        elements = OrderedDict()
        elements["col1"] = StringArrayMeta()
        elements["col2"] = StringArrayMeta()
        tm.set_elements(elements)
        assert elements == tm.elements

    def test_set_elements_from_serialized(self):
        tm = self.tm
        elements = OrderedDict()
        elements["col1"] = StringArrayMeta().to_dict()
        elements["col2"] = StringArrayMeta().to_dict()
        tm.set_elements(elements)
        assert isinstance(tm.elements["col1"], StringArrayMeta)
        assert tm.elements["col1"].to_dict() == elements["col1"]

    def test_to_dict(self):
        tm = TableMeta("desc")
        tm.set_label("Name")
        tm.set_writeable(True)
        tm.set_elements(dict(c1=self.sam))
        assert tm.to_dict() == self.serialized

    def test_from_dict(self):
        tm = TableMeta.from_dict(self.serialized)
        assert tm.description == "desc"
        assert len(tm.elements) == 1
        assert tm.elements["c1"].to_dict() == self.sam.to_dict()
        assert tm.tags == []
        assert tm.writeable is True
        assert tm.label == "Name"

    def test_validate_from_good_table(self):
        tm = self.tm
        t = tm.table_cls(c1=["me", "me3"])
        t_serialized = t.to_dict()
        t = tm.validate(t)
        assert t.to_dict() == t_serialized

    def test_validate_from_serialized(self):
        tm = self.tm
        serialized = dict(typeid="anything", c1=("me", "me3"))
        t = tm.validate(serialized)
        assert list(t) == ["c1"]
        assert t.c1 == serialized["c1"]
Ejemplo n.º 16
0
 def setUp(self):
     self.meta = StringArrayMeta("test description")
Ejemplo n.º 17
0
 def test_set_elements(self):
     els = dict(sam=StringArrayMeta())
     self.mm.set_elements(els)
     assert self.mm.elements == els