mirror of
https://opendev.org/openstack/python-openstackclient.git
synced 2026-01-17 07:20:45 +00:00
Refactor: Initialize parser in setUp() in TestNonNegativeAction
Change-Id: I12846acc4450d31d19897bbdfc6846bde8c8f2ce
This commit is contained in:
parent
f0a3b175a1
commit
8d718e9d67
1 changed files with 10 additions and 26 deletions
|
|
@ -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='<foo>',
|
||||
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='<foo>',
|
||||
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='<foo>',
|
||||
type=int,
|
||||
action=parseractions.NonNegativeAction,
|
||||
)
|
||||
|
||||
results = parser.parse_args(
|
||||
results = self.parser.parse_args(
|
||||
'--foo 1'.split()
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue