Adapt message order in some tests.
authorBenjamin Braatz <bb@bbraatz.eu>
Sun, 21 Mar 2021 02:03:28 +0000 (03:03 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Sun, 21 Mar 2021 02:03:28 +0000 (03:03 +0100)
controlpi-plugins/util.py
controlpi/__init__.py

index d3b42fd805ce91db7e8829375eba4b85e74df48e..313e50b8a987c226e1899edb198e511623d322eb 100644 (file)
@@ -4,7 +4,6 @@
 - Init sends list of messages on startup and on demand.
 - Alias translates messages to an alias.
 
->>> import asyncio
 >>> import controlpi
 >>> asyncio.run(controlpi.test(
 ...     {"Test Log": {"plugin": "Log",
@@ -37,6 +36,8 @@ test(): {'sender': 'Test Alias', 'id': 'translated',
 Test Log: {'sender': 'Test Alias', 'id': 'translated',
            'content': 'Test Message'}
 """
+import asyncio
+
 from controlpi import BasePlugin, Message, MessageTemplate
 
 
@@ -50,7 +51,6 @@ class Log(BasePlugin):
     template and are logged by the instance "Test Log", while the second
     message does not match and is only logged by the test, but not by the
     Log instance:
-    >>> import asyncio
     >>> import controlpi
     >>> asyncio.run(controlpi.test(
     ...     {"Test Log": {"plugin": "Log",
@@ -130,7 +130,6 @@ class Init(BasePlugin):
     In the example, the two configured messages are sent twice, once at
     startup and a second time in reaction to the "execute" command sent by
     the test:
-    >>> import asyncio
     >>> import controlpi
     >>> asyncio.run(controlpi.test(
     ...     {"Test Init": {"plugin": "Init",
@@ -197,6 +196,8 @@ class Init(BasePlugin):
         """Send configured messages."""
         for message in self.conf['messages']:
             await self.bus.send(Message(self.name, message))
+            # Give immediate reactions to messages opportunity to happen:
+            await asyncio.sleep(0)
 
     def process_conf(self) -> None:
         """Register plugin as bus client."""
@@ -222,7 +223,6 @@ class Execute(BasePlugin):
 
     In the example, the first command sent by the test sets two messages,
     which are then sent in reaction to the second command sent by the test:
-    >>> import asyncio
     >>> import controlpi
     >>> asyncio.run(controlpi.test(
     ...     {"Test Execute": {"plugin": "Execute"}},
@@ -266,6 +266,8 @@ class Execute(BasePlugin):
         elif message['command'] == 'execute':
             for message in self.messages:
                 await self.bus.send(Message(self.name, message))
+                # Give immediate reactions to messages opportunity to happen:
+                await asyncio.sleep(0)
 
     def process_conf(self) -> None:
         """Register plugin as bus client."""
@@ -298,7 +300,6 @@ class Alias(BasePlugin):
     In the example, the two messages sent by the test are translated by the
     Alias instance and the translated messages are sent by it preserving
     the "content" keys:
-    >>> import asyncio
     >>> import controlpi
     >>> asyncio.run(controlpi.test(
     ...     {"Test Alias": {"plugin": "Alias",
@@ -313,10 +314,10 @@ class Alias(BasePlugin):
              'receives': [{'id': {'const': 42}}]}
     test(): {'sender': 'test()', 'id': 42,
              'content': 'Test Message'}
-    test(): {'sender': 'test()', 'id': 42,
-             'content': 'Second Message'}
     test(): {'sender': 'Test Alias', 'id': 'translated',
              'content': 'Test Message'}
+    test(): {'sender': 'test()', 'id': 42,
+             'content': 'Second Message'}
     test(): {'sender': 'Test Alias', 'id': 'translated',
              'content': 'Second Message'}
 
index 22d4e9edc43fa4edfc9cb3336b2c354488499e06..e3e5d5676e997965737bdc1c46846ee0d0181912 100644 (file)
@@ -168,6 +168,6 @@ async def test(conf: Dict[str, PluginConf],
         await asyncio.sleep(0)
     for message in messages:
         await message_bus.send(Message('test()', message))
-        # Give immediate reactions to these messages opportunity to happen:
+        # Give immediate reactions to messages opportunity to happen:
         await asyncio.sleep(0)
     await message_bus._queue.join()