Skip to content

Commit

Permalink
Test that optfunc.run passes the correct arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Willison committed May 28, 2009
1 parent 15a73da commit d2e36f3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test.py
Expand Up @@ -33,7 +33,7 @@ def test_one_arg_one_option(self):

has_run = [False]
def func(one, two=optfunc.Var('-o', '--option')):
has_run[0] = True
has_run[0] = (one, two)

# Should have -o option as well as -h option
parser, required_args = optfunc.func_to_optionparser(func)
Expand All @@ -45,7 +45,17 @@ def func(one, two=optfunc.Var('-o', '--option')):
# Should have one required arg
self.assertEqual(required_args, ['one'])



# Should execute
self.assert_(not has_run[0])
optfunc.run(func, ['the-required', '-o', 'the-option'])
self.assert_(has_run[0])
self.assertEqual(has_run[0], ('the-required', 'the-option'))

# Option should be optional
has_run[0] = False
optfunc.run(func, ['required2'])
self.assert_(has_run[0])
self.assertEqual(has_run[0], ('required2', None))

if __name__ == '__main__':
unittest.main()

0 comments on commit d2e36f3

Please sign in to comment.