Use assertRaises instead of try/except/else

Change-Id: I8b1105404511c003e032f03777ce85325abbe0cd
This commit is contained in:
Steve Baker
2014-01-08 13:45:31 +13:00
parent b6f81d5124
commit 8b0725d7fb

View File

@@ -67,18 +67,13 @@ class TestCase(testtools.TestCase):
def shell_error(self, argstr, error_match):
orig = sys.stderr
try:
sys.stderr = six.StringIO()
_shell = heatclient.shell.HeatShell()
_shell.main(argstr.split())
except Exception as e:
self.assertRegexpMatches(e.__str__(), error_match)
else:
self.fail('Expected error matching: %s' % error_match)
finally:
err = sys.stderr.getvalue()
sys.stderr.close()
sys.stderr = orig
sys.stderr = six.StringIO()
_shell = heatclient.shell.HeatShell()
e = self.assertRaises(Exception, _shell.main, argstr.split())
self.assertRegexpMatches(e.__str__(), error_match)
err = sys.stderr.getvalue()
sys.stderr.close()
sys.stderr = orig
return err