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

Introduce Hypothesis for testing #191

Merged
merged 2 commits into from
Feb 5, 2017
Merged
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
4 changes: 2 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ New features:

Bug fixes:

- *add item here*

- Don't split content lines on the unicode ``LINE SEPARATOR`` character
``\u2028`` but only on ``CRLF`` or ``LF``.

3.11.2 (2017-01-12)
-------------------
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ create-wheel = yes

[wheel]
universal = 1

[tool:pytest]
norecursedirs = .* env* docs *.egg src/icalendar/tests/hypothesis
2 changes: 1 addition & 1 deletion src/icalendar/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def from_ical(cls, st):
# a fold is carriage return followed by either a space or a tab
unfolded = uFOLD.sub('', st)
lines = cls(Contentline(line) for
line in unfolded.splitlines() if line)
line in NEWLINE.split(unfolded) if line)
lines.append('') # '\r\n' at the end of every content line
return lines
except:
Expand Down
35 changes: 35 additions & 0 deletions src/icalendar/tests/hypothesis/test_fuzzing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import string

from hypothesis import given, settings
import hypothesis.strategies as st

from icalendar.parser import Contentline, Contentlines, Parameters
from icalendar.tests import unittest


def printable_characters(**kw):
return st.text(
st.characters(blacklist_categories=(
'Cc', 'Cs'
), **kw)
)

key = st.text(string.ascii_letters + string.digits, min_size=1)
value = printable_characters(blacklist_characters=u'\\;:\"')


class TestFuzzing(unittest.TestCase):

@given(lines=st.lists(
st.tuples(key, st.dictionaries(key, value), value),
min_size=1
))
@settings(max_examples=10**9)
def test_main(self, lines):
cl = Contentlines()
for key, params, value in lines:
params = Parameters(**params)
cl.append(Contentline.from_parts(key, params, value))
cl.append('')

assert Contentlines.from_ical(cl.to_ical()) == cl
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ envlist = py26,py27,py33,py34,py35,py36
deps =
pytest
coverage
py{27,33,34,35,36}: hypothesis>=3.0
icalendar [test]
commands =
coverage run --source=src/icalendar --omit=*/tests/* --module pytest [] src/icalendar
coverage run --source=src/icalendar --omit=*/tests/* --module pytest []
py{27,33,34,35,36}: coverage run --append --source=src/icalendar --omit=*/tests/* --module pytest [] src/icalendar/tests/hypothesis/
coverage report
coverage html