Skip to content

Commit c64af9a

Browse files
committed
pull out the byte conversion
1 parent 7f148f1 commit c64af9a

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

mig/shared/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,6 @@ def _walk_and_covert_recursive(input_obj, highlight='', _as_bytes=False, _force_
519519
return thetype((_force_recursive(i, highlight) for i in input_obj))
520520
elif not is_unicode(input_obj):
521521
return _force_primitive(input_obj, highlight)
522-
elif not PY2 and _as_bytes:
523-
return _force_primitive(input_obj, highlight)
524522
else:
525523
return input_obj
526524

@@ -530,7 +528,7 @@ def force_utf8_rec(input_obj, highlight=''):
530528
dictionaries with nested unicode strings to a pure utf8 version. Actual
531529
changes are marked out with the highlight string if given.
532530
"""
533-
return _walk_and_covert_recursive(input_obj, highlight, _as_bytes=True, _force_primitive=force_utf8, _force_recursive=force_utf8_rec)
531+
return _walk_and_covert_recursive(input_obj, highlight, _force_primitive=force_utf8, _force_recursive=force_utf8_rec)
534532

535533

536534
def force_unicode(val, highlight=''):

tests/test_mig_shared_base.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,28 @@
4040
DUMMY_UNICODE = u'UniCode123½¾µßðþđŋħĸþł@ª€£$¥©®'
4141

4242

43-
if PY2:
44-
def _strbytes(value):
45-
assert isinstance(value, str)
46-
return value
47-
else:
48-
def _strbytes(value):
49-
assert isinstance(value, str)
50-
return bytes(value, 'utf8')
51-
52-
5343
class MigSharedBase__force_default_fs_coding_rec(MigTestCase):
5444
"""Unit tests of mig.shared.base force_default_fs_coding_rec()"""
5545

5646
def test_encode_a_string(self):
5747
output = force_default_fs_coding_rec('foobar')
5848

59-
self.assertEqual(output, _strbytes('foobar'))
49+
self.assertEqual(output, 'foobar')
6050

6151
def test_encode_within_a_dict(self):
6252
output = force_default_fs_coding_rec({ 'key': 'value' })
6353

64-
self.assertEqual(output, { _strbytes('key'): _strbytes('value') })
54+
self.assertEqual(output, { 'key': 'value' })
6555

6656
def test_encode_within_a_list(self):
6757
output = force_default_fs_coding_rec(['foo', 'bar', 'baz'])
6858

69-
self.assertEqual(output, [_strbytes('foo'), _strbytes('bar'), _strbytes('baz')])
59+
self.assertEqual(output, ['foo', 'bar', 'baz'])
7060

7161
def test_encode_within_a_tuple(self):
7262
output = force_default_fs_coding_rec(('foo', 'bar', 'baz'))
7363

74-
self.assertEqual(output, (_strbytes('foo'), _strbytes('bar'), _strbytes('baz')))
64+
self.assertEqual(output, ('foo', 'bar', 'baz'))
7565

7666

7767
class MigSharedBase__force_default_str_coding_rec(MigTestCase):

0 commit comments

Comments
 (0)