Skip to content

Commit 4ebdb11

Browse files
committed
restore intended behaviour
1 parent ca47e01 commit 4ebdb11

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

mig/shared/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,14 @@ def force_utf8(val, highlight=''):
510510
return codecs.encode("%s%s%s" % (highlight, val, highlight), 'utf8')
511511

512512

513-
def _walk_and_covert_recursive(input_obj, highlight='', _as_bytes=False, _force_primitive=None, _force_recursive=None):
513+
def _walk_and_convert_recursive(input_obj, highlight='', _as_bytes=False, _force_primitive=None, _force_recursive=None):
514514
thetype = type(input_obj)
515515
if issubclass(thetype, dict):
516516
return {_force_recursive(i, highlight): _force_recursive(j, highlight) for (i, j) in
517517
input_obj.items()}
518518
elif issubclass(thetype, (list, tuple)):
519519
return thetype((_force_recursive(i, highlight) for i in input_obj))
520-
elif not is_unicode(input_obj):
520+
elif is_unicode(input_obj):
521521
return _force_primitive(input_obj, highlight)
522522
else:
523523
return input_obj
@@ -528,7 +528,7 @@ def force_utf8_rec(input_obj, highlight=''):
528528
dictionaries with nested unicode strings to a pure utf8 version. Actual
529529
changes are marked out with the highlight string if given.
530530
"""
531-
return _walk_and_covert_recursive(input_obj, highlight, _force_primitive=force_utf8, _force_recursive=force_utf8_rec)
531+
return _walk_and_convert_recursive(input_obj, highlight, _force_primitive=force_utf8, _force_recursive=force_utf8_rec)
532532

533533

534534
def force_unicode(val, highlight=''):
@@ -548,7 +548,7 @@ def force_unicode_rec(input_obj, highlight=''):
548548
dictionaries with nested utf8 strings to a pure unicode version. Actual
549549
changes are marked out with the highlight string if given.
550550
"""
551-
return _walk_and_covert_recursive(input_obj, highlight, _force_primitive=force_unicode, _force_recursive=force_unicode_rec)
551+
return _walk_and_convert_recursive(input_obj, highlight, _force_primitive=force_unicode, _force_recursive=force_unicode_rec)
552552

553553

554554
def _force_default_coding(input_obj, kind, highlight=''):

tests/test_mig_shared_base.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from tests.support import PY2, MigTestCase, testmain
3535

36-
from mig.shared.base import force_default_fs_coding_rec, force_default_str_coding_rec
36+
from mig.shared.base import force_default_fs_coding_rec, force_default_str_coding_rec, force_utf8
3737

3838
DUMMY_BYTECHARS = b'DEADBEEF'
3939
DUMMY_BYTESRAW = binascii.unhexlify('DEADBEEF') # 4 bytes
@@ -46,22 +46,22 @@ class MigSharedBase__force_default_fs_coding_rec(MigTestCase):
4646
def test_encode_a_string(self):
4747
output = force_default_fs_coding_rec('foobar')
4848

49-
self.assertEqual(output, 'foobar')
49+
self.assertEqual(output, b'foobar')
5050

5151
def test_encode_within_a_dict(self):
5252
output = force_default_fs_coding_rec({ 'key': 'value' })
5353

54-
self.assertEqual(output, { 'key': 'value' })
54+
self.assertEqual(output, { b'key': b'value' })
5555

5656
def test_encode_within_a_list(self):
5757
output = force_default_fs_coding_rec(['foo', 'bar', 'baz'])
5858

59-
self.assertEqual(output, ['foo', 'bar', 'baz'])
59+
self.assertEqual(output, [b'foo', b'bar', b'baz'])
6060

6161
def test_encode_within_a_tuple(self):
6262
output = force_default_fs_coding_rec(('foo', 'bar', 'baz'))
6363

64-
self.assertEqual(output, ('foo', 'bar', 'baz'))
64+
self.assertEqual(output, (b'foo', b'bar', b'baz'))
6565

6666

6767
class MigSharedBase__force_default_str_coding_rec(MigTestCase):
@@ -88,5 +88,14 @@ def test_encode_within_a_tuple(self):
8888
self.assertEqual(output, ('foo', 'bar', 'baz'))
8989

9090

91+
class MigSharedBase__force_utf8(MigTestCase):
92+
"""Unit tests of mig.shared.base force_utf8()"""
93+
94+
def test_encode_a_string(self):
95+
output = force_utf8('foobar')
96+
97+
self.assertEqual(output, b'foobar')
98+
99+
91100
if __name__ == '__main__':
92101
testmain()

0 commit comments

Comments
 (0)