From 0102e2e1eed76e74652f082d7aec96855147c4a1 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 23 Apr 2014 11:40:37 -0700 Subject: [PATCH] Updated test_shell for Python3 Change-Id: Ia76e544fa6e0a222c260191a1ab74939078ed2fb --- tests/test_shell.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_shell.py b/tests/test_shell.py index 55967b65..b6f74f37 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -18,9 +18,17 @@ import os import tempfile import unittest +import six + import swiftclient import swiftclient.shell + +if six.PY2: + BUILTIN_OPEN = '__builtin__.open' +else: + BUILTIN_OPEN = 'builtins.open' + mocked_os_environ = { 'ST_AUTH': 'http://localhost:8080/auth/v1.0', 'ST_USER': 'test:tester', @@ -164,7 +172,7 @@ class TestShell(unittest.TestCase): mock.call(' 0')] mock_print.assert_has_calls(calls) - @mock.patch('__builtin__.open') + @mock.patch(BUILTIN_OPEN) @mock.patch('swiftclient.shell.Connection') def test_download(self, connection, mock_open): connection.return_value.get_object.return_value = [ @@ -217,7 +225,7 @@ class TestShell(unittest.TestCase): # Upload in segments argv = ["", "upload", "container", self.tmpfile, "-S", "10"] with open(self.tmpfile, "wb") as fh: - fh.write('12345678901234567890') + fh.write(b'12345678901234567890') swiftclient.shell.main(argv) connection.return_value.put_object.assert_called_with( 'container',