コード例 #1
0
 def test_as_dict(self):
     'returns dict from .as_dict'
     x = Message(x=1, y=2)
     self.assertEqual(
         {'x': 1, 'y': 2},
         x.as_dict()
     )
コード例 #2
0
    def test_equality(self):
        'two messages are equal if their bundles are equal'
        d = {'x': 1, 'y': 2}
        x = Message(**d)
        y = Message(**d)

        self.assertEqual(x, y)
コード例 #3
0
    def test_as_json(self):
        'returns string from .as_msgpack'
        d = {'x': 1, 'y': 2}
        x = Message(**d)

        self.assertEqual(
            json.dumps(d),
            x.as_json()
        )
コード例 #4
0
 def test_dir(self):
     'dir includes attributes'
     x = Message(x=1, y=2)
     try:
         self.assertIn('x', dir(x))
         self.assertIn('y', dir(x))
     except AttributeError:  # python 2.6
         self.assertTrue('x' in dir(x), '"x" not in dir(x)')
         self.assertTrue('y' in dir(x), '"y" not in dir(x)')
コード例 #5
0
 def test_repr(self):
     x = Message(x=1, y=2)
     try:
         self.assertRegexpMatches(
             repr(x),
             r'Message\(((x=1|y=2)(, )?){2}\)'
         )
     except AttributeError:  # python 2.6
         self.assertEqual(
             'Message(y=2, x=1)',
             repr(x)
         )
コード例 #6
0
 def test_access_missing(self):
     'accessing attributes that do not exist'
     x = Message(x=1)
     try:
         self.assertRaisesRegex(
             AttributeError, '"y" is not included in this message',
             getattr, x, 'y'
         )
     except AttributeError:  # python 2.6
         self.assertRaises(
             AttributeError,
             getattr, x, 'y'
         )
コード例 #7
0
 def test_dot_access(self):
     'accessing attributes'
     x = Message(x=1)
     self.assertEqual(1, x.x)
コード例 #8
0
 def test_from_kwargs(self):
     'gets correct message from kwargs'
     d = {'test': 1}
     self.assertEqual(Message(d), self.router.get_message_from_call(**d))