Merge "python3: Remove mox support from oslo.config."
This commit is contained in:
commit
13bcb0fa6c
@ -152,16 +152,18 @@ class FindConfigFilesTestCase(BaseTestCase):
|
|||||||
config_files = [os.path.expanduser('~/.blaa/blaa.conf'),
|
config_files = [os.path.expanduser('~/.blaa/blaa.conf'),
|
||||||
'/etc/foo.conf']
|
'/etc/foo.conf']
|
||||||
|
|
||||||
self.stubs.Set(sys, 'argv', ['foo'])
|
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
|
||||||
self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
|
self.useFixture(fixtures.MonkeyPatch('os.path.exists',
|
||||||
|
lambda p: p in config_files))
|
||||||
|
|
||||||
self.assertEquals(cfg.find_config_files(project='blaa'), config_files)
|
self.assertEquals(cfg.find_config_files(project='blaa'), config_files)
|
||||||
|
|
||||||
def test_find_config_files_with_extension(self):
|
def test_find_config_files_with_extension(self):
|
||||||
config_files = ['/etc/foo.json']
|
config_files = ['/etc/foo.json']
|
||||||
|
|
||||||
self.stubs.Set(sys, 'argv', ['foo'])
|
self.useFixture(fixtures.MonkeyPatch('sys.argv', ['foo']))
|
||||||
self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
|
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'), [])
|
||||||
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):
|
def test_find_default_config_file(self):
|
||||||
paths = self.create_tempfiles([('def', '[DEFAULT]')])
|
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.conf(args=[], default_config_files=None)
|
||||||
self.assertEquals(self.conf.config_file, paths)
|
self.assertEquals(self.conf.config_file, paths)
|
||||||
@ -459,7 +463,7 @@ class CliOptsTestCase(BaseTestCase):
|
|||||||
class CliSpecialOptsTestCase(BaseTestCase):
|
class CliSpecialOptsTestCase(BaseTestCase):
|
||||||
|
|
||||||
def test_help(self):
|
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.assertRaises(SystemExit, self.conf, ['--help'])
|
||||||
self.assertTrue('FOO BAR' in sys.stdout.getvalue())
|
self.assertTrue('FOO BAR' in sys.stdout.getvalue())
|
||||||
self.assertTrue('--version' 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())
|
self.assertTrue('--config-file' in sys.stdout.getvalue())
|
||||||
|
|
||||||
def test_version(self):
|
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.assertRaises(SystemExit, self.conf, ['--version'])
|
||||||
self.assertTrue('1.0' in sys.stderr.getvalue())
|
self.assertTrue('1.0' in sys.stderr.getvalue())
|
||||||
|
|
||||||
@ -2108,7 +2112,7 @@ class SadPathTestCase(BaseTestCase):
|
|||||||
def test_bad_cli_arg(self):
|
def test_bad_cli_arg(self):
|
||||||
self.conf.register_opt(cfg.BoolOpt('foo'))
|
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'])
|
self.assertRaises(SystemExit, self.conf, ['--foo'])
|
||||||
|
|
||||||
@ -2118,7 +2122,7 @@ class SadPathTestCase(BaseTestCase):
|
|||||||
def _do_test_bad_cli_value(self, opt_class):
|
def _do_test_bad_cli_value(self, opt_class):
|
||||||
self.conf.register_cli_opt(opt_class('foo'))
|
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'])
|
self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
|
||||||
|
|
||||||
@ -2202,7 +2206,9 @@ class FindFileTestCase(BaseTestCase):
|
|||||||
def test_find_policy_file(self):
|
def test_find_policy_file(self):
|
||||||
policy_file = '/etc/policy.json'
|
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([])
|
self.conf([])
|
||||||
|
|
||||||
@ -2287,7 +2293,7 @@ class OptDumpingTestCase(BaseTestCase):
|
|||||||
self._do_test_log_opt_values(self._args)
|
self._do_test_log_opt_values(self._args)
|
||||||
|
|
||||||
def test_log_opt_values_from_sys_argv(self):
|
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)
|
self._do_test_log_opt_values(None)
|
||||||
|
|
||||||
|
|
||||||
@ -2428,7 +2434,9 @@ class TildeExpansionTestCase(BaseTestCase):
|
|||||||
except cfg.ConfigFilesNotFoundError as cfnfe:
|
except cfg.ConfigFilesNotFoundError as cfnfe:
|
||||||
self.assertTrue(homedir in str(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)
|
self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
|
||||||
|
|
||||||
@ -2440,7 +2448,9 @@ class TildeExpansionTestCase(BaseTestCase):
|
|||||||
tmpfile = os.path.join(tmpdir, 'foo.conf')
|
tmpfile = os.path.join(tmpdir, 'foo.conf')
|
||||||
tmpbase = os.path.basename(tmpfile)
|
tmpbase = os.path.basename(tmpfile)
|
||||||
|
|
||||||
self.stubs.Set(cfg.glob, 'glob', lambda p: [tmpfile])
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
|
'glob.glob',
|
||||||
|
lambda p: [tmpfile]))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.conf(['--config-dir',
|
self.conf(['--config-dir',
|
||||||
@ -2448,7 +2458,9 @@ class TildeExpansionTestCase(BaseTestCase):
|
|||||||
except cfg.ConfigFilesNotFoundError as cfnfe:
|
except cfg.ConfigFilesNotFoundError as cfnfe:
|
||||||
self.assertTrue(os.path.expanduser('~') in str(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)
|
self.assertEquals(self.conf.find_file(tmpbase), tmpfile)
|
||||||
|
|
||||||
@ -2525,7 +2537,7 @@ class SubCommandTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_sub_command_no_handler(self):
|
def test_sub_command_no_handler(self):
|
||||||
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd'))
|
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.assertRaises(SystemExit, self.conf, [])
|
||||||
self.assertTrue('error' in sys.stderr.getvalue())
|
self.assertTrue('error' in sys.stderr.getvalue())
|
||||||
|
|
||||||
@ -2538,7 +2550,7 @@ class SubCommandTestCase(BaseTestCase):
|
|||||||
description='bar bar',
|
description='bar bar',
|
||||||
help='blaa blaa',
|
help='blaa blaa',
|
||||||
handler=add_parsers))
|
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.assertRaises(SystemExit, self.conf, ['--help'])
|
||||||
self.assertTrue('foo foo' in sys.stdout.getvalue())
|
self.assertTrue('foo foo' in sys.stdout.getvalue())
|
||||||
self.assertTrue('bar bar' 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):
|
def test_sub_command_multiple(self):
|
||||||
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1'))
|
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd1'))
|
||||||
self.conf.register_cli_opt(cfg.SubCommandOpt('cmd2'))
|
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.assertRaises(SystemExit, self.conf, [])
|
||||||
self.assertTrue('multiple' in sys.stderr.getvalue())
|
self.assertTrue('multiple' in sys.stderr.getvalue())
|
||||||
|
|
||||||
|
@ -23,33 +23,15 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import mox
|
|
||||||
import stubout
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
TRUE_VALUES = ('true', '1', 'yes')
|
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):
|
class BaseTestCase(testtools.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BaseTestCase, self).setUp()
|
super(BaseTestCase, self).setUp()
|
||||||
self.stubs = self.useFixture(MoxStubout()).stubs
|
|
||||||
self.useFixture(fixtures.FakeLogger('oslo.config'))
|
self.useFixture(fixtures.FakeLogger('oslo.config'))
|
||||||
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30)
|
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 30)
|
||||||
try:
|
try:
|
||||||
|
@ -6,7 +6,6 @@ hacking>=0.5.3,<0.6
|
|||||||
|
|
||||||
discover
|
discover
|
||||||
fixtures>=0.3.12
|
fixtures>=0.3.12
|
||||||
mox
|
|
||||||
python-subunit
|
python-subunit
|
||||||
testrepository>=0.0.13
|
testrepository>=0.0.13
|
||||||
testscenarios<0.5
|
testscenarios<0.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user