Merge "python3: Remove mox support from oslo.config."

This commit is contained in:
Jenkins 2013-06-06 18:54:30 +00:00 committed by Gerrit Code Review
commit 13bcb0fa6c
3 changed files with 29 additions and 36 deletions

View File

@ -152,16 +152,18 @@ class FindConfigFilesTestCase(BaseTestCase):
config_files = [os.path.expanduser('~/.blaa/blaa.conf'),
'/etc/foo.conf']
self.stubs.Set(sys, 'argv', ['foo'])
self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
lambda p: p in config_files))
self.assertEquals(cfg.find_config_files(project='blaa'), config_files)
def test_find_config_files_with_extension(self):
config_files = ['/etc/foo.json']
self.stubs.Set(sys, 'argv', ['foo'])
self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
lambda p: p in config_files))
self.assertEquals(cfg.find_config_files(project='blaa'), [])
self.assertEquals(cfg.find_config_files(project='blaa',
@ -209,7 +211,9 @@ class DefaultConfigFilesTestCase(BaseTestCase):
def test_find_default_config_file(self):
paths = self.create_tempfiles([('def', '[DEFAULT]')])
self.stubs.Set(cfg, 'find_config_files', lambda project, prog: paths)
self.useFixture(fixtures.MonkeyPatch(
'oslo.config.cfg.find_config_files',
lambda project, prog: paths))
self.conf(args=[], default_config_files=None)
self.assertEquals(self.conf.config_file, paths)
@ -459,7 +463,7 @@ class CliOptsTestCase(BaseTestCase):
class CliSpecialOptsTestCase(BaseTestCase):
def test_help(self):
self.stubs.Set(sys, 'stdout', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertTrue('FOO BAR' in sys.stdout.getvalue())
self.assertTrue('--version' in sys.stdout.getvalue())
@ -467,7 +471,7 @@ class CliSpecialOptsTestCase(BaseTestCase):
self.assertTrue('--config-file' in sys.stdout.getvalue())
def test_version(self):
self.stubs.Set(sys, 'stderr', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--version'])
self.assertTrue('1.0' in sys.stderr.getvalue())
@ -2108,7 +2112,7 @@ class SadPathTestCase(BaseTestCase):
def test_bad_cli_arg(self):
self.conf.register_opt(cfg.BoolOpt('foo'))
self.stubs.Set(sys, 'stderr', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--foo'])
@ -2118,7 +2122,7 @@ class SadPathTestCase(BaseTestCase):
def _do_test_bad_cli_value(self, opt_class):
self.conf.register_cli_opt(opt_class('foo'))
self.stubs.Set(sys, 'stderr', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
@ -2202,7 +2206,9 @@ class FindFileTestCase(BaseTestCase):
def test_find_policy_file(self):
policy_file = '/etc/policy.json'
self.stubs.Set(os.path, 'exists', lambda p: p == policy_file)
self.useFixture(fixtures.MonkeyPatch(
'os.path.exists',
lambda p: p == policy_file))
self.conf([])
@ -2287,7 +2293,7 @@ class OptDumpingTestCase(BaseTestCase):
self._do_test_log_opt_values(self._args)
def test_log_opt_values_from_sys_argv(self):
self.stubs.Set(sys, 'argv', ['foo'] + self._args)
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo'] + self._args))
self._do_test_log_opt_values(None)
@ -2428,7 +2434,9 @@ class TildeExpansionTestCase(BaseTestCase):
except cfg.ConfigFilesNotFoundError as cfnfe:
self.assertTrue(homedir in str(cfnfe))
self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
self.useFixture(fixtures.MonkeyPatch(
'os.path.exists',
lambda p: p == tmpfile))
self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
@ -2440,7 +2448,9 @@ class TildeExpansionTestCase(BaseTestCase):
tmpfile = os.path.join(tmpdir, 'foo.conf')
tmpbase = os.path.basename(tmpfile)
self.stubs.Set(cfg.glob, 'glob', lambda p: [tmpfile])
self.useFixture(fixtures.MonkeyPatch(
'glob.glob',
lambda p: [tmpfile]))
try:
self.conf(['--config-dir',
@ -2448,7 +2458,9 @@ class TildeExpansionTestCase(BaseTestCase):
except cfg.ConfigFilesNotFoundError as cfnfe:
self.assertTrue(os.path.expanduser('~') in str(cfnfe))
self.stubs.Set(os.path, 'exists', lambda p: p == tmpfile)
self.useFixture(fixtures.MonkeyPatch(
'os.path.exists',
lambda p: p == tmpfile))
self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
@ -2525,7 +2537,7 @@ class SubCommandTestCase(BaseTestCase):
def test_sub_command_no_handler(self):
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd'))
self.stubs.Set(sys, 'stderr', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, [])
self.assertTrue('error' in sys.stderr.getvalue())
@ -2538,7 +2550,7 @@ class SubCommandTestCase(BaseTestCase):
description='bar bar',
help='blaa blaa',
handler=add_parsers))
self.stubs.Set(sys, 'stdout', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, ['--help'])
self.assertTrue('foo foo' in sys.stdout.getvalue())
self.assertTrue('bar bar' in sys.stdout.getvalue())
@ -2559,7 +2571,7 @@ class SubCommandTestCase(BaseTestCase):
def test_sub_command_multiple(self):
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1'))
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd2'))
self.stubs.Set(sys, 'stderr', moves.StringIO())
self.useFixture(fixtures.MonkeyPatch('sys.stderr', moves.StringIO()))
self.assertRaises(SystemExit, self.conf, [])
self.assertTrue('multiple' in sys.stderr.getvalue())

View File

@ -23,33 +23,15 @@
import os
import fixtures
import mox
import stubout
import testtools
TRUE_VALUES = ('true', '1', 'yes')
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 BaseTestCase(testtools.TestCase):
def setUp(self):
super(BaseTestCase, self).setUp()
self.stubs = self.useFixture(MoxStubout()).stubs
self.useFixture(fixtures.FakeLogger('oslo.config'))
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30)
try:

View File

@ -6,7 +6,6 @@ hacking>=0.5.3,<0.6
discover
fixtures>=0.3.12
mox
python-subunit
testrepository>=0.0.13
testscenarios<0.5