Switch to mox3

As mox3 is a drop-in Python 3 replacement for mox, let's switch to it.

Change-Id: I0174398c492fdd5e53672dd0f654f220583b75d4
This commit is contained in:
Julien Danjou 2015-01-15 11:54:41 +01:00
parent 808fa29ce2
commit a360ed98bb
8 changed files with 32 additions and 57 deletions

View File

@ -15,7 +15,7 @@
import httplib import httplib
import mox from mox3 import mox
import testtools import testtools
from glance.common import auth from glance.common import auth

View File

@ -17,8 +17,8 @@ import os.path
import shutil import shutil
import fixtures import fixtures
from oslotest import moxstubout
import osprofiler.web import osprofiler.web
import stubout
from glance.api.middleware import context from glance.api.middleware import context
from glance.common import config from glance.common import config
@ -29,8 +29,8 @@ class TestPasteApp(test_utils.BaseTestCase):
def setUp(self): def setUp(self):
super(TestPasteApp, self).setUp() super(TestPasteApp, self).setUp()
self.stubs = stubout.StubOutForTesting() mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.addCleanup(self.stubs.UnsetAll) self.stubs = mox_fixture.stubs
def _do_test_load_paste_app(self, def _do_test_load_paste_app(self,
expected_app_type, expected_app_type,

View File

@ -16,7 +16,7 @@
from oslo.serialization import jsonutils from oslo.serialization import jsonutils
from oslo_utils import timeutils from oslo_utils import timeutils
import stubout from oslotest import moxstubout
import webob import webob
from glance.api import authorization from glance.api import authorization
@ -122,8 +122,8 @@ class TestKeystoneAuthPlugin(utils.BaseTestCase):
def setUp(self): def setUp(self):
super(TestKeystoneAuthPlugin, self).setUp() super(TestKeystoneAuthPlugin, self).setUp()
self.stubs = stubout.StubOutForTesting() mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.addCleanup(self.stubs.UnsetAll) self.stubs = mox_fixture.stubs
def test_get_plugin_from_strategy_keystone(self): def test_get_plugin_from_strategy_keystone(self):
strategy = auth.get_plugin_from_strategy('keystone') strategy = auth.get_plugin_from_strategy('keystone')

View File

@ -21,9 +21,9 @@ import time
import fixtures import fixtures
from oslo_utils import units from oslo_utils import units
from oslotest import moxstubout
import six import six
from six.moves import xrange from six.moves import xrange
import stubout
from glance.common import exception from glance.common import exception
from glance import image_cache from glance import image_cache
@ -506,9 +506,9 @@ class TestImageCacheNoDep(test_utils.BaseTestCase):
def init_driver(self2): def init_driver(self2):
self2.driver = self.driver self2.driver = self.driver
self.stubs = stubout.StubOutForTesting() mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = mox_fixture.stubs
self.stubs.Set(image_cache.ImageCache, 'init_driver', init_driver) self.stubs.Set(image_cache.ImageCache, 'init_driver', init_driver)
self.addCleanup(self.stubs.UnsetAll)
def test_get_caching_iter_when_write_fails(self): def test_get_caching_iter_when_write_fails(self):

View File

@ -21,7 +21,7 @@ import uuid
import eventlet import eventlet
import glance_store import glance_store
from mock import patch from mock import patch
import mox from mox3 import mox
from oslo_config import cfg from oslo_config import cfg
from glance.common import exception from glance.common import exception

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import glance_store import glance_store
import mox import mock
from glance.common import exception from glance.common import exception
import glance.location import glance.location
@ -852,21 +852,13 @@ class TestStoreAddToBackend(utils.BaseTestCase):
self.size = len(self.data) self.size = len(self.data)
self.location = "file:///ab/cde/fgh" self.location = "file:///ab/cde/fgh"
self.checksum = "md5" self.checksum = "md5"
self.mox = mox.Mox()
def tearDown(self):
super(TestStoreAddToBackend, self).tearDown()
self.mox.UnsetStubs()
def _bad_metadata(self, in_metadata): def _bad_metadata(self, in_metadata):
mstore = self.mox.CreateMockAnything() mstore = mock.Mock()
mstore.add(self.image_id, mox.IgnoreArg(), mstore.add.return_value = (self.location, self.size,
self.size, context=None).AndReturn( self.checksum, in_metadata)
(self.location, self.size, self.checksum, in_metadata)) mstore.__str__ = lambda self: "hello"
mstore.__str__ = lambda: "hello" mstore.__unicode__ = lambda self: "hello"
mstore.__unicode__ = lambda: "hello"
self.mox.ReplayAll()
self.assertRaises(glance_store.BackendException, self.assertRaises(glance_store.BackendException,
glance_store.store_add_to_backend, glance_store.store_add_to_backend,
@ -874,16 +866,15 @@ class TestStoreAddToBackend(utils.BaseTestCase):
self.data, self.data,
self.size, self.size,
mstore) mstore)
self.mox.VerifyAll()
mstore.add.assert_called_once_with(self.image_id, mock.ANY,
self.size, context=None)
def _good_metadata(self, in_metadata): def _good_metadata(self, in_metadata):
mstore = mock.Mock()
mstore.add.return_value = (self.location, self.size,
self.checksum, in_metadata)
mstore = self.mox.CreateMockAnything()
mstore.add(self.image_id, mox.IgnoreArg(),
self.size, context=None).AndReturn(
(self.location, self.size, self.checksum, in_metadata))
self.mox.ReplayAll()
(location, (location,
size, size,
checksum, checksum,
@ -891,7 +882,10 @@ class TestStoreAddToBackend(utils.BaseTestCase):
self.data, self.data,
self.size, self.size,
mstore) mstore)
self.mox.VerifyAll()
mstore.add.assert_called_once_with(self.image_id, mock.ANY,
self.size, context=None)
self.assertEqual(self.location, location) self.assertEqual(self.location, location)
self.assertEqual(self.size, size) self.assertEqual(self.size, size)
self.assertEqual(self.checksum, checksum) self.assertEqual(self.checksum, checksum)
@ -937,19 +931,4 @@ class TestStoreAddToBackend(utils.BaseTestCase):
self._bad_metadata(m) self._bad_metadata(m)
def test_bad_metadata_not_dict(self): def test_bad_metadata_not_dict(self):
store = self.mox.CreateMockAnything() self._bad_metadata([])
store.add(self.image_id, mox.IgnoreArg(),
self.size, context=None).AndReturn(
(self.location, self.size, self.checksum, []))
store.__str__ = lambda: "hello"
store.__unicode__ = lambda: "hello"
self.mox.ReplayAll()
self.assertRaises(glance_store.BackendException,
glance_store.store_add_to_backend,
self.image_id,
self.data,
self.size,
store)
self.mox.VerifyAll()

View File

@ -27,8 +27,8 @@ import fixtures
from oslo.serialization import jsonutils from oslo.serialization import jsonutils
from oslo_config import cfg from oslo_config import cfg
from oslo_utils import timeutils from oslo_utils import timeutils
from oslotest import moxstubout
import six import six
import stubout
import testtools import testtools
import webob import webob
@ -54,18 +54,14 @@ class BaseTestCase(testtools.TestCase):
# the following policy tests # the following policy tests
config.parse_args(args=[]) config.parse_args(args=[])
self.addCleanup(CONF.reset) self.addCleanup(CONF.reset)
self.stubs = stubout.StubOutForTesting() mox_fixture = self.useFixture(moxstubout.MoxStubout())
self.stubs = mox_fixture.stubs
self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True) self.stubs.Set(exception, '_FATAL_EXCEPTION_FORMAT_ERRORS', True)
self.test_dir = self.useFixture(fixtures.TempDir()).path self.test_dir = self.useFixture(fixtures.TempDir()).path
self.conf_dir = os.path.join(self.test_dir, 'etc') self.conf_dir = os.path.join(self.test_dir, 'etc')
utils.safe_mkdirs(self.conf_dir) utils.safe_mkdirs(self.conf_dir)
self.set_policy() self.set_policy()
def tearDown(self):
self.stubs.UnsetAll()
self.stubs.SmartUnsetAll()
super(BaseTestCase, self).tearDown()
def set_policy(self): def set_policy(self):
conf_file = "policy.json" conf_file = "policy.json"
self.policy_file = self._copy_data_file(conf_file, self.conf_dir) self.policy_file = self._copy_data_file(conf_file, self.conf_dir)

View File

@ -12,7 +12,7 @@ Babel>=1.3
coverage>=3.6 coverage>=3.6
discover discover
fixtures>=0.3.14 fixtures>=0.3.14
mox>=0.5.3 mox3>=0.7.0
mock>=1.0 mock>=1.0
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
requests>=2.2.0,!=2.4.0 requests>=2.2.0,!=2.4.0