Added hypothesis property based testing
This PR uses hypothesis to check if arrays & dictionaries are serialized and deserialized correctly.
I also fixed our integer serialization and deserialization code, bytes string serialization and small string serialization on tables and arrays.
Yes, the examples directory should be ignored when reviewing this.
Seems like we have a genuine problem with strings inside dictionaries on Python 2. Even without any adjustments that were made in this branch I can reproduce this:
Falsifying example: test_table(self=<t.unit.test_serialization.test_serialization instance at 0x7fdf17cde518>, table={u'': u'\x80'})
Traceback (most recent call last):
File "/home/omer/Documents/Projects/py-amqp/t/unit/test_serialization.py", line 126, in test_table
assert loads(b'F', dumps(b'F', [table]))[0][0] == table
AssertionError: assert {'': '\xc2\x80'} == {'': '\x80'}
Differing items:
{'': '\xc2\x80'} != {'': '\x80'}
Full diff:
- {'': '\xc2\x80'}
? ----
+ {u'': u'\x80'}
? + +
Since '\x80' is a unicode string when you encode it to bytes, you get \xc2\x80 but we aren't decoding back. We're encoding again.
Not sure how to resolve this issue.
Authentication fails with the addition of support for small strings in tables and arrays. I'm not sure why though.
Also, tox-docker doesn't seem to work anymore which is super strange.
Seems like there's a bug in RabbitMQ with short strings in tables. It is allowed in the spec.
I found the source of the problem: When RabbitMQ authenticates using the AMQPLAIN method it expects a longstr instead of a shortstr. See issue https://github.com/rabbitmq/rabbitmq-server/issues/1914.