diff options
author | Ask Solem <ask@celeryproject.org> | 2014-01-13 13:50:26 +0000 |
---|---|---|
committer | Ask Solem <ask@celeryproject.org> | 2014-01-13 13:50:26 +0000 |
commit | 4edad0de2f3e3b2b37d59e0d03aeb61a24ca1409 (patch) | |
tree | 28b1554dc3645e4cdec953c5377027ec9963fca5 | |
parent | 6c8bcc49e9fbc38ed7f4a991e2f4e812016bafdc (diff) | |
parent | 6f71663dc9e68eaefab4d7e240491b0b71837f58 (diff) | |
download | py-amqp-4edad0de2f3e3b2b37d59e0d03aeb61a24ca1409.tar.gz |
Merge branch 'dfa/master'
-rw-r--r-- | amqp/serialization.py | 4 | ||||
-rwxr-xr-x | funtests/test_channel.py | 2 | ||||
-rwxr-xr-x | funtests/test_serialization.py | 53 |
3 files changed, 11 insertions, 48 deletions
diff --git a/amqp/serialization.py b/amqp/serialization.py index 6a74702..615bb91 100644 --- a/amqp/serialization.py +++ b/amqp/serialization.py @@ -174,6 +174,8 @@ class AMQPReader(object): val = self.read_bit() elif ftype == 100: val = self.read_float() + elif ftype == 86: # 'V' + val = None else: raise FrameSyntaxError( 'Unknown value in table: {0!r} ({1!r})'.format( @@ -357,6 +359,8 @@ class AMQPWriter(object): elif isinstance(v, (list, tuple)): self.write(b'A') self.write_array(v) + elif v == None: + self.write(b'V') else: err = (ILLEGAL_TABLE_TYPE_WITH_KEY.format(type(v), k, v) if k else ILLEGAL_TABLE_TYPE.format(type(v), v)) diff --git a/funtests/test_channel.py b/funtests/test_channel.py index 503a48e..c5d7796 100755 --- a/funtests/test_channel.py +++ b/funtests/test_channel.py @@ -181,7 +181,7 @@ class TestChannel(unittest.TestCase): """ qname, _, _ = self.ch.queue_declare() - msg = Message(application_headers={'test': None}) + msg = Message(application_headers={'test': object()}) self.assertRaises( FrameSyntaxError, self.ch.basic_publish, msg, routing_key=qname, diff --git a/funtests/test_serialization.py b/funtests/test_serialization.py index 9a8793c..0d6631e 100755 --- a/funtests/test_serialization.py +++ b/funtests/test_serialization.py @@ -316,7 +316,7 @@ class TestSerialization(unittest.TestCase): Check that an un-serializable table entry raises a ValueError """ - val = {'test': None} + val = {'test': object()} w = AMQPWriter() self.assertRaises(FrameSyntaxError, w.write_table, val) @@ -327,6 +327,7 @@ class TestSerialization(unittest.TestCase): 'baz': 'this is some random string I typed', 'ubaz': u'And something in unicode', 'dday_aniv': datetime(1994, 6, 6), + 'nothing' : None, 'more': { 'abc': -123, 'def': 'hello world', @@ -351,26 +352,26 @@ class TestSerialization(unittest.TestCase): # Array # def test_array_from_list(self): - val = [1, 'foo'] + val = [1, 'foo', None] w = AMQPWriter() w.write_array(val) s = w.getvalue() self.assertEqualBinary( - s, '\x00\x00\x00\x0DI\x00\x00\x00\x01S\x00\x00\x00\x03foo', + s, '\x00\x00\x00\x0EI\x00\x00\x00\x01S\x00\x00\x00\x03fooV', ) r = AMQPReader(s) self.assertEqual(r.read_array(), val) def test_array_from_tuple(self): - val = (1, 'foo') + val = (1, 'foo', None) w = AMQPWriter() w.write_array(val) s = w.getvalue() self.assertEqualBinary( - s, '\x00\x00\x00\x0DI\x00\x00\x00\x01S\x00\x00\x00\x03foo', + s, '\x00\x00\x00\x0EI\x00\x00\x00\x01S\x00\x00\x00\x03fooV', ) r = AMQPReader(s) @@ -394,48 +395,6 @@ class TestSerialization(unittest.TestCase): self.assertEqual(r.read_table(), val) # - # Array - # - def test_array_from_list(self): - val = [1, 'foo'] - w = AMQPWriter() - w.write_array(val) - s = w.getvalue() - - self.assertEqualBinary(s, '\x00\x00\x00\x0DI\x00\x00\x00\x01S\x00\x00\x00\x03foo') - - r = AMQPReader(s) - self.assertEqual(r.read_array(), val) - - def test_array_from_tuple(self): - val = (1, 'foo') - w = AMQPWriter() - w.write_array(val) - s = w.getvalue() - - self.assertEqualBinary(s, '\x00\x00\x00\x0DI\x00\x00\x00\x01S\x00\x00\x00\x03foo') - - r = AMQPReader(s) - self.assertEqual(r.read_array(), list(val)) - - def test_table_with_array(self): - val = { - 'foo': 7, - 'bar': Decimal('123345.1234'), - 'baz': 'this is some random string I typed', - 'blist': [1,2,3], - 'nlist': [1, [2,3,4]], - 'ndictl': {'nfoo': 8, 'nblist': [5,6,7] } - } - - w = AMQPWriter() - w.write_table(val) - s = w.getvalue() - - r = AMQPReader(s) - self.assertEqual(r.read_table(), val) - - # # GenericContent # def test_generic_content_eq(self): |