From ac251ea5159a05c08f37edc2517e90efd02a3854 Mon Sep 17 00:00:00 2001 From: Alexander Zaft Date: Thu, 4 Apr 2024 09:05:35 +0200 Subject: [PATCH] test: add uri attach test Change-Id: I8a021c53c9987ed03ce31c8481f73573b943d1f3 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/33417 Tested-by: Jenkins Automated Tests Reviewed-by: Alexander Zaft --- test/test_attach.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_attach.py b/test/test_attach.py index 551feda..5d943d8 100644 --- a/test/test_attach.py +++ b/test/test_attach.py @@ -19,6 +19,7 @@ # # ***************************************************************************** +from frappy.io import HasIO from frappy.modules import Module, Attached from frappy.protocol.dispatcher import Dispatcher @@ -29,6 +30,9 @@ class LoggerStub: info = warning = exception = debug handlers = [] + def getChild(self, name): + return self + logger = LoggerStub() @@ -51,6 +55,7 @@ class ServerStub: def __init__(self): self.secnode = SecNodeStub() self.dispatcher = Dispatcher('dispatcher', logger, {}, self) + self.log = logger def test_attach(): @@ -64,3 +69,22 @@ def test_attach(): srv.secnode.add_module(a, 'a') srv.secnode.add_module(m, 'm') assert m.att == a + + +def test_attach_hasio_uri(): + class TestIO(Module): + def __init__(self, name, logger, cfgdict, srv): + self._uri = cfgdict.pop('uri') + super().__init__(name, logger, cfgdict, srv) + + class HasIOTest(HasIO): + ioClass = TestIO + + srv = ServerStub() + m = HasIOTest('m', logger, {'description': '', 'uri': 'abc'}, srv) + assert srv.secnode.modules['m_io']._uri == 'abc' + assert m.io == srv.secnode.modules['m_io'] + # two modules with the same IO should use the same io module + m2 = HasIOTest('m', logger, {'description': '', 'uri': 'abc'}, srv) + assert m2.io == srv.secnode.modules['m_io'] +