From 5ce26ec392f1baa9d86a83e38f0f01b3a65868e7 Mon Sep 17 00:00:00 2001 From: Zhao Chao Date: Tue, 13 Mar 2018 19:00:26 +0800 Subject: [PATCH] Fix os.path.join() for unittests under python 3.6 Some unittest cases of trove.tests.unittests.guestagent has mocked os.path.expanduser(), the result of the mocked function is passed to os.path.join(). This causes these tests failed under Python3.6 by TypeError, because a str, bytes or os.PathLike object is expected, but a MagicMock object is passed in instead. Giving a string return value for the mocked os.path.expanduser() fixes. Partial-Bug: #1755417 Change-Id: Ieeb7964a65ceb6fab0f20a0c8fefbe38dd25cb10 Signed-off-by: Zhao Chao --- trove/tests/unittests/guestagent/test_backups.py | 3 ++- trove/tests/unittests/guestagent/test_redis_manager.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/trove/tests/unittests/guestagent/test_backups.py b/trove/tests/unittests/guestagent/test_backups.py index 7ad9ec4614..59c2ea25ea 100644 --- a/trove/tests/unittests/guestagent/test_backups.py +++ b/trove/tests/unittests/guestagent/test_backups.py @@ -796,7 +796,8 @@ class MongodbRestoreTests(trove_testtools.TestCase): def setUp(self, _): super(MongodbRestoreTests, self).setUp() - self.patch_ope = patch('os.path.expanduser') + self.patch_ope = patch('os.path.expanduser', + return_value='/tmp/mongo') self.mock_ope = self.patch_ope.start() self.addCleanup(self.patch_ope.stop) self.restore_runner = utils.import_class( diff --git a/trove/tests/unittests/guestagent/test_redis_manager.py b/trove/tests/unittests/guestagent/test_redis_manager.py index 733ce7dc29..611d45c8dc 100644 --- a/trove/tests/unittests/guestagent/test_redis_manager.py +++ b/trove/tests/unittests/guestagent/test_redis_manager.py @@ -34,7 +34,8 @@ class RedisGuestAgentManagerTest(DatastoreManagerTest): @patch.object(ImportOverrideStrategy, '_initialize_import_directory') def setUp(self, *args, **kwargs): super(RedisGuestAgentManagerTest, self).setUp('redis') - self.patch_ope = patch('os.path.expanduser') + self.patch_ope = patch('os.path.expanduser', + return_value='/tmp/redis') self.mock_ope = self.patch_ope.start() self.addCleanup(self.patch_ope.stop) self.replication_strategy = 'RedisSyncReplication'