Skip to content

Commit

Permalink
Introduce Hypothesis for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Jan 29, 2017
1 parent 74ef4c1 commit 5c02e01
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
3 changes: 1 addition & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ New features:

Bug fixes:

- *add item here*

- Fix a consistency bug regarding unicode newlines

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 @@ -6,3 +6,6 @@ ignore =

[zest.releaser]
python-file-with-version = src/icalendar/__init__.py

[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

0 comments on commit 5c02e01

Please sign in to comment.