From cfcb750a97af1ab82b425532437456c22dcebad9 Mon Sep 17 00:00:00 2001
From: Tang Chen <chen.tang@easystack.cn>
Date: Sun, 14 Feb 2016 18:43:19 +0800
Subject: [PATCH] Use assertRaises() to check if an exception is raised

In some test cases, try/except is used to check if an exception
has been raised. We should use assertRaises() instead.

Change-Id: I15c8e757dcab77fd6f895feb018184e1eb7e617b
---
 .../tests/compute/v2/test_server.py           |  9 ++++----
 .../tests/network/v2/test_network.py          | 16 +++++--------
 .../tests/network/v2/test_router.py           | 23 ++++++++-----------
 3 files changed, 19 insertions(+), 29 deletions(-)

diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py
index a80eaf51e6..95188522fa 100644
--- a/openstackclient/tests/compute/v2/test_server.py
+++ b/openstackclient/tests/compute/v2/test_server.py
@@ -143,11 +143,10 @@ class TestServerCreate(TestServer):
         verifylist = [
             ('server_name', self.new_server.name),
         ]
-        try:
-            # Missing required args should bail here
-            self.check_parser(self.cmd, arglist, verifylist)
-        except utils.ParserException:
-            pass
+
+        # Missing required args should bail here
+        self.assertRaises(utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_server_create_minimal(self):
         arglist = [
diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py
index d6c6fbca2f..4b73e68027 100644
--- a/openstackclient/tests/network/v2/test_network.py
+++ b/openstackclient/tests/network/v2/test_network.py
@@ -103,11 +103,9 @@ class TestCreateNetworkIdentityV3(TestNetwork):
         arglist = []
         verifylist = []
 
-        try:
-            # Missing required args should bail here
-            self.check_parser(self.cmd, arglist, verifylist)
-        except tests_utils.ParserException:
-            pass
+        # Missing required args should bail here
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_create_default_options(self):
         arglist = [
@@ -542,11 +540,9 @@ class TestShowNetwork(TestNetwork):
         arglist = []
         verifylist = []
 
-        try:
-            # Missing required args should bail here
-            self.check_parser(self.cmd, arglist, verifylist)
-        except tests_utils.ParserException:
-            pass
+        # Missing required args should bail here
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_show_all_options(self):
         arglist = [
diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py
index 69c548a0b7..05bb7857e2 100644
--- a/openstackclient/tests/network/v2/test_router.py
+++ b/openstackclient/tests/network/v2/test_router.py
@@ -63,10 +63,9 @@ class TestCreateRouter(TestRouter):
         arglist = []
         verifylist = []
 
-        try:
-            self.check_parser(self.cmd, arglist, verifylist)
-        except tests_utils.ParserException:
-            pass
+        # Missing required args should bail here
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_create_default_options(self):
         arglist = [
@@ -303,11 +302,9 @@ class TestSetRouter(TestRouter):
             ('distributed', False),
         ]
 
-        try:
-            # Argument parse failing should bail here
-            self.check_parser(self.cmd, arglist, verifylist)
-        except tests_utils.ParserException:
-            pass
+        # Missing required args should bail here
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_set_nothing(self):
         arglist = [self._router.name, ]
@@ -353,11 +350,9 @@ class TestShowRouter(TestRouter):
         arglist = []
         verifylist = []
 
-        try:
-            # Missing required args should bail here
-            self.check_parser(self.cmd, arglist, verifylist)
-        except tests_utils.ParserException:
-            pass
+        # Missing required args should bail here
+        self.assertRaises(tests_utils.ParserException, self.check_parser,
+                          self.cmd, arglist, verifylist)
 
     def test_show_all_options(self):
         arglist = [