Skip to content

Commit

Permalink
Add hypothesis to our testing arsenal.
Browse files Browse the repository at this point in the history
And this has uncovered a bug::

   cut_suffix('u', '') != 'u'
  • Loading branch information
mvaled committed Sep 15, 2016
1 parent 6dcd3fb commit 0a4a0f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
.pydevproject
.settings/
.tox/
.cache/
.hypothesis/

build/
dist/
Expand Down
19 changes: 19 additions & 0 deletions tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
unicode_literals as _py3_unicode,
absolute_import as _py3_abs_imports)

from hypothesis import given
from hypothesis.strategies import text, binary


def test_safe_decode_dont_fail_uppon_invalid_encoding():
from xoutil.string import safe_decode
Expand Down Expand Up @@ -52,3 +55,19 @@ def test_normalize_slug():
assert normalize_slug(135) == '135'
assert normalize_slug(123456, '', invalids='52') == '1346'
assert normalize_slug('_x', '_') == '_x'


@given(s=text(), p=text())
def test_cutting_is_inverse_to_adding(s, p):
from xoutil.string import cut_prefix, cut_suffix
assert cut_prefix(p + s, p) == s
assert cut_suffix(s + p, p) == s


@given(s=text(), p=text())
def test_cutting_is_stable(s, p):
from xoutil.string import cut_prefix, cut_suffix
if not s.startswith(p):
assert cut_prefix(s, p) == s == cut_prefix(cut_prefix(s, p), p)
if not s.endswith(p):
assert cut_suffix(s, p) == s == cut_suffix(cut_suffix(s, p), p)
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deps = ipython>=2.0.0,<2.2.0
pytest-ipdb==0.1-prerelease2
mock
pytest
hypothesis

commands=py.test -l -q []

Expand All @@ -22,6 +23,7 @@ deps = ipython>=2.0.0,<2.2.0
pytest-ipdb==0.1-prerelease2
mock
pytest
hypothesis

commands=py.test -l -q -k greenlet []

Expand All @@ -34,6 +36,7 @@ deps = ipython>=2.0.0,<2.2.0
pytest-ipdb==0.1-prerelease2
mock
pytest
hypothesis

commands=py.test -l -q -k greenlet []

Expand All @@ -47,5 +50,6 @@ deps = ipython>=2.0.0,<2.2.0
pytest-ipdb==0.1-prerelease2
mock
pytest
hypothesis

commands=py.test -l -q -k greenlet []

0 comments on commit 0a4a0f5

Please sign in to comment.