Refactor: Initialize parser in setUp() in TestNonNegativeAction

Change-Id: I12846acc4450d31d19897bbdfc6846bde8c8f2ce
This commit is contained in:
Tang Chen 2015-12-28 17:34:28 +08:00
parent f0a3b175a1
commit 8d718e9d67

View File

@ -62,35 +62,29 @@ class TestKeyValueAction(utils.TestCase):
class TestNonNegativeAction(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 # Set up our typical usage
parser.add_argument( self.parser.add_argument(
'--foo', '--foo',
metavar='<foo>', metavar='<foo>',
type=int, type=int,
action=parseractions.NonNegativeAction, action=parseractions.NonNegativeAction,
) )
def test_negative_values(self):
self.assertRaises( self.assertRaises(
argparse.ArgumentTypeError, argparse.ArgumentTypeError,
parser.parse_args, self.parser.parse_args,
"--foo -1".split() "--foo -1".split()
) )
def test_zero_values(self): def test_zero_values(self):
parser = argparse.ArgumentParser() results = self.parser.parse_args(
# Set up our typical usage
parser.add_argument(
'--foo',
metavar='<foo>',
type=int,
action=parseractions.NonNegativeAction,
)
results = parser.parse_args(
'--foo 0'.split() '--foo 0'.split()
) )
@ -98,17 +92,7 @@ class TestNonNegativeAction(utils.TestCase):
self.assertEqual(actual, 0) self.assertEqual(actual, 0)
def test_positive_values(self): def test_positive_values(self):
parser = argparse.ArgumentParser() results = self.parser.parse_args(
# Set up our typical usage
parser.add_argument(
'--foo',
metavar='<foo>',
type=int,
action=parseractions.NonNegativeAction,
)
results = parser.parse_args(
'--foo 1'.split() '--foo 1'.split()
) )