##// END OF EJS Templates
Convert from nose-style to ours a parametric test....
Fernando Perez -
Show More
@@ -1,113 +1,121
1 1 #-----------------------------------------------------------------------------
2 2 # Copyright (c) 2010, IPython Development Team.
3 3 #
4 4 # Distributed under the terms of the Modified BSD License.
5 5 #
6 6 # The full license is in the file COPYING.txt, distributed with this software.
7 7 #-----------------------------------------------------------------------------
8 8
9 9 from nose.tools import assert_equal, assert_true
10 10
11 11 from IPython.external import argparse
12 12 from IPython.core.magic_arguments import (argument, argument_group, kwds,
13 13 magic_arguments, parse_argstring, real_name)
14 from IPython.testing.decorators import parametric
14 15
15 16
16 17 @magic_arguments()
17 18 @argument('-f', '--foo', help="an argument")
18 19 def magic_foo1(self, args):
19 20 """ A docstring.
20 21 """
21 22 return parse_argstring(magic_foo1, args)
22 23
24
23 25 @magic_arguments()
24 26 def magic_foo2(self, args):
25 27 """ A docstring.
26 28 """
27 29 return parse_argstring(magic_foo2, args)
28 30
31
29 32 @magic_arguments()
30 33 @argument('-f', '--foo', help="an argument")
31 34 @argument_group('Group')
32 35 @argument('-b', '--bar', help="a grouped argument")
33 36 @argument_group('Second Group')
34 37 @argument('-z', '--baz', help="another grouped argument")
35 38 def magic_foo3(self, args):
36 39 """ A docstring.
37 40 """
38 41 return parse_argstring(magic_foo3, args)
39 42
43
40 44 @magic_arguments()
41 45 @kwds(argument_default=argparse.SUPPRESS)
42 46 @argument('-f', '--foo', help="an argument")
43 47 def magic_foo4(self, args):
44 48 """ A docstring.
45 49 """
46 50 return parse_argstring(magic_foo4, args)
47 51
52
48 53 @magic_arguments('frobnicate')
49 54 @argument('-f', '--foo', help="an argument")
50 55 def magic_foo5(self, args):
51 56 """ A docstring.
52 57 """
53 58 return parse_argstring(magic_foo5, args)
54 59
60
55 61 @magic_arguments()
56 62 @argument('-f', '--foo', help="an argument")
57 63 def magic_magic_foo(self, args):
58 64 """ A docstring.
59 65 """
60 66 return parse_argstring(magic_magic_foo, args)
61 67
68
62 69 @magic_arguments()
63 70 @argument('-f', '--foo', help="an argument")
64 71 def foo(self, args):
65 72 """ A docstring.
66 73 """
67 74 return parse_argstring(foo, args)
68 75
76
77 @parametric
69 78 def test_magic_arguments():
70 79 # Ideally, these would be doctests, but I could not get it to work.
71 yield assert_equal, magic_foo1.__doc__, '%foo1 [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
72 yield assert_equal, getattr(magic_foo1, 'argcmd_name', None), None
73 yield assert_equal, real_name(magic_foo1), 'foo1'
74 yield assert_equal, magic_foo1(None, ''), argparse.Namespace(foo=None)
75 yield assert_true, hasattr(magic_foo1, 'has_arguments')
76
77 yield assert_equal, magic_foo2.__doc__, '%foo2\n\nA docstring.\n'
78 yield assert_equal, getattr(magic_foo2, 'argcmd_name', None), None
79 yield assert_equal, real_name(magic_foo2), 'foo2'
80 yield assert_equal, magic_foo2(None, ''), argparse.Namespace()
81 yield assert_true, hasattr(magic_foo2, 'has_arguments')
82
83 yield assert_equal, magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n'
84 yield assert_equal, getattr(magic_foo3, 'argcmd_name', None), None
85 yield assert_equal, real_name(magic_foo3), 'foo3'
86 yield assert_equal, magic_foo3(None, ''), argparse.Namespace(bar=None, baz=None, foo=None)
87 yield assert_true, hasattr(magic_foo3, 'has_arguments')
88
89 yield assert_equal, magic_foo4.__doc__, '%foo4 [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
90 yield assert_equal, getattr(magic_foo4, 'argcmd_name', None), None
91 yield assert_equal, real_name(magic_foo4), 'foo4'
92 yield assert_equal, magic_foo4(None, ''), argparse.Namespace()
93 yield assert_true, hasattr(magic_foo4, 'has_arguments')
94
95 yield assert_equal, magic_foo5.__doc__, '%frobnicate [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
96 yield assert_equal, getattr(magic_foo5, 'argcmd_name', None), 'frobnicate'
97 yield assert_equal, real_name(magic_foo5), 'frobnicate'
98 yield assert_equal, magic_foo5(None, ''), argparse.Namespace(foo=None)
99 yield assert_true, hasattr(magic_foo5, 'has_arguments')
100
101 yield assert_equal, magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
102 yield assert_equal, getattr(magic_magic_foo, 'argcmd_name', None), None
103 yield assert_equal, real_name(magic_magic_foo), 'magic_foo'
104 yield assert_equal, magic_magic_foo(None, ''), argparse.Namespace(foo=None)
105 yield assert_true, hasattr(magic_magic_foo, 'has_arguments')
106
107 yield assert_equal, foo.__doc__, '%foo [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n'
108 yield assert_equal, getattr(foo, 'argcmd_name', None), None
109 yield assert_equal, real_name(foo), 'foo'
110 yield assert_equal, foo(None, ''), argparse.Namespace(foo=None)
111 yield assert_true, hasattr(foo, 'has_arguments')
112
113
80 yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
81 yield assert_equal(getattr(magic_foo1, 'argcmd_name', None), None)
82 yield assert_equal(real_name(magic_foo1), 'foo1')
83 yield assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None))
84 yield assert_true(hasattr(magic_foo1, 'has_arguments'))
85
86 yield assert_equal(magic_foo2.__doc__, '%foo2\n\nA docstring.\n')
87 yield assert_equal(getattr(magic_foo2, 'argcmd_name', None), None)
88 yield assert_equal(real_name(magic_foo2), 'foo2')
89 yield assert_equal(magic_foo2(None, ''), argparse.Namespace())
90 yield assert_true(hasattr(magic_foo2, 'has_arguments'))
91
92 yield assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n')
93 yield assert_equal(getattr(magic_foo3, 'argcmd_name', None), None)
94 yield assert_equal(real_name(magic_foo3), 'foo3')
95 yield assert_equal(magic_foo3(None, ''),
96 argparse.Namespace(bar=None, baz=None, foo=None))
97 yield assert_true(hasattr(magic_foo3, 'has_arguments'))
98
99 yield assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
100 yield assert_equal(getattr(magic_foo4, 'argcmd_name', None), None)
101 yield assert_equal(real_name(magic_foo4), 'foo4')
102 yield assert_equal(magic_foo4(None, ''), argparse.Namespace())
103 yield assert_true(hasattr(magic_foo4, 'has_arguments'))
104
105 yield assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
106 yield assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate')
107 yield assert_equal(real_name(magic_foo5), 'frobnicate')
108 yield assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None))
109 yield assert_true(hasattr(magic_foo5, 'has_arguments'))
110
111 yield assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
112 yield assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None)
113 yield assert_equal(real_name(magic_magic_foo), 'magic_foo')
114 yield assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None))
115 yield assert_true(hasattr(magic_magic_foo, 'has_arguments'))
116
117 yield assert_equal(foo.__doc__, '%foo [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
118 yield assert_equal(getattr(foo, 'argcmd_name', None), None)
119 yield assert_equal(real_name(foo), 'foo')
120 yield assert_equal(foo(None, ''), argparse.Namespace(foo=None))
121 yield assert_true(hasattr(foo, 'has_arguments'))
General Comments 0
You need to be logged in to leave comments. Login now