Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment with using hypothesis to find bugs #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
Expand Down
30 changes: 30 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
]