-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathargs_test.py
More file actions
74 lines (59 loc) · 1.54 KB
/
args_test.py
File metadata and controls
74 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from template.test import TestCase, main
class MyObj:
def foo(self, *arg):
return "object:\n" + self.args(*arg)
def args(self, *arg):
if arg and isinstance(arg[-1], dict):
arg = list(arg)
named = arg.pop()
else:
named = {}
return " ARGS: [ %s ]\n NAMED: { %s }\n" % (
", ".join(str(x) for x in arg),
", ".join("%s => %s" % (key, named[key]) for key in sorted(named.keys())))
class ArgsTest(TestCase):
def testArgs(self):
replace = self._callsign()
o = MyObj()
replace['args'] = o.args
replace['obj'] = MyObj()
self.Expect(DATA, {'INTERPOLATE': True}, replace)
DATA = r"""
-- test --
[% args(a b c) %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
NAMED: { }
-- test --
[% args(a b c d=e f=g) %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
NAMED: { d => echo, f => golf }
-- test --
[% args(a, b, c, d=e, f=g) %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
NAMED: { d => echo, f => golf }
-- test --
[% args(a, b, c, d=e, f=g,) %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
NAMED: { d => echo, f => golf }
-- test --
[% args(d=e, a, b, f=g, c) %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
NAMED: { d => echo, f => golf }
-- test --
[% obj.foo(d=e, a, b, f=g, c) %]
-- expect --
object:
ARGS: [ alpha, bravo, charlie ]
NAMED: { d => echo, f => golf }
-- test --
[% obj.foo(d=e, a, b, f=g, c).split("\n").1 %]
-- expect --
ARGS: [ alpha, bravo, charlie ]
"""
if __name__ == '__main__':
main()