Skip to content

Commit

Permalink
tests: require hypothesis
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Oct 24, 2016
1 parent 5ef5cea commit 7582b03
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions tests/test_hypo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,50 @@
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

try:
import hypothesis
from hypothesis import given, strategies
except ImportError:
hypothesis = None
from hypothesis import given, strategies

from senf import fsnative, text2fsn, fsn2text, bytes2fsn, fsn2bytes, print_
from senf._compat import text_type, StringIO, BytesIO


if hypothesis:

@given(strategies.lists(strategies.text()), strategies.text(),
strategies.text(), strategies.booleans())
def test_print(objects, sep, end, flush):
h = StringIO()
print_(*objects, sep=sep, end=end, flush=flush, file=h)
h.getvalue()

@given(strategies.lists(strategies.binary()), strategies.binary(),
strategies.binary(), strategies.booleans())
def test_print_bytes(objects, sep, end, flush):
h = StringIO()
print_(*objects, sep=sep, end=end, flush=flush, file=h)
h.getvalue()

@given(strategies.text())
def test_fsnative(text):
assert isinstance(fsnative(text), fsnative)

@given(strategies.text())
def test_text2fsn(text):
assert isinstance(text2fsn(text), fsnative)

@given(strategies.text())
def test_text_fsn_roudntrip(text):
assert isinstance(fsn2text(text2fsn(text)), text_type)

@given(strategies.binary(),
strategies.sampled_from(("utf-8", "utf-16-le",
"utf-32-le", "latin-1")))
def test_bytes(data, encoding):
try:
path = bytes2fsn(data, encoding)
except ValueError:
pass
else:
assert fsn2bytes(path, encoding) == data
from senf._compat import text_type, StringIO


@given(strategies.lists(strategies.text()), strategies.text(),
strategies.text(), strategies.booleans())
def test_print(objects, sep, end, flush):
h = StringIO()
print_(*objects, sep=sep, end=end, flush=flush, file=h)
h.getvalue()


@given(strategies.lists(strategies.binary()), strategies.binary(),
strategies.binary(), strategies.booleans())
def test_print_bytes(objects, sep, end, flush):
h = StringIO()
print_(*objects, sep=sep, end=end, flush=flush, file=h)
h.getvalue()


@given(strategies.text())
def test_fsnative(text):
assert isinstance(fsnative(text), fsnative)


@given(strategies.text())
def test_text2fsn(text):
assert isinstance(text2fsn(text), fsnative)


@given(strategies.text())
def test_text_fsn_roudntrip(text):
assert isinstance(fsn2text(text2fsn(text)), text_type)


@given(strategies.binary(),
strategies.sampled_from(("utf-8", "utf-16-le",
"utf-32-le", "latin-1")))
def test_bytes(data, encoding):
try:
path = bytes2fsn(data, encoding)
except ValueError:
pass
else:
assert fsn2bytes(path, encoding) == data

0 comments on commit 7582b03

Please sign in to comment.