Fix py3.2 test failure and unicode behavior

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2015-10-27 18:01:19 +01:00
parent 311ae711d4
commit a610a1be0e
2 changed files with 10 additions and 6 deletions

View File

@ -674,7 +674,7 @@ def parse_env_file(env_file):
def split_command(command): def split_command(command):
if six.PY2: if six.PY2 and not isinstance(command, six.binary_type):
command = command.encode('utf-8') command = command.encode('utf-8')
return shlex.split(command) return shlex.split(command)

View File

@ -392,14 +392,18 @@ class UtilsTest(base.BaseTestCase):
class SplitCommandTest(base.BaseTestCase): class SplitCommandTest(base.BaseTestCase):
@pytest.mark.skipif(six.PY2, reason="shlex doesn't support unicode in py2")
def test_split_command_with_unicode(self): def test_split_command_with_unicode(self):
self.assertEqual(split_command('echo μ'), ['echo', 'μ']) if six.PY2:
self.assertEqual(
split_command(unicode('echo μμ', 'utf-8')),
['echo', 'μμ']
)
else:
self.assertEqual(split_command('echo μμ'), ['echo', 'μμ'])
@pytest.mark.skipif(six.PY3, reason="shlex doesn't support unicode in py2") @pytest.mark.skipif(six.PY3, reason="shlex doesn't support bytes in py3")
def test_split_command_with_bytes(self): def test_split_command_with_bytes(self):
expected = ['echo', u'μ'.encode('utf-8')] self.assertEqual(split_command('echo μμ'), ['echo', 'μμ'])
self.assertEqual(split_command(u'echo μ'), expected)
class PortsTest(base.BaseTestCase): class PortsTest(base.BaseTestCase):