Permalink
Browse files

Add hypothesis to our testing arsenal.

And this has uncovered a bug::

   cut_suffix('u', '') != 'u'
  • Loading branch information...
mvaled committed Sep 15, 2016
1 parent 6dcd3fb commit 0a4a0f529812fed363efb653f3ade2d2bc203945
Showing with 25 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +19 −0 tests/test_string.py
  3. +4 −0 tox.ini
@@ -7,6 +7,8 @@
.pydevproject
.settings/
.tox/
.cache/
.hypothesis/
build/
dist/
@@ -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
@@ -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)
@@ -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 []
@@ -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 []
@@ -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 []
@@ -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.