Fix coerce_native

See #344
This commit is contained in:
Markus Unterwaditzer 2016-02-27 20:17:53 +01:00
parent 8b13a932b8
commit 768cebe0e1
2 changed files with 36 additions and 2 deletions

26
tests/cli/test_utils.py Normal file
View file

@ -0,0 +1,26 @@
from hypothesis import given
from hypothesis.strategies import (
binary,
booleans,
complex_numbers,
floats,
integers,
none,
one_of,
text
)
from vdirsyncer.cli.utils import coerce_native
@given(one_of(
binary(),
booleans(),
complex_numbers(),
floats(),
integers(),
none(),
text()
))
def test_coerce_native_fuzzing(s):
coerce_native(s)

View file

@ -503,7 +503,15 @@ def assert_permissions(path, wanted):
def coerce_native(x, encoding='utf-8'):
# XXX: Remove with Python 3 only
try:
return to_native(x, encoding)
return str(x)
except UnicodeError:
return repr(x)
pass
try:
return to_native(x, encoding=encoding)
except UnicodeError:
pass
return repr(x)