Add assertions to verify placement-manage error output
The tests for placement-manage, in unit/cmd/test_manage were not verifying help message output when partial or incorrect commands were provided. This led to some confusion when trying to verify a fix related to different behaviors of argparse. Here, some verification is added. Because of differences between python 2 and 3, we need to look at stderr and stdout, respectively, to verify the output. Change-Id: I337a25cfdc23bc56fbf15f128a94d2b1b1d1b664 Related-Bug: #1804420
This commit is contained in:
parent
ce7b05a1f9
commit
da20d6101d
|
@ -30,7 +30,8 @@ class TestCommandParsers(testtools.TestCase):
|
|||
self.useFixture(conf_fixture)
|
||||
# Quiet output from argparse (used within oslo_config).
|
||||
# If you are debugging, commenting this out might be useful.
|
||||
self.useFixture(output.CaptureOutput(do_stderr=True))
|
||||
self.output = self.useFixture(
|
||||
output.CaptureOutput(do_stderr=True, do_stdout=True))
|
||||
# We don't use a database, but we need to set the opt as
|
||||
# it's required for a valid config.
|
||||
conf_fixture.config(group="placement_database", connection='sqlite://')
|
||||
|
@ -79,3 +80,24 @@ class TestCommandParsers(testtools.TestCase):
|
|||
def test_too_many_args(self):
|
||||
self.assertRaises(SystemExit,
|
||||
self.conf, ['version', '5'], default_config_files=[])
|
||||
self.output.stderr.seek(0)
|
||||
self.assertIn("choose from 'db'", self.output.stderr.read())
|
||||
|
||||
def test_help_message(self):
|
||||
"""Test that help output for sub commands shows right commands."""
|
||||
# This is noisy because we have different 'help' behaviors in
|
||||
# Python 2 and 3.
|
||||
if six.PY2:
|
||||
self.assertRaises(SystemExit, self.conf, ['db'],
|
||||
default_config_files=[])
|
||||
else:
|
||||
self.conf(['db'], default_config_files=[])
|
||||
self.conf.command.func()
|
||||
|
||||
self.output.stdout.seek(0)
|
||||
self.output.stderr.seek(0)
|
||||
|
||||
if six.PY2:
|
||||
self.assertIn('{sync,version}', self.output.stderr.read())
|
||||
else:
|
||||
self.assertIn('{sync,version}', self.output.stdout.read())
|
||||
|
|
Loading…
Reference in New Issue