mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Merge pull request #346 from untitaker/fix-coerce-native
Fix coerce_native
This commit is contained in:
commit
f9854b9077
2 changed files with 36 additions and 2 deletions
26
tests/cli/test_utils.py
Normal file
26
tests/cli/test_utils.py
Normal 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)
|
||||||
|
|
@ -503,7 +503,15 @@ def assert_permissions(path, wanted):
|
||||||
|
|
||||||
|
|
||||||
def coerce_native(x, encoding='utf-8'):
|
def coerce_native(x, encoding='utf-8'):
|
||||||
|
# XXX: Remove with Python 3 only
|
||||||
try:
|
try:
|
||||||
return to_native(x, encoding)
|
return str(x)
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
return repr(x)
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
return to_native(x, encoding=encoding)
|
||||||
|
except UnicodeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return repr(x)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue