From 8d718e9d6796b0ff115698a19f330113a80d09ef Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Mon, 28 Dec 2015 17:34:28 +0800 Subject: [PATCH] Refactor: Initialize parser in setUp() in TestNonNegativeAction Change-Id: I12846acc4450d31d19897bbdfc6846bde8c8f2ce --- .../tests/common/test_parseractions.py | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/openstackclient/tests/common/test_parseractions.py b/openstackclient/tests/common/test_parseractions.py index 0d9961bcb1..0109a3f3d9 100644 --- a/openstackclient/tests/common/test_parseractions.py +++ b/openstackclient/tests/common/test_parseractions.py @@ -62,35 +62,29 @@ class TestKeyValueAction(utils.TestCase): class TestNonNegativeAction(utils.TestCase): - def test_negative_values(self): - parser = argparse.ArgumentParser() + + def setUp(self): + super(TestNonNegativeAction, self).setUp() + + self.parser = argparse.ArgumentParser() # Set up our typical usage - parser.add_argument( + self.parser.add_argument( '--foo', metavar='', type=int, action=parseractions.NonNegativeAction, ) + def test_negative_values(self): self.assertRaises( argparse.ArgumentTypeError, - parser.parse_args, + self.parser.parse_args, "--foo -1".split() ) def test_zero_values(self): - parser = argparse.ArgumentParser() - - # Set up our typical usage - parser.add_argument( - '--foo', - metavar='', - type=int, - action=parseractions.NonNegativeAction, - ) - - results = parser.parse_args( + results = self.parser.parse_args( '--foo 0'.split() ) @@ -98,17 +92,7 @@ class TestNonNegativeAction(utils.TestCase): self.assertEqual(actual, 0) def test_positive_values(self): - parser = argparse.ArgumentParser() - - # Set up our typical usage - parser.add_argument( - '--foo', - metavar='', - type=int, - action=parseractions.NonNegativeAction, - ) - - results = parser.parse_args( + results = self.parser.parse_args( '--foo 1'.split() )