Home | History | Annotate | Download | only in layout_package
      1 # Copyright (C) 2011 Google Inc. All rights reserved.
      2 #
      3 # Redistribution and use in source and binary forms, with or without
      4 # modification, are permitted provided that the following conditions are
      5 # met:
      6 #
      7 #     * Redistributions of source code must retain the above copyright
      8 # notice, this list of conditions and the following disclaimer.
      9 #     * Redistributions in binary form must reproduce the above
     10 # copyright notice, this list of conditions and the following disclaimer
     11 # in the documentation and/or other materials provided with the
     12 # distribution.
     13 #     * Neither the name of Google Inc. nor the names of its
     14 # contributors may be used to endorse or promote products derived from
     15 # this software without specific prior written permission.
     16 #
     17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 
     29 import unittest
     30 
     31 from webkitpy.layout_tests.layout_package import message_broker2
     32 
     33 # This file exists to test routines that aren't necessarily covered elsewhere;
     34 # most of the testing of message_broker2 will be covered under the tests in
     35 # the manager_worker_broker module.
     36 
     37 
     38 class MessageTest(unittest.TestCase):
     39     def test__no_body(self):
     40         msg = message_broker2._Message('src', 'topic_name', 'message_name', None)
     41         self.assertTrue(repr(msg))
     42         s = msg.dumps()
     43         new_msg = message_broker2._Message.loads(s)
     44         self.assertEqual(new_msg.name, 'message_name')
     45         self.assertEqual(new_msg.args, None)
     46         self.assertEqual(new_msg.topic_name, 'topic_name')
     47         self.assertEqual(new_msg.src, 'src')
     48 
     49     def test__body(self):
     50         msg = message_broker2._Message('src', 'topic_name', 'message_name',
     51                                       ('body', 0))
     52         self.assertTrue(repr(msg))
     53         s = msg.dumps()
     54         new_msg = message_broker2._Message.loads(s)
     55         self.assertEqual(new_msg.name, 'message_name')
     56         self.assertEqual(new_msg.args, ('body', 0))
     57         self.assertEqual(new_msg.topic_name, 'topic_name')
     58         self.assertEqual(new_msg.src, 'src')
     59 
     60 
     61 class InterfaceTest(unittest.TestCase):
     62     # These tests mostly exist to pacify coverage.
     63 
     64     # FIXME: There must be a better way to do this and also verify
     65     # that classes do implement every abstract method in an interface.
     66 
     67     def test_brokerclient_is_abstract(self):
     68         # Test that we can't create an instance directly.
     69         self.assertRaises(NotImplementedError, message_broker2.BrokerClient)
     70 
     71         class TestClient(message_broker2.BrokerClient):
     72             def __init__(self):
     73                 pass
     74 
     75         # Test that all the base class methods are abstract and have the
     76         # signature we expect.
     77         obj = TestClient()
     78         self.assertRaises(NotImplementedError, obj.is_done)
     79         self.assertRaises(NotImplementedError, obj.name)
     80 
     81 
     82 if __name__ == '__main__':
     83     unittest.main()
     84