@@ -149,37 +149,6 @@ def test_case_insensitive_long_options_with_equal_sign(self):
149149 assert_equals (opts ['variable' ], ['X:y' , 'ZzZ' ])
150150 assert_equals (args , [])
151151
152- def test_check_args_with_correct_args (self ):
153- for arg in ['hello' , 'hello world' ]:
154- self .ap .parse_args ([arg ], check_args = True )
155-
156- def test_check_args_with_wrong_number_of_args (self ):
157- for args in [(), ('arg1' , 'arg2' , 'arg3' )]:
158- assert_raises (DataError , self .ap ._check_args , args )
159-
160- def test_check_variable_number_of_args (self ):
161- ap = ArgumentParser ('usage: robot.py [options] args' )
162- ap .parse_args (['one_is_ok' ], check_args = True )
163- ap .parse_args (['two' , 'ok' ], check_args = True )
164- ap .parse_args (['this' , 'should' , 'also' , 'work' , '!' ], check_args = True )
165- assert_raises_with_msg (DataError , "Expected at least 1 argument, got 0." ,
166- ap ._check_args , [])
167-
168- def test_arg_limits_to_constructor (self ):
169- ap = ArgumentParser ('usage: test.py [options] args' , arg_limits = (2 ,4 ))
170- assert_raises_with_msg (DataError , "Expected 2 to 4 arguments, got 1." ,
171- ap ._check_args , ['one is not enough' ])
172-
173- def test_reading_args_from_usage_when_it_has_just_options (self ):
174- ap = ArgumentParser ('usage: test.py [options]' )
175- ap .parse_args ([], check_args = True )
176- assert_raises_with_msg (DataError , "Expected 0 arguments, got 2." ,
177- ap ._check_args , ['1' , '2' ])
178-
179- def test_check_args_fails_when_no_args_specified (self ):
180- assert_raises (FrameworkError , ArgumentParser ('test' ).parse_args ,
181- [], check_args = True )
182-
183152 def test_unescape_options (self ):
184153 cli = '--escape quot:Q -E space:SP -E lt:LT -E gt:GT ' \
185154 + '-N QQQLTmySPfineSPnameGTQQQ sourceSPwithSPspaces'
@@ -225,6 +194,42 @@ def test_arguments_with_glob_patterns_arent_removed_if_they_dont_match(self):
225194 assert_equals (args , ['*.non.existing' , 'non.ex.??' ])
226195
227196
197+ class TestArgumentValidation (unittest .TestCase ):
198+
199+ def test_check_args_with_correct_args (self ):
200+ ap = ArgumentParser (USAGE )
201+ for arg in ['hello' , 'hello world' ]:
202+ ap .parse_args ([arg ], check_args = True )
203+
204+ def test_check_args_with_wrong_number_of_args (self ):
205+ ap = ArgumentParser (USAGE )
206+ for args in [(), ('arg1' , 'arg2' , 'arg3' )]:
207+ assert_raises (DataError , ap ._check_args , args )
208+
209+ def test_check_variable_number_of_args (self ):
210+ ap = ArgumentParser ('usage: robot.py [options] args' )
211+ ap .parse_args (['one_is_ok' ], check_args = True )
212+ ap .parse_args (['two' , 'ok' ], check_args = True )
213+ ap .parse_args (['this' , 'should' , 'also' , 'work' , '!' ], check_args = True )
214+ assert_raises_with_msg (DataError , "Expected at least 1 argument, got 0." ,
215+ ap ._check_args , [])
216+
217+ def test_arg_limits_to_constructor (self ):
218+ ap = ArgumentParser ('usage: test.py [options] args' , arg_limits = (2 ,4 ))
219+ assert_raises_with_msg (DataError , "Expected 2 to 4 arguments, got 1." ,
220+ ap ._check_args , ['one is not enough' ])
221+
222+ def test_reading_args_from_usage_when_it_has_just_options (self ):
223+ ap = ArgumentParser ('usage: test.py [options]' )
224+ ap .parse_args ([], check_args = True )
225+ assert_raises_with_msg (DataError , "Expected 0 arguments, got 2." ,
226+ ap ._check_args , ['1' , '2' ])
227+
228+ def test_check_args_fails_when_no_args_specified (self ):
229+ assert_raises (FrameworkError , ArgumentParser ('test' ).parse_args ,
230+ [], check_args = True )
231+
232+
228233class TestPrintHelpAndVersion (unittest .TestCase ):
229234
230235 def setUp (self ):
0 commit comments