From 0c93b1257e3da7b7dd496ac5a8b87b8dbea93737 Mon Sep 17 00:00:00 2001 From: Jan Rinze Peterzon <peterzon@astron.nl> Date: Thu, 15 Oct 2015 09:06:46 +0000 Subject: [PATCH] Task #8571: Convert all Apertif to Lofar in python messaging/common library. --- LCS/MessageBus/python/common/CMakeLists.txt | 2 +- LCS/MessageBus/python/common/factory.py | 8 +- LCS/MessageBus/python/common/util.py | 12 +-- LCS/MessageBus/python/examples/ToUpperClient | 2 +- .../python/examples/ToUpperMapClient | 2 +- LCS/MessageBus/python/examples/ToUpperService | 2 +- .../python/messaging/CMakeLists.txt | 2 +- LCS/MessageBus/python/messaging/RPC.py | 4 +- LCS/MessageBus/python/messaging/Service.py | 4 +- LCS/MessageBus/python/messaging/__init__.py | 8 +- LCS/MessageBus/python/messaging/exceptions.py | 14 +-- LCS/MessageBus/python/messaging/messagebus.py | 14 +-- LCS/MessageBus/python/messaging/messages.py | 46 ++++---- .../python/messaging/test/t_messagebus.py | 20 ++-- .../python/messaging/test/t_messages.py | 102 +++++++++--------- 15 files changed, 121 insertions(+), 121 deletions(-) diff --git a/LCS/MessageBus/python/common/CMakeLists.txt b/LCS/MessageBus/python/common/CMakeLists.txt index 3fcff6966fe..d419ad2ef75 100644 --- a/LCS/MessageBus/python/common/CMakeLists.txt +++ b/LCS/MessageBus/python/common/CMakeLists.txt @@ -10,4 +10,4 @@ set(_py_files factory.py util.py) -python_install(${_py_files} DESTINATION common) +python_install(${_py_files} DESTINATION lofar/common) diff --git a/LCS/MessageBus/python/common/factory.py b/LCS/MessageBus/python/common/factory.py index acebc53ad66..a80c6137e0a 100644 --- a/LCS/MessageBus/python/common/factory.py +++ b/LCS/MessageBus/python/common/factory.py @@ -4,19 +4,19 @@ # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: factory.py 1584 2015-10-02 12:10:14Z loose $ diff --git a/LCS/MessageBus/python/common/util.py b/LCS/MessageBus/python/common/util.py index 585032a8ecd..100ac836e25 100644 --- a/LCS/MessageBus/python/common/util.py +++ b/LCS/MessageBus/python/common/util.py @@ -1,27 +1,27 @@ -# util.py: utils for apertif software +# util.py: utils for lofar software # # Copyright (C) 2015 # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: util.py 1584 2015-10-02 12:10:14Z loose $ # """ -This package contains different utilities that are common for APERTIF software +This package contains different utilities that are common for LOFAR software """ import sys diff --git a/LCS/MessageBus/python/examples/ToUpperClient b/LCS/MessageBus/python/examples/ToUpperClient index ff4bc97f020..fcc226e4115 100755 --- a/LCS/MessageBus/python/examples/ToUpperClient +++ b/LCS/MessageBus/python/examples/ToUpperClient @@ -1,6 +1,6 @@ #!/usr/bin/python -from messaging.RPC import RPC +from lofar.messaging.RPC import RPC # Simple RPC client for Service 'ToUpper' diff --git a/LCS/MessageBus/python/examples/ToUpperMapClient b/LCS/MessageBus/python/examples/ToUpperMapClient index 65a73aad4e8..0171a003a2a 100755 --- a/LCS/MessageBus/python/examples/ToUpperMapClient +++ b/LCS/MessageBus/python/examples/ToUpperMapClient @@ -1,7 +1,7 @@ #!/usr/bin/python #from messagebus.RPC import RPC -from messaging.RPC import RPC +from lofar.messaging.RPC import RPC # Simple RPC client for Service 'ToUpper' diff --git a/LCS/MessageBus/python/examples/ToUpperService b/LCS/MessageBus/python/examples/ToUpperService index 89e3faaae9e..7bd3f2004fe 100755 --- a/LCS/MessageBus/python/examples/ToUpperService +++ b/LCS/MessageBus/python/examples/ToUpperService @@ -1,6 +1,6 @@ #!/usr/bin/python -from messaging.Service import Service +from lofar.messaging.Service import Service # Simple RPC server 'ToUpper' diff --git a/LCS/MessageBus/python/messaging/CMakeLists.txt b/LCS/MessageBus/python/messaging/CMakeLists.txt index 8a20caa152a..142cd51e6ae 100644 --- a/LCS/MessageBus/python/messaging/CMakeLists.txt +++ b/LCS/MessageBus/python/messaging/CMakeLists.txt @@ -13,6 +13,6 @@ set(_py_files Service.py ) -python_install(${_py_files} DESTINATION messaging) +python_install(${_py_files} DESTINATION lofar/messaging) add_subdirectory(test) diff --git a/LCS/MessageBus/python/messaging/RPC.py b/LCS/MessageBus/python/messaging/RPC.py index 6a111ac060e..14d0f3c82d5 100644 --- a/LCS/MessageBus/python/messaging/RPC.py +++ b/LCS/MessageBus/python/messaging/RPC.py @@ -1,7 +1,7 @@ # RPC invocation with possible timeout -from messaging.messagebus import ToBus,FromBus -from messaging.messages import ServiceMessage +from lofar.messaging.messagebus import ToBus,FromBus +from lofar.messaging.messages import ServiceMessage import uuid diff --git a/LCS/MessageBus/python/messaging/Service.py b/LCS/MessageBus/python/messaging/Service.py index 84403777b08..4248ade8fce 100644 --- a/LCS/MessageBus/python/messaging/Service.py +++ b/LCS/MessageBus/python/messaging/Service.py @@ -1,7 +1,7 @@ #!/usr/bin/python -from messaging.messagebus import ToBus,FromBus -from messaging.messages import EventMessage +from lofar.messaging.messagebus import ToBus,FromBus +from lofar.messaging.messages import EventMessage import threading import time import uuid diff --git a/LCS/MessageBus/python/messaging/__init__.py b/LCS/MessageBus/python/messaging/__init__.py index af1929824be..a4c4ecb5dc1 100644 --- a/LCS/MessageBus/python/messaging/__init__.py +++ b/LCS/MessageBus/python/messaging/__init__.py @@ -4,19 +4,19 @@ # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: __init__.py 1568 2015-09-18 15:21:11Z loose $ diff --git a/LCS/MessageBus/python/messaging/exceptions.py b/LCS/MessageBus/python/messaging/exceptions.py index 2be36a19b0a..32e837f3c3b 100644 --- a/LCS/MessageBus/python/messaging/exceptions.py +++ b/LCS/MessageBus/python/messaging/exceptions.py @@ -1,32 +1,32 @@ -# exceptions.py: Exceptions used by the apertif.messaging module. +# exceptions.py: Exceptions used by the lofar.messaging module. # # Copyright (C) 2015 # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: exceptions.py 1580 2015-09-30 14:18:57Z loose $ """ -Exceptions used by the apertif.messaging module. +Exceptions used by the lofar.messaging module. """ class MessagingError(Exception): """ - Base exception class for the apertif.messaging package. + Base exception class for the lofar.messaging package. """ pass diff --git a/LCS/MessageBus/python/messaging/messagebus.py b/LCS/MessageBus/python/messaging/messagebus.py index 7946c19f3db..a6cc7b208c4 100644 --- a/LCS/MessageBus/python/messaging/messagebus.py +++ b/LCS/MessageBus/python/messaging/messagebus.py @@ -4,19 +4,19 @@ # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: messagebus.py 1580 2015-09-30 14:18:57Z loose $ @@ -24,9 +24,9 @@ Provide an easy way exchange messages on the message bus. """ -from .exceptions import MessageBusError, MessageFactoryError -from .messages import to_qpid_message, MESSAGE_FACTORY -from common.util import raise_exception +from lofar.messaging.exceptions import MessageBusError, MessageFactoryError +from lofar.messaging.messages import to_qpid_message, MESSAGE_FACTORY +from lofar.common.util import raise_exception import qpid.messaging import logging diff --git a/LCS/MessageBus/python/messaging/messages.py b/LCS/MessageBus/python/messaging/messages.py index cbf1fc1c80b..cb531fb525e 100644 --- a/LCS/MessageBus/python/messaging/messages.py +++ b/LCS/MessageBus/python/messaging/messages.py @@ -1,34 +1,34 @@ -# messages.py: Message classes used by the package apertif.messaging. +# messages.py: Message classes used by the package lofar.messaging. # # Copyright (C) 2015 # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: messages.py 1580 2015-09-30 14:18:57Z loose $ """ -Message classes used by the package apertif.messaging. +Message classes used by the package lofar.messaging. """ import qpid.messaging import uuid -from common.factory import Factory -from .exceptions import InvalidMessage, MessageFactoryError +from lofar.common.factory import Factory +from lofar.messaging.exceptions import InvalidMessage, MessageFactoryError # Valid QPID message fields (from qpid.messaging.Message) @@ -41,7 +41,7 @@ def validate_qpid_message(qmsg): """ Validate Qpid message `qmsg`. A Qpid message is required to contain the following properties in order to be considered valid: - - "SystemName" : "APERTIF" + - "SystemName" : "LOFAR" - "MessageType" : message type string - "MessageId" : a valid UUID string :raises InvalidMessage: if any of the required properties are missing in @@ -71,7 +71,7 @@ def validate_qpid_message(qmsg): ("ies" if len(missing_props) > 1 else "y", ', '.join(missing_props)) ) sysname, _, msgid = (msg_props[prop] for prop in required_props) - if sysname != "APERTIF": + if sysname != "LOFAR": raise InvalidMessage( "Invalid message property 'SystemName': %s" % sysname ) @@ -92,22 +92,22 @@ def to_qpid_message(msg): """ if isinstance(msg, qpid.messaging.Message): return msg - if isinstance(msg, ApertifMessage): + if isinstance(msg, LofarMessage): return msg.qpid_msg raise InvalidMessage("Invalid message type: %r" % type(msg)) class MessageFactory(Factory): """ - Factory to produce ApertifMessage objects. + Factory to produce LofarMessage objects. """ def create(self, qmsg): """ Override the create method to restrict the number of arguments to one and to do some extra testing. - :param qmsg: Qpid message that must be converted into an ApertifMessage. - :return: Instance of a child class of ApertifMessage. + :param qmsg: Qpid message that must be converted into an LofarMessage. + :return: Instance of a child class of LofarMessage. :raise MessageFactoryError: if the MessageType property of the Qpid message `qmsg` contains a type name that is not registered with the factory. @@ -122,11 +122,11 @@ class MessageFactory(Factory): return msg -# Global MessageFactory object, to be used by the apertif.messaging package, +# Global MessageFactory object, to be used by the lofar.messaging package, MESSAGE_FACTORY = MessageFactory() -class ApertifMessage(object): +class LofarMessage(object): """ Describes the content of a message, which can be constructed from either a set of fields, or from an existing QPID message. @@ -144,9 +144,9 @@ class ApertifMessage(object): :param content: Content can either be a qpid.messaging.Message object, or an object that is valid content for a qpid.messaging.Message. In the first case, `content` must contain all the message properties that are - required by APERTIF. + required by LOFAR. :raise InvalidMessage if `content` cannot be used to initialize an - ApertifMessage object. + LofarMessage object. note:: Because every access to attributes will be caught by `__getattr__` and `__setattr__`, we need to use `self.__dict__` to @@ -164,7 +164,7 @@ class ApertifMessage(object): "Unsupported content type: %r" % type(content)) else: self._qpid_msg.properties.update({ - 'SystemName': 'APERTIF', + 'SystemName': 'LOFAR', 'MessageId': str(uuid.uuid4()), 'MessageType': self.__class__.__name__}) @@ -235,7 +235,7 @@ class ApertifMessage(object): print "===" -class EventMessage(ApertifMessage): +class EventMessage(LofarMessage): """ Message class used for event messages. Events are messages that *must* be delivered. If the message cannot be delivered to the recipient, it @@ -247,7 +247,7 @@ class EventMessage(ApertifMessage): self.durable = True -class MonitoringMessage(ApertifMessage): +class MonitoringMessage(LofarMessage): """ Message class used for monitoring messages. Monitoring messages are publish-subscribe type of messages. They will be not be queued, so they @@ -258,7 +258,7 @@ class MonitoringMessage(ApertifMessage): super(MonitoringMessage, self).__init__(content) -class ProgressMessage(ApertifMessage): +class ProgressMessage(LofarMessage): """ Message class used for progress messages. Progress messages are publish-subscribe type of messages. They will be not be queued, so they @@ -269,7 +269,7 @@ class ProgressMessage(ApertifMessage): super(ProgressMessage, self).__init__(content) -class ServiceMessage(ApertifMessage): +class ServiceMessage(LofarMessage): """ Message class used for service messages. Service messages are request-reply type of messages. They are typically used to query a diff --git a/LCS/MessageBus/python/messaging/test/t_messagebus.py b/LCS/MessageBus/python/messaging/test/t_messagebus.py index 946e6056e2e..4bd9fb998ed 100644 --- a/LCS/MessageBus/python/messaging/test/t_messagebus.py +++ b/LCS/MessageBus/python/messaging/test/t_messagebus.py @@ -1,27 +1,27 @@ -# t_messagebus.py: Test program for the module apertif.messaging.messagebus +# t_messagebus.py: Test program for the module lofar.messaging.messagebus # # Copyright (C) 2015 # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: t_messagebus.py 1580 2015-09-30 14:18:57Z loose $ """ -Test program for the module apertif.messaging.messagebus +Test program for the module lofar.messaging.messagebus """ import re @@ -29,9 +29,9 @@ import struct import sys import unittest -from apertif.messaging.messages import * -from apertif.messaging.messagebus import * -from apertif.messaging.exceptions import MessageBusError, InvalidMessage +from lofar.messaging.messages import * +from lofar.messaging.messagebus import * +from lofar.messaging.exceptions import MessageBusError, InvalidMessage TIMEOUT = 0.1 @@ -220,7 +220,7 @@ class ToBusSendMessage(unittest.TestCase): def test_send_invalid_message_raises(self): """ - If an invalid message is sent (i.e., not an ApertifMessage), then an + If an invalid message is sent (i.e., not an LofarMessage), then an InvalidMessage must be raised. """ with self.tobus: diff --git a/LCS/MessageBus/python/messaging/test/t_messages.py b/LCS/MessageBus/python/messaging/test/t_messages.py index 754e7c68ff6..b83c4891794 100644 --- a/LCS/MessageBus/python/messaging/test/t_messages.py +++ b/LCS/MessageBus/python/messaging/test/t_messages.py @@ -1,52 +1,52 @@ -# t_message.py: Test program for the module apertif.messaging.message +# t_message.py: Test program for the module lofar.messaging.message # # Copyright (C) 2015 # ASTRON (Netherlands Institute for Radio Astronomy) # P.O.Box 2, 7990 AA Dwingeloo, The Netherlands # -# This file is part of the APERTIF software suite. -# The APERTIF software suite is free software: you can redistribute it +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it # and/or modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # -# The APERTIF software suite is distributed in the hope that it will be +# The LOFAR software suite is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with the APERTIF software suite. If not, see <http://www.gnu.org/licenses/>. +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # # $Id: t_messages.py 1576 2015-09-29 15:22:28Z loose $ """ -Test program for the module apertif.messaging.message +Test program for the module lofar.messaging.message """ import unittest import uuid import struct import qpid.messaging -from apertif.messaging.messages import ApertifMessage, InvalidMessage +from lofar.messaging.messages import LofarMessage, InvalidMessage -class DefaultApertifMessage(unittest.TestCase): +class DefaultLofarMessage(unittest.TestCase): """ - Class to test default constructed ApertifMessage class + Class to test default constructed LofarMessage class """ def setUp(self): """ Create default constructed object """ - self.message = ApertifMessage() + self.message = LofarMessage() def test_system_name(self): """ - Object attribute SystemName must be set to 'APERTIF' + Object attribute SystemName must be set to 'LOFAR' """ - self.assertEqual(self.message.SystemName, "APERTIF") + self.assertEqual(self.message.SystemName, "LOFAR") def test_message_id(self): """ @@ -55,9 +55,9 @@ class DefaultApertifMessage(unittest.TestCase): self.assertIsNotNone(uuid.UUID(self.message.MessageId)) -class QpidApertifMessage(unittest.TestCase): +class QpidLofarMessage(unittest.TestCase): """ - Class to test ApertifMessage constructed from a Qpid message + Class to test LofarMessage constructed from a Qpid message """ def setUp(self): @@ -66,7 +66,7 @@ class QpidApertifMessage(unittest.TestCase): """ self.qmsg = qpid.messaging.Message() self.qmsg.properties = { - "SystemName": "APERTIF", + "SystemName": "LOFAR", "MessageType": None, "MessageId": str(uuid.uuid4()) } @@ -79,7 +79,7 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties = 42 self.assertRaisesRegexp(InvalidMessage, "^Invalid message properties type:", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_illegal_properties(self): """ @@ -89,17 +89,17 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties['content'] = 'blah blah blah' self.assertRaisesRegexp(InvalidMessage, "^Illegal message propert(y|ies).*:", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_missing_properties(self): """ Test that exception is raised if required properties for constructing - an ApertifMessage are missing. + an LofarMessage are missing. """ self.qmsg.properties = {} self.assertRaisesRegexp(InvalidMessage, "^Missing message propert(y|ies):", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_missing_property_systemname(self): """ @@ -109,7 +109,7 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties.pop("SystemName") self.assertRaisesRegexp(InvalidMessage, "^Missing message property: SystemName", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_missing_property_messageid(self): """ @@ -119,7 +119,7 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties.pop("MessageId") self.assertRaisesRegexp(InvalidMessage, "^Missing message property: MessageId", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_missing_property_messagetype(self): """ @@ -129,17 +129,17 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties.pop("MessageType") self.assertRaisesRegexp(InvalidMessage, "^Missing message property: MessageType", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_invalid_property_systemname(self): """ Test that exception is raised if 'SystemName' has wrong value (i.e. - not equal to 'APERTIF') + not equal to 'LOFAR') """ self.qmsg.properties["SystemName"] = "LOFAR" self.assertRaisesRegexp(InvalidMessage, "^Invalid message property 'SystemName':", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_invalid_property_messageid(self): """ @@ -149,13 +149,13 @@ class QpidApertifMessage(unittest.TestCase): self.qmsg.properties["MessageId"] = "Invalid-UUID-string" self.assertRaisesRegexp(InvalidMessage, "^Invalid message property 'MessageId':", - ApertifMessage, self.qmsg) + LofarMessage, self.qmsg) def test_getattr_raises(self): """ Test that exception is raised if a non-existent attribute is read. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) with self.assertRaisesRegexp(AttributeError, "object has no attribute"): _ = msg.non_existent @@ -164,7 +164,7 @@ class QpidApertifMessage(unittest.TestCase): Test that exception is raised if attribute 'properties' is read. This attribute should not be visible. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) with self.assertRaisesRegexp(AttributeError, "object has no attribute"): _ = msg.properties @@ -173,42 +173,42 @@ class QpidApertifMessage(unittest.TestCase): Test that exception is raised if attribute 'properties' is written. This attribute should not be visible. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) with self.assertRaisesRegexp(AttributeError, "object has no attribute"): msg.properties = {} def test_getattr_qpid_field(self): """ - Test that a Qpid message field becomes an ApertifMessage attribute. + Test that a Qpid message field becomes an LofarMessage attribute. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) msg.qpid_msg.ttl = 100 self.assertEqual(self.qmsg.ttl, msg.ttl) self.assertEqual(msg.ttl, 100) def test_setattr_qpid_field(self): """ - Test that an ApertifMessage attribute becomes a Qpid message field. + Test that an LofarMessage attribute becomes a Qpid message field. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) msg.ttl = 100 self.assertEqual(self.qmsg.ttl, msg.ttl) self.assertEqual(self.qmsg.ttl, 100) def test_getattr_qpid_property(self): """ - Test that a Qpid message property becomes an ApertifMessage attribute. + Test that a Qpid message property becomes an LofarMessage attribute. """ self.qmsg.properties["NewProperty"] = "New Property" - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) self.assertEqual(msg.qpid_msg.properties["NewProperty"], msg.NewProperty) def test_setattr_qpid_property(self): """ - Test that an ApertifMessage attribute becomes a Qpid message property. + Test that an LofarMessage attribute becomes a Qpid message property. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) msg.NewProperty = "New Property" self.assertEqual(msg.qpid_msg.properties["NewProperty"], msg.NewProperty) @@ -218,71 +218,71 @@ class QpidApertifMessage(unittest.TestCase): Test that prop_names() does not return the property 'properties'. This attribute should not be visible. """ - msg = ApertifMessage(self.qmsg) + msg = LofarMessage(self.qmsg) self.assertNotIn('properties', msg.prop_names()) -class ContentApertifMessage(unittest.TestCase): +class ContentLofarMessage(unittest.TestCase): """ - Class to test that an ApertifMessage can be constructed from different types + Class to test that an LofarMessage can be constructed from different types of content. The content is used to initialize a Qpid Message object. """ def test_construct_from_string(self): """ - Test that an ApertifMessage can be constructed from an ASCII string. + Test that an LofarMessage can be constructed from an ASCII string. """ content = "ASCII string" - msg = ApertifMessage(content) + msg = LofarMessage(content) self.assertEqual((msg.content, msg.content_type), (content, None)) def test_construct_from_unicode(self): """ - Test that an ApertifMessage can be constructed from a Unicode string. + Test that an LofarMessage can be constructed from a Unicode string. :return: """ content = u"Unicode string" - msg = ApertifMessage(content) + msg = LofarMessage(content) self.assertEqual((msg.content, msg.content_type), (content, "text/plain")) def test_construct_from_list(self): """ - Test that an ApertifMessage can be constructed from a python list. + Test that an LofarMessage can be constructed from a python list. """ content = range(10) - msg = ApertifMessage(content) + msg = LofarMessage(content) self.assertEqual((msg.content, msg.content_type), (content, "amqp/list")) def test_construct_from_dict(self): """ - Test that an ApertifMessage can be constructed from a python dict. + Test that an LofarMessage can be constructed from a python dict. """ content = {1: 'one', 2: 'two', 3: 'three'} - msg = ApertifMessage(content) + msg = LofarMessage(content) self.assertEqual((msg.content, msg.content_type), (content, "amqp/map")) def test_construct_from_binary(self): """ - Test that an ApertifMessage can be constructed from binary data. + Test that an LofarMessage can be constructed from binary data. Use struct.pack() to create a byte array """ content = struct.pack("<256B", *range(256)) - msg = ApertifMessage(content) + msg = LofarMessage(content) self.assertEqual((msg.content, msg.content_type), (content, None)) def test_construct_from_unsupported(self): """ - Test that an ApertifMessage cannot be constructed from unsupported + Test that an LofarMessage cannot be constructed from unsupported data type like 'int'. """ content = 42 self.assertRaisesRegexp(InvalidMessage, "^Unsupported content type:", - ApertifMessage, content) + LofarMessage, content) if __name__ == '__main__': -- GitLab