@@ -62,53 +62,37 @@ def test_error_values(self):
6262
6363
6464class TestNonNegativeAction (utils .TestCase ):
65- def test_negative_values (self ):
66- parser = argparse .ArgumentParser ()
65+
66+ def setUp (self ):
67+ super (TestNonNegativeAction , self ).setUp ()
68+
69+ self .parser = argparse .ArgumentParser ()
6770
6871 # Set up our typical usage
69- parser .add_argument (
72+ self . parser .add_argument (
7073 '--foo' ,
7174 metavar = '<foo>' ,
7275 type = int ,
7376 action = parseractions .NonNegativeAction ,
7477 )
7578
79+ def test_negative_values (self ):
7680 self .assertRaises (
7781 argparse .ArgumentTypeError ,
78- parser .parse_args ,
82+ self . parser .parse_args ,
7983 "--foo -1" .split ()
8084 )
8185
8286 def test_zero_values (self ):
83- parser = argparse .ArgumentParser ()
84-
85- # Set up our typical usage
86- parser .add_argument (
87- '--foo' ,
88- metavar = '<foo>' ,
89- type = int ,
90- action = parseractions .NonNegativeAction ,
91- )
92-
93- results = parser .parse_args (
87+ results = self .parser .parse_args (
9488 '--foo 0' .split ()
9589 )
9690
9791 actual = getattr (results , 'foo' , None )
9892 self .assertEqual (actual , 0 )
9993
10094 def test_positive_values (self ):
101- parser = argparse .ArgumentParser ()
102-
103- # Set up our typical usage
104- parser .add_argument (
105- '--foo' ,
106- metavar = '<foo>' ,
107- type = int ,
108- action = parseractions .NonNegativeAction ,
109- )
110-
111- results = parser .parse_args (
95+ results = self .parser .parse_args (
11296 '--foo 1' .split ()
11397 )
11498
0 commit comments