summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhao Chao <zhaochao1984@gmail.com>2018-07-10 13:47:04 +0800
committerZhao Chao <zhaochao1984@gmail.com>2018-07-10 14:26:02 +0800
commit0fc7d9e33d0ec018126b57e43004e2fba4f7ebaa (patch)
treead3f6224757601d03f1e37a3b2bbb10e6b29b3d9
parent9e2d282b4de0ef5e7e7dbecce70af34c2d60d5dd (diff)
downloadpython-troveclient-0fc7d9e33d0ec018126b57e43004e2fba4f7ebaa.tar.gz
Correctly mocking builtin open in test_v1_shell
There's now a seperate module 'builtins' from python-future(this package is now installed by stestr, and stestr in required by oslotest-3.6.0), so under Python 2.x 'builtins' is also imported as a module and 'bultins.open' is mocked instead of '__builtin__.open'. And according to the Mock document, we should always patch the object where it's looked up, so only necessary mocking is made in this patch. Change-Id: I57ea61cefd3b01b19475b0fa7e16f716eaaa14e6 Signed-off-by: Zhao Chao <zhaochao1984@gmail.com>
-rw-r--r--troveclient/tests/test_v1_shell.py11
1 files changed, 2 insertions, 9 deletions
diff --git a/troveclient/tests/test_v1_shell.py b/troveclient/tests/test_v1_shell.py
index 689cb5a..59b0ab1 100644
--- a/troveclient/tests/test_v1_shell.py
+++ b/troveclient/tests/test_v1_shell.py
@@ -13,13 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-try:
- # handle py34
- import builtins
-except ImportError:
- # and py27
- import __builtin__ as builtins
-
import base64
import fixtures
import mock
@@ -699,7 +692,7 @@ class ShellTest(utils.TestCase):
self.assert_called('GET', '/modules/4321')
def test_module_create(self):
- with mock.patch.object(builtins, 'open'):
+ with mock.patch('argparse.open'):
return_value = b'mycontents'
expected_contents = str(return_value.decode('utf-8'))
mock_encode = mock.Mock(return_value=return_value)
@@ -787,7 +780,7 @@ class ShellTest(utils.TestCase):
def test_module_retrieve(self):
with mock.patch.object(troveclient.v1.modules.Module, '__getattr__',
mock.Mock(return_value='4321')):
- with mock.patch.object(builtins, 'open'):
+ with mock.patch('troveclient.v1.instances.open'):
self.run_command('module-retrieve 1234')
self.assert_called(
'GET',