Skip to content

Commit 191937f

Browse files
committed
tst: add a test that fails with unicode strings
1 parent 74cd3bd commit 191937f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

nipype/utils/provenance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def safe_encode(x, as_literal=True):
183183
return pm.Literal(dumps(x), nipype_ns['pickle'])
184184
except TypeError as e:
185185
iflogger.info(e)
186-
value = "Could not encode: " + text_type(e, 'utf-8')
186+
value = "Could not encode: " + text_type(str(e), 'utf-8')
187187
if not as_literal:
188188
return value
189189
return pm.Literal(value, pm.XSD['string'])

nipype/utils/tests/test_provenance.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from future import standard_library
44
standard_library.install_aliases()
55

6-
from nipype.testing import assert_equal, assert_true, assert_false
6+
from ...testing import assert_equal, assert_true, assert_false
77

8-
from ..provenance import ProvStore
8+
from ..provenance import ProvStore, safe_encode, text_type
99

1010

1111
def test_provenance():
@@ -16,3 +16,8 @@ def test_provenance():
1616
provn = ps.g.get_provn()
1717
prov_json = ps.g.serialize(format='json')
1818
yield assert_true, 'echo hello' in provn
19+
20+
def test_safe_encode():
21+
a = '\xc3\xa9lg'
22+
out = safe_encode(a)
23+
yield assert_equal, out.value, text_type(a, 'utf-8')

0 commit comments

Comments
 (0)