Example #1
0
class MessageTestCase(unittest.TestCase):
    def setUp(self):
        self.message = Message()

    def test_pattern_valid(self):
        """Test setting the pattern property."""
        pattern = '/test'
        self.message.pattern = pattern
        self.assertEqual(self.message.pattern, pattern)

    def test_pattern_no_slash(self):
        """Test setting the pattern property with no forward-slash."""
        pattern = 'test'
        with self.assertRaises(ValueError):
            self.message.pattern = pattern

    def test_append_integer(self):
        """Test appending an integer to the message."""
        data = 5
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['i'])

    def test_append_float(self):
        """Test appending a float to the message."""
        data = 5.0
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['f'])

    def test_append_string(self):
        """Test appending a string to the message."""
        data = 'test'
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['s'])

    def test_append_blob(self):
        """Test appending a blob to the message."""
        data = ('blob', 'b')
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data[0]])
        self.assertListEqual(self.message.typetags, ['b'])

    def test_append_invalid_tuple(self):
        """Test appending an invalid sequence in a tuple."""
        self.assertRaises(Exception, self.message.append, ('a', 'b', 'c'))

    def test_append_invalid_python_type(self):
        """Test appending an invalid Python type to the message."""
        self.assertRaises(KeyError, self.message.append, {})

    def test_append_invalid_type(self):
        """Test appending an invalid type to the message."""
        self.assertRaises(TypeError, self.message.append, ('test', 'invalid'))
Example #2
0
class MessageTestCase(unittest.TestCase):
    def setUp(self):
        self.message = Message()

    def test_pattern_valid(self):
        """Test setting the pattern property."""
        pattern = '/test'
        self.message.pattern = pattern
        self.assertEqual(self.message.pattern, pattern)

    def test_pattern_no_slash(self):
        """Test setting the pattern property with no forward-slash."""
        pattern ='test'
        with self.assertRaises(ValueError):
            self.message.pattern = pattern

    def test_append_integer(self):
        """Test appending an integer to the message."""
        data = 5
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['i'])

    def test_append_float(self):
        """Test appending a float to the message."""
        data = 5.0
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['f'])

    def test_append_string(self):
        """Test appending a string to the message."""
        data = 'test'
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data])
        self.assertListEqual(self.message.typetags, ['s'])

    def test_append_blob(self):
        """Test appending a blob to the message."""
        data = ('blob', 'b')
        self.message.append(data)
        self.assertListEqual(self.message.arguments, [data[0]])
        self.assertListEqual(self.message.typetags, ['b'])

    def test_append_invalid_tuple(self):
        """Test appending an invalid sequence in a tuple."""
        self.assertRaises(Exception, self.message.append, ('a', 'b', 'c'))

    def test_append_invalid_python_type(self):
        """Test appending an invalid Python type to the message."""
        self.assertRaises(KeyError, self.message.append, {})

    def test_append_invalid_type(self):
        """Test appending an invalid type to the message."""
        self.assertRaises(TypeError, self.message.append, ('test', 'invalid'))
Example #3
0
 def test_serialize_message(self):
     """Test serializing a message."""
     message = Message('/test', 5)
     self.assertEqual(self.serial.serialize_message(message),
                      b'/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05')
Example #4
0
 def test_serialize_bundle(self):
     """Test serializing a bundle."""
     message = Message('/test', 5)
     bundle = Bundle(None, message)
     self.assertEqual(self.serial.serialize_bundle(bundle),
     b'#bundle\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x10/test\x00\x00\x00,i\x00\x00\x00\x00\x00\x05')
Example #5
0
 def test_append_message(self):
     """Test appending a message."""
     data = Message()
     self.bundle.append(data)
     self.assertListEqual(self.bundle.elements, [data])
Example #6
0
 def setUp(self):
     self.message = Message()
Example #7
0
 def setUp(self):
     self.message = Message()