summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
authorEric Fried <openstack@fried.cc>2019-10-29 15:55:11 -0500
committermelanie witt <melwittt@gmail.com>2020-07-21 03:25:22 +0000
commit3228713ea302a962c11eb96ce34918b94528205e (patch)
treea5a472a8275c1f5c4d4516ed1626e46b0b1e27ed /openstackclient/tests/unit
parentd2e809f12086171d227a06fd7ea19e0e36ed12f8 (diff)
downloadpython-openstackclient-3228713ea302a962c11eb96ce34918b94528205e.tar.gz
Fix functional tests for py3
Fix various things so the functional tests will work under python3: - A hashlib.md5() can only be update()d with an encoded string in py3. - There's no dict.iteritems(), change to dict.items() (which is already an iterator). - Open temp files with 'w+' mode rather than the default 'w+b' (as an alternative to encoding all the write and expected-read payloads as bytes). - (This is a weird one) Explicitly raise SkipTest from unittest (rather than unittest2, which is where cls.skipException landed). Not sure why this is busted, but this moves the ball. Conflict/issue with raising SkipTest on this branch. (cherry picked from commit f1d742f32adeb662a3fdf8fa3ef3bc391e71ed81) (cherry picked from commit b866202f54afddca66a77cd989b082e193a96956) Includes squash of: Before writing object data to stdout, re-open it in binary mode Otherwise, you can hit TypeErrors on Python3. Closes-Bug: 1775482 (cherry picked from commit 415b48056d9d021e04ec972029040a89a6b13928) Conflicts: openstackclient/tests/functional/identity/v3/common.py NOTE(melwitt): The conflicts are due to the following changes not in Queens: Id8377363f7a3248b45aeeba21d2acc02684a0305 I7c44bbb60557378b66c5c43a7ba917f40dc2b633 Change-Id: Ic9b2b47848a600e87a3674289ae7ae8c3e091fee (cherry picked from commit 47f0277208362a3224f8e587bbdd60dd5aebf846)
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/object/v1/test_object_all.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/openstackclient/tests/unit/object/v1/test_object_all.py b/openstackclient/tests/unit/object/v1/test_object_all.py
index 363f2ea2..08a7534d 100644
--- a/openstackclient/tests/unit/object/v1/test_object_all.py
+++ b/openstackclient/tests/unit/object/v1/test_object_all.py
@@ -241,7 +241,25 @@ class TestObjectSave(TestObjectAll):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- with mock.patch('sys.stdout', new=six.BytesIO()) as fake_stdout:
+ class FakeStdout(six.BytesIO):
+ def __init__(self):
+ six.BytesIO.__init__(self)
+ self.context_manager_calls = []
+
+ def __enter__(self):
+ self.context_manager_calls.append('__enter__')
+ return self
+
+ def __exit__(self, *a):
+ self.context_manager_calls.append('__exit__')
+
+ with mock.patch('sys.stdout') as fake_stdout, mock.patch(
+ 'os.fdopen', return_value=FakeStdout()) as fake_fdopen:
+ fake_stdout.fileno.return_value = 123
self.cmd.take_action(parsed_args)
- self.assertEqual(fake_stdout.getvalue(), object_fakes.object_1_content)
+ self.assertEqual(fake_fdopen.return_value.getvalue(),
+ object_fakes.object_1_content)
+ self.assertEqual(fake_fdopen.mock_calls, [mock.call(123, 'wb')])
+ self.assertEqual(fake_fdopen.return_value.context_manager_calls,
+ ['__enter__', '__exit__'])