Skip to content

Commit a610a1b

Browse files
committed
Fix py3.2 test failure and unicode behavior
Signed-off-by: Joffrey F <[email protected]>
1 parent 311ae71 commit a610a1b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docker/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def parse_env_file(env_file):
674674

675675

676676
def split_command(command):
677-
if six.PY2:
677+
if six.PY2 and not isinstance(command, six.binary_type):
678678
command = command.encode('utf-8')
679679
return shlex.split(command)
680680

tests/unit/utils_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,18 @@ def test_decode_json_header(self):
392392

393393
class SplitCommandTest(base.BaseTestCase):
394394

395-
@pytest.mark.skipif(six.PY2, reason="shlex doesn't support unicode in py2")
396395
def test_split_command_with_unicode(self):
397-
self.assertEqual(split_command('echo μ'), ['echo', 'μ'])
396+
if six.PY2:
397+
self.assertEqual(
398+
split_command(unicode('echo μμ', 'utf-8')),
399+
['echo', 'μμ']
400+
)
401+
else:
402+
self.assertEqual(split_command('echo μμ'), ['echo', 'μμ'])
398403

399-
@pytest.mark.skipif(six.PY3, reason="shlex doesn't support unicode in py2")
404+
@pytest.mark.skipif(six.PY3, reason="shlex doesn't support bytes in py3")
400405
def test_split_command_with_bytes(self):
401-
expected = ['echo', u'μ'.encode('utf-8')]
402-
self.assertEqual(split_command(u'echo μ'), expected)
406+
self.assertEqual(split_command('echo μμ'), ['echo', 'μμ'])
403407

404408

405409
class PortsTest(base.BaseTestCase):

0 commit comments

Comments
 (0)