Removed unused mox testing utilities
Change-Id: Ia81030f599f5712d020ba1fe83bc784785da2c71
This commit is contained in:
parent
6d96351b37
commit
39a43aa9a6
@ -5,8 +5,6 @@ coverage>=3.6
|
|||||||
discover
|
discover
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
mox>=0.5.3
|
|
||||||
python-subunit
|
|
||||||
# Doc requirements
|
# Doc requirements
|
||||||
sphinx>=1.1.2,<1.2
|
sphinx>=1.1.2,<1.2
|
||||||
sphinxcontrib-pecanwsme>=0.5
|
sphinxcontrib-pecanwsme>=0.5
|
||||||
|
@ -26,12 +26,9 @@ eventlet.monkey_patch(os=False)
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import mox
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import stubout
|
|
||||||
import testtools
|
import testtools
|
||||||
import unittest2
|
import unittest2
|
||||||
|
|
||||||
@ -105,38 +102,6 @@ class Database(fixtures.Fixture):
|
|||||||
"""Any addition steps that are needed outside of the migrations."""
|
"""Any addition steps that are needed outside of the migrations."""
|
||||||
|
|
||||||
|
|
||||||
class ReplaceModule(fixtures.Fixture):
|
|
||||||
"""Replace a module with a fake module."""
|
|
||||||
|
|
||||||
def __init__(self, name, new_value):
|
|
||||||
self.name = name
|
|
||||||
self.new_value = new_value
|
|
||||||
|
|
||||||
def _restore(self, old_value):
|
|
||||||
sys.modules[self.name] = old_value
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(ReplaceModule, self).setUp()
|
|
||||||
old_value = sys.modules.get(self.name)
|
|
||||||
sys.modules[self.name] = self.new_value
|
|
||||||
self.addCleanup(self._restore, old_value)
|
|
||||||
|
|
||||||
|
|
||||||
class MoxStubout(fixtures.Fixture):
|
|
||||||
"""Deal with code around mox and stubout as a fixture."""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(MoxStubout, self).setUp()
|
|
||||||
# emulate some of the mox stuff, we can't use the metaclass
|
|
||||||
# because it screws with our generators
|
|
||||||
self.mox = mox.Mox()
|
|
||||||
self.stubs = stubout.StubOutForTesting()
|
|
||||||
self.addCleanup(self.mox.UnsetStubs)
|
|
||||||
self.addCleanup(self.stubs.UnsetAll)
|
|
||||||
self.addCleanup(self.stubs.SmartUnsetAll)
|
|
||||||
self.addCleanup(self.mox.VerifyAll)
|
|
||||||
|
|
||||||
|
|
||||||
class TestingException(Exception):
|
class TestingException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -182,9 +147,6 @@ class TestCase(testtools.TestCase, unittest2.TestCase):
|
|||||||
)
|
)
|
||||||
self.useFixture(_DB_CACHE)
|
self.useFixture(_DB_CACHE)
|
||||||
|
|
||||||
mox_fixture = self.useFixture(MoxStubout())
|
|
||||||
self.mox = mox_fixture.mox
|
|
||||||
self.stubs = mox_fixture.stubs
|
|
||||||
self.addCleanup(self._clear_attrs)
|
self.addCleanup(self._clear_attrs)
|
||||||
self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
|
self.useFixture(fixtures.EnvironmentVariable('http_proxy'))
|
||||||
self.policy = self.useFixture(policy_fixture.PolicyFixture())
|
self.policy = self.useFixture(policy_fixture.PolicyFixture())
|
||||||
|
@ -13,57 +13,10 @@
|
|||||||
# 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 os
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
import mox
|
|
||||||
import six.moves.builtins as __builtin__
|
|
||||||
|
|
||||||
from tuskar.common import utils
|
from tuskar.common import utils
|
||||||
from tuskar.tests import base
|
from tuskar.tests import base
|
||||||
|
|
||||||
|
|
||||||
class GenericUtilsTestCase(base.TestCase):
|
|
||||||
|
|
||||||
def test_read_cached_file(self):
|
|
||||||
self.mox.StubOutWithMock(os.path, "getmtime")
|
|
||||||
os.path.getmtime(mox.IgnoreArg()).AndReturn(1)
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
|
|
||||||
cache_data = {"data": 1123, "mtime": 1}
|
|
||||||
data = utils.read_cached_file("/this/is/a/fake", cache_data)
|
|
||||||
self.assertEqual(cache_data["data"], data)
|
|
||||||
|
|
||||||
def test_read_modified_cached_file(self):
|
|
||||||
self.mox.StubOutWithMock(os.path, "getmtime")
|
|
||||||
self.mox.StubOutWithMock(__builtin__, 'open')
|
|
||||||
os.path.getmtime(mox.IgnoreArg()).AndReturn(2)
|
|
||||||
|
|
||||||
fake_contents = "lorem ipsum"
|
|
||||||
fake_file = self.mox.CreateMockAnything()
|
|
||||||
fake_file.read().AndReturn(fake_contents)
|
|
||||||
fake_context_manager = self.mox.CreateMockAnything()
|
|
||||||
fake_context_manager.__enter__().AndReturn(fake_file)
|
|
||||||
fake_context_manager.__exit__(mox.IgnoreArg(),
|
|
||||||
mox.IgnoreArg(),
|
|
||||||
mox.IgnoreArg())
|
|
||||||
|
|
||||||
__builtin__.open(mox.IgnoreArg()).AndReturn(fake_context_manager)
|
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
cache_data = {"data": 1123, "mtime": 1}
|
|
||||||
self.reload_called = False
|
|
||||||
|
|
||||||
def test_reload(reloaded_data):
|
|
||||||
self.assertEqual(reloaded_data, fake_contents)
|
|
||||||
self.reload_called = True
|
|
||||||
|
|
||||||
data = utils.read_cached_file(
|
|
||||||
"/this/is/a/fake", cache_data, reload_func=test_reload)
|
|
||||||
self.assertEqual(data, fake_contents)
|
|
||||||
self.assertTrue(self.reload_called)
|
|
||||||
|
|
||||||
|
|
||||||
class IntLikeTestCase(base.TestCase):
|
class IntLikeTestCase(base.TestCase):
|
||||||
|
|
||||||
def test_is_int_like(self):
|
def test_is_int_like(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user