Show More
@@ -1,121 +1,121 b'' | |||
|
1 | 1 | #----------------------------------------------------------------------------- |
|
2 | 2 | # Copyright (C) 2010-2011, 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 | 14 | from IPython.testing.decorators import parametric |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | @magic_arguments() |
|
18 | 18 | @argument('-f', '--foo', help="an argument") |
|
19 | 19 | def magic_foo1(self, args): |
|
20 | 20 | """ A docstring. |
|
21 | 21 | """ |
|
22 | 22 | return parse_argstring(magic_foo1, args) |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | @magic_arguments() |
|
26 | 26 | def magic_foo2(self, args): |
|
27 | 27 | """ A docstring. |
|
28 | 28 | """ |
|
29 | 29 | return parse_argstring(magic_foo2, args) |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | @magic_arguments() |
|
33 | 33 | @argument('-f', '--foo', help="an argument") |
|
34 | 34 | @argument_group('Group') |
|
35 | 35 | @argument('-b', '--bar', help="a grouped argument") |
|
36 | 36 | @argument_group('Second Group') |
|
37 | 37 | @argument('-z', '--baz', help="another grouped argument") |
|
38 | 38 | def magic_foo3(self, args): |
|
39 | 39 | """ A docstring. |
|
40 | 40 | """ |
|
41 | 41 | return parse_argstring(magic_foo3, args) |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | @magic_arguments() |
|
45 | 45 | @kwds(argument_default=argparse.SUPPRESS) |
|
46 | 46 | @argument('-f', '--foo', help="an argument") |
|
47 | 47 | def magic_foo4(self, args): |
|
48 | 48 | """ A docstring. |
|
49 | 49 | """ |
|
50 | 50 | return parse_argstring(magic_foo4, args) |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | @magic_arguments('frobnicate') |
|
54 | 54 | @argument('-f', '--foo', help="an argument") |
|
55 | 55 | def magic_foo5(self, args): |
|
56 | 56 | """ A docstring. |
|
57 | 57 | """ |
|
58 | 58 | return parse_argstring(magic_foo5, args) |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | @magic_arguments() |
|
62 | 62 | @argument('-f', '--foo', help="an argument") |
|
63 | 63 | def magic_magic_foo(self, args): |
|
64 | 64 | """ A docstring. |
|
65 | 65 | """ |
|
66 | 66 | return parse_argstring(magic_magic_foo, args) |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | @magic_arguments() |
|
70 | 70 | @argument('-f', '--foo', help="an argument") |
|
71 | 71 | def foo(self, args): |
|
72 | 72 | """ A docstring. |
|
73 | 73 | """ |
|
74 | 74 | return parse_argstring(foo, args) |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | @parametric |
|
78 | 78 | def test_magic_arguments(): |
|
79 | 79 | # Ideally, these would be doctests, but I could not get it to work. |
|
80 | yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
80 | yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
81 | 81 | yield assert_equal(getattr(magic_foo1, 'argcmd_name', None), None) |
|
82 | 82 | yield assert_equal(real_name(magic_foo1), 'foo1') |
|
83 | 83 | yield assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None)) |
|
84 | 84 | yield assert_true(hasattr(magic_foo1, 'has_arguments')) |
|
85 | 85 | |
|
86 | yield assert_equal(magic_foo2.__doc__, '%foo2\n\nA docstring.\n') | |
|
86 | yield assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n') | |
|
87 | 87 | yield assert_equal(getattr(magic_foo2, 'argcmd_name', None), None) |
|
88 | 88 | yield assert_equal(real_name(magic_foo2), 'foo2') |
|
89 | 89 | yield assert_equal(magic_foo2(None, ''), argparse.Namespace()) |
|
90 | 90 | yield assert_true(hasattr(magic_foo2, 'has_arguments')) |
|
91 | 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') | |
|
92 | yield assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A 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 | 93 | yield assert_equal(getattr(magic_foo3, 'argcmd_name', None), None) |
|
94 | 94 | yield assert_equal(real_name(magic_foo3), 'foo3') |
|
95 | 95 | yield assert_equal(magic_foo3(None, ''), |
|
96 | 96 | argparse.Namespace(bar=None, baz=None, foo=None)) |
|
97 | 97 | yield assert_true(hasattr(magic_foo3, 'has_arguments')) |
|
98 | 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') | |
|
99 | yield assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
100 | 100 | yield assert_equal(getattr(magic_foo4, 'argcmd_name', None), None) |
|
101 | 101 | yield assert_equal(real_name(magic_foo4), 'foo4') |
|
102 | 102 | yield assert_equal(magic_foo4(None, ''), argparse.Namespace()) |
|
103 | 103 | yield assert_true(hasattr(magic_foo4, 'has_arguments')) |
|
104 | 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') | |
|
105 | yield assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
106 | 106 | yield assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate') |
|
107 | 107 | yield assert_equal(real_name(magic_foo5), 'frobnicate') |
|
108 | 108 | yield assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None)) |
|
109 | 109 | yield assert_true(hasattr(magic_foo5, 'has_arguments')) |
|
110 | 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') | |
|
111 | yield assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
112 | 112 | yield assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None) |
|
113 | 113 | yield assert_equal(real_name(magic_magic_foo), 'magic_foo') |
|
114 | 114 | yield assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None)) |
|
115 | 115 | yield assert_true(hasattr(magic_magic_foo, 'has_arguments')) |
|
116 | 116 | |
|
117 | yield assert_equal(foo.__doc__, '%foo [-f FOO]\n\nA docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
117 | yield assert_equal(foo.__doc__, '%foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n') | |
|
118 | 118 | yield assert_equal(getattr(foo, 'argcmd_name', None), None) |
|
119 | 119 | yield assert_equal(real_name(foo), 'foo') |
|
120 | 120 | yield assert_equal(foo(None, ''), argparse.Namespace(foo=None)) |
|
121 | 121 | yield assert_true(hasattr(foo, 'has_arguments')) |
General Comments 0
You need to be logged in to leave comments.
Login now