Support python 3
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
17682c58db
commit
809443d6d0
23 changed files with 128 additions and 85 deletions
|
|
@ -3,9 +3,8 @@ from __future__ import unicode_literals
|
|||
|
||||
import os
|
||||
|
||||
import mock
|
||||
|
||||
from compose.cli import docker_client
|
||||
from tests import mock
|
||||
from tests import unittest
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
|
||||
from compose.cli import verbose_proxy
|
||||
from tests import unittest
|
||||
|
||||
|
|
@ -8,7 +10,8 @@ from tests import unittest
|
|||
class VerboseProxyTestCase(unittest.TestCase):
|
||||
|
||||
def test_format_call(self):
|
||||
expected = "(u'arg1', True, key=u'value')"
|
||||
prefix = '' if six.PY3 else 'u'
|
||||
expected = "(%(p)s'arg1', True, key=%(p)s'value')" % dict(p=prefix)
|
||||
actual = verbose_proxy.format_call(
|
||||
("arg1", True),
|
||||
{'key': 'value'})
|
||||
|
|
@ -21,7 +24,7 @@ class VerboseProxyTestCase(unittest.TestCase):
|
|||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_format_return(self):
|
||||
expected = "{u'Id': u'ok'}"
|
||||
expected = repr({'Id': 'ok'})
|
||||
actual = verbose_proxy.format_return({'Id': 'ok'}, 2)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ from __future__ import unicode_literals
|
|||
import os
|
||||
|
||||
import docker
|
||||
import mock
|
||||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.cli.docopt_command import NoSuchCommand
|
||||
from compose.cli.errors import UserError
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from operator import itemgetter
|
||||
|
||||
import mock
|
||||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.config import config
|
||||
from compose.config.errors import ConfigurationError
|
||||
|
|
@ -30,7 +32,7 @@ class ConfigTest(unittest.TestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
sorted(service_dicts, key=lambda d: d['name']),
|
||||
sorted(service_dicts, key=itemgetter('name')),
|
||||
sorted([
|
||||
{
|
||||
'name': 'bar',
|
||||
|
|
@ -41,7 +43,7 @@ class ConfigTest(unittest.TestCase):
|
|||
'name': 'foo',
|
||||
'image': 'busybox',
|
||||
}
|
||||
], key=lambda d: d['name'])
|
||||
], key=itemgetter('name'))
|
||||
)
|
||||
|
||||
def test_load_throws_error_when_not_dict(self):
|
||||
|
|
@ -885,24 +887,24 @@ class ExtendsTest(unittest.TestCase):
|
|||
other_config = {'web': {'links': ['db']}}
|
||||
|
||||
with mock.patch.object(config, 'load_yaml', return_value=other_config):
|
||||
print load_config()
|
||||
print(load_config())
|
||||
|
||||
with self.assertRaisesRegexp(ConfigurationError, 'volumes_from'):
|
||||
other_config = {'web': {'volumes_from': ['db']}}
|
||||
|
||||
with mock.patch.object(config, 'load_yaml', return_value=other_config):
|
||||
print load_config()
|
||||
print(load_config())
|
||||
|
||||
with self.assertRaisesRegexp(ConfigurationError, 'net'):
|
||||
other_config = {'web': {'net': 'container:db'}}
|
||||
|
||||
with mock.patch.object(config, 'load_yaml', return_value=other_config):
|
||||
print load_config()
|
||||
print(load_config())
|
||||
|
||||
other_config = {'web': {'net': 'host'}}
|
||||
|
||||
with mock.patch.object(config, 'load_yaml', return_value=other_config):
|
||||
print load_config()
|
||||
print(load_config())
|
||||
|
||||
def test_volume_path(self):
|
||||
dicts = load_from_filename('tests/fixtures/volume-path/docker-compose.yml')
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import docker
|
||||
import mock
|
||||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.container import Container
|
||||
from compose.container import get_container_name
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||
|
||||
import os
|
||||
|
||||
import six
|
||||
|
||||
from .. import unittest
|
||||
from compose.cli.log_printer import LogPrinter
|
||||
|
||||
|
|
@ -30,16 +32,17 @@ class LogPrinterTest(unittest.TestCase):
|
|||
output = self.get_default_output()
|
||||
self.assertIn('\033[', output)
|
||||
|
||||
@unittest.skipIf(six.PY3, "Only test unicode in python2")
|
||||
def test_unicode(self):
|
||||
glyph = u'\u2022'.encode('utf-8')
|
||||
glyph = u'\u2022'
|
||||
|
||||
def reader(*args, **kwargs):
|
||||
yield glyph + b'\n'
|
||||
yield glyph + '\n'
|
||||
|
||||
container = MockContainer(reader)
|
||||
output = run_log_printer([container])
|
||||
|
||||
self.assertIn(glyph, output)
|
||||
self.assertIn(glyph, output.decode('utf-8'))
|
||||
|
||||
|
||||
def run_log_printer(containers, monochrome=False):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import docker
|
||||
import mock
|
||||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.const import LABEL_SERVICE
|
||||
from compose.container import Container
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ from __future__ import absolute_import
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import docker
|
||||
import mock
|
||||
from docker.utils import LogConfig
|
||||
|
||||
from .. import mock
|
||||
from .. import unittest
|
||||
from compose.const import LABEL_ONE_OFF
|
||||
from compose.const import LABEL_PROJECT
|
||||
|
|
|
|||
|
|
@ -8,38 +8,38 @@ from compose.cli.utils import split_buffer
|
|||
class SplitBufferTest(unittest.TestCase):
|
||||
def test_single_line_chunks(self):
|
||||
def reader():
|
||||
yield b'abc\n'
|
||||
yield b'def\n'
|
||||
yield b'ghi\n'
|
||||
yield 'abc\n'
|
||||
yield 'def\n'
|
||||
yield 'ghi\n'
|
||||
|
||||
self.assert_produces(reader, [b'abc\n', b'def\n', b'ghi\n'])
|
||||
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi\n'])
|
||||
|
||||
def test_no_end_separator(self):
|
||||
def reader():
|
||||
yield b'abc\n'
|
||||
yield b'def\n'
|
||||
yield b'ghi'
|
||||
yield 'abc\n'
|
||||
yield 'def\n'
|
||||
yield 'ghi'
|
||||
|
||||
self.assert_produces(reader, [b'abc\n', b'def\n', b'ghi'])
|
||||
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
|
||||
|
||||
def test_multiple_line_chunk(self):
|
||||
def reader():
|
||||
yield b'abc\ndef\nghi'
|
||||
yield 'abc\ndef\nghi'
|
||||
|
||||
self.assert_produces(reader, [b'abc\n', b'def\n', b'ghi'])
|
||||
self.assert_produces(reader, ['abc\n', 'def\n', 'ghi'])
|
||||
|
||||
def test_chunked_line(self):
|
||||
def reader():
|
||||
yield b'a'
|
||||
yield b'b'
|
||||
yield b'c'
|
||||
yield b'\n'
|
||||
yield b'd'
|
||||
yield 'a'
|
||||
yield 'b'
|
||||
yield 'c'
|
||||
yield '\n'
|
||||
yield 'd'
|
||||
|
||||
self.assert_produces(reader, [b'abc\n', b'd'])
|
||||
self.assert_produces(reader, ['abc\n', 'd'])
|
||||
|
||||
def test_preserves_unicode_sequences_within_lines(self):
|
||||
string = u"a\u2022c\n".encode('utf-8')
|
||||
string = u"a\u2022c\n"
|
||||
|
||||
def reader():
|
||||
yield string
|
||||
|
|
@ -47,7 +47,7 @@ class SplitBufferTest(unittest.TestCase):
|
|||
self.assert_produces(reader, [string])
|
||||
|
||||
def assert_produces(self, reader, expectations):
|
||||
split = split_buffer(reader(), b'\n')
|
||||
split = split_buffer(reader(), '\n')
|
||||
|
||||
for (actual, expected) in zip(split, expectations):
|
||||
self.assertEqual(type(actual), type(expected))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue