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
Changes from 1 commit
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
Next Next commit
experiment with using hypothesis to find bugs
tshirtman committed Sep 2, 2018
commit 048d1d2cd3f5544ab1d5dc89dd31143119023798
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
packages=find_packages(exclude=['contrib', 'docs', 'tests']),
install_requires=[],
extras_require={
'dev': ['pytest', 'wheel', 'pytest-cov', 'pycodestyle'],
'dev': ['pytest', 'wheel', 'pytest-cov', 'pycodestyle', 'hypothesis'],
'travis': ['coveralls'],
},
package_data={},
30 changes: 30 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,10 @@
format_message, format_bundle, timetag_to_time, time_to_timetag
)
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

@@ -239,3 +243,29 @@ def test_format_encoding():
format_message('/test', [s], encoding='utf8'),
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
]