diff --git a/setup.py b/setup.py index 5b7b823..8c3bed1 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ packages=find_packages(exclude=['contrib', 'docs', 'tests']), install_requires=[], extras_require={ - 'dev': ['pytest>=3.6', 'wheel', 'pytest-cov', 'pycodestyle'], + 'dev': ['pytest>=3.6', 'wheel', 'pytest-cov', 'pycodestyle', 'hypothesis'], 'travis': ['coveralls'], }, package_data={}, diff --git a/tests/test_parser.py b/tests/test_parser.py index 62d094b..ea1f76e 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -6,6 +6,10 @@ format_midi, format_true, format_false, format_nil, format_infinitum, MidiTuple ) from pytest import approx, raises +from hypothesis import given, example, assume, settings, Verbosity +from hypothesis.strategies import \ + text, binary, floats, integers, lists, tuples, choices, one_of + from time import time import struct from oscpy.stats import Stats @@ -301,3 +305,29 @@ def test_format_encoding(): format_message('/test', [s], encoding='utf8')[0], encoding='ascii', encoding_errors='replace' )[2][0] == u'������������' + + +@given( + lists( + one_of( + binary(), + floats( + allow_nan=False, + min_value=-2147483647, + max_value=2147483647 + ), + integers( + min_value=-2147483648, + max_value=2147483647 + ) + ), + ) +) +def test_decode_encoded(args): + for x in args: + assume(not (isinstance(x, bytes) and b'\x00' in x)) + + assert read_message(format_message(b'/test', values=args))[2] == [ + approx(x) if isinstance(x, float) else x + for x in args + ]