annotate MoinMoin/_tests/test_wikiutil.py @ 2567:b403a24f7c8f

(xorAxAx, johill) make saner looking anchors, no more sha hash
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jul 2007 15:34:01 +0200
parents fb05ca2c0bdc
children 80eac6fc152a
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - MoinMoin.wikiutil Tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
5 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
6 2007 by MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
2172
c15ec6a2c69e reduce number of failing tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2164
diff changeset
10 import py
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
11
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 from MoinMoin import wikiutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
2265
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
15 class TestQueryStringSupport:
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
16 tests = [
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
17 ('', {}, {}),
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
18 ('key1=value1', {'key1': 'value1'}, {'key1': u'value1'}),
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
19 ('key1=value1&key2=value2', {'key1': 'value1', 'key2': 'value2'}, {'key1': u'value1', 'key2': u'value2'}),
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
20 ('rc_de=Aktuelle%C3%84nderungen', {'rc_de': 'Aktuelle\xc3\x84nderungen'}, {'rc_de': u'Aktuelle\xc4nderungen'}),
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
21 ]
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
22 def testParseQueryString(self):
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
23 for qstr, expected_str, expected_unicode in self.tests:
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
24 assert wikiutil.parseQueryString(qstr, want_unicode=False) == expected_str
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
25 assert wikiutil.parseQueryString(qstr, want_unicode=True) == expected_unicode
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
26 assert wikiutil.parseQueryString(unicode(qstr), want_unicode=False) == expected_str
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
27 assert wikiutil.parseQueryString(unicode(qstr), want_unicode=True) == expected_unicode
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
28
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
29 def testMakeQueryString(self):
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
30 for qstr, in_str, in_unicode in self.tests:
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
31 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_unicode, want_unicode=False), want_unicode=False) == in_str
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
32 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_str, want_unicode=False), want_unicode=False) == in_str
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
33 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_unicode, want_unicode=True), want_unicode=True) == in_unicode
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
34 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_str, want_unicode=True), want_unicode=True) == in_unicode
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
35
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
36
2266
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
37 class TestTickets:
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
38 def testTickets(self):
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
39 from MoinMoin.Page import Page
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
40 # page name with double quotes
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
41 self.request.page = Page(self.request, u'bla"bla')
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
42 ticket1 = wikiutil.createTicket(self.request)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
43 assert wikiutil.checkTicket(self.request, ticket1)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
44 # page name with non-ASCII chars
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
45 self.request.page = Page(self.request, u'\xc4rger')
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
46 ticket2 = wikiutil.createTicket(self.request)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
47 assert wikiutil.checkTicket(self.request, ticket2)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
48 # same page with another action
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
49 self.request.page = Page(self.request, u'\xc4rger')
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
50 self.request.action = 'another'
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
51 ticket3 = wikiutil.createTicket(self.request)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
52 assert wikiutil.checkTicket(self.request, ticket3)
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
53
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
54 assert ticket1 != ticket2
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
55 assert ticket2 != ticket3
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
56
3318504c5dd5 create tickets as fn(time, pagename, action, secret) - so they are not reusable, add tests for tickets
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2265
diff changeset
57
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
58 class TestCleanInput:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
59 def testCleanInput(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
60 tests = [(u"", u""), # empty
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
61 (u"aaa\r\n\tbbb", u"aaa bbb"), # ws chars -> blanks
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
62 (u"aaa\x00\x01bbb", u"aaabbb"), # strip weird chars
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
63 (u"a"*500, u""), # too long
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
64 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
65 for instr, outstr in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
66 assert wikiutil.clean_input(instr) == outstr
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
67
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
68
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
69 class TestNameQuoting:
2378
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
70 tests = [(u"", u'""'), # empty
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
71 (u"test", u'"test"'), # nothing special
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
72 (u"Sarah O'Connor", u"\"Sarah O'Connor\""),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
73 (u'Just "something" quoted', u'"Just ""something"" quoted"'),
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
74 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
75 def testQuoteName(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
76 for name, qname in self.tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
77 assert wikiutil.quoteName(name) == qname
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
78
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
79 def testUnquoteName(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
80 for name, qname in self.tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
81 assert wikiutil.unquoteName(qname) == name
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
82
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
83
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
84 class TestInterWiki:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
85 def testSplitWiki(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
86 tests = [('SomePage', ('Self', 'SomePage', '')),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
87 ('OtherWiki:OtherPage', ('OtherWiki', 'OtherPage', '')),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
88 ('MoinMoin:"Page with blanks" link title', ("MoinMoin", "Page with blanks", "link title")),
2378
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
89 ('MoinMoin:"Page with blanks"link title', ("MoinMoin", "Page with blanks", "link title")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
90 ('MoinMoin:"Page with blanks"', ("MoinMoin", "Page with blanks", "")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
91 ('MoinMoin:"Page with ""quote""" link title', ("MoinMoin", 'Page with "quote"', "link title")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
92 ('MoinMoin:"Page with """"double-quote"""link title', ("MoinMoin", 'Page with ""double-quote"', "link title")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
93 ('MoinMoin:"""starts with quote"link title', ("MoinMoin", '"starts with quote', "link title")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
94 ('MoinMoin:"ends with quote"""link title', ("MoinMoin", 'ends with quote"', "link title")),
a7f4b02f5fdb fix the quoting mess
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2267
diff changeset
95 ('MoinMoin:"""page with quotes around"""link title', ("MoinMoin", '"page with quotes around"', "link title")),
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
96 ('attachment:"filename with blanks.txt" other title', ("attachment", "filename with blanks.txt", "other title")),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
97 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
98 for markup, (wikiname, pagename, linktext) in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
99 assert wikiutil.split_wiki(markup) == (wikiname, pagename, linktext)
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
100
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
101 def testJoinWiki(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
102 tests = [(('http://example.org/', u'SomePage'), 'http://example.org/SomePage'),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
103 (('http://example.org/?page=$PAGE&action=show', u'SomePage'), 'http://example.org/?page=SomePage&action=show'),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
104 (('http://example.org/', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen'),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
105 (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen/show'),
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
106 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
107 for (baseurl, pagename), url in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
108 assert wikiutil.join_wiki(baseurl, pagename) == url
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
109
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
110
2173
789c1a37e4ab don't run docbook formatter test when we have no 4suite installed, add test for non-empty SystemPagesGroup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2172
diff changeset
111 class TestSystemPagesGroup:
789c1a37e4ab don't run docbook formatter test when we have no 4suite installed, add test for non-empty SystemPagesGroup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2172
diff changeset
112 def testSystemPagesGroupNotEmpty(self):
789c1a37e4ab don't run docbook formatter test when we have no 4suite installed, add test for non-empty SystemPagesGroup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2172
diff changeset
113 assert self.request.dicts.members('SystemPagesGroup')
789c1a37e4ab don't run docbook formatter test when we have no 4suite installed, add test for non-empty SystemPagesGroup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2172
diff changeset
114
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
115 class TestSystemPage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 systemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 # First level, on SystemPagesGroup
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 'SystemPagesInEnglishGroup',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 # Second level, on one of the pages above
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 'RecentChanges',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 'TitleIndex',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 notSystemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 'NoSuchPageYetAndWillNeverBe',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 def testSystemPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 """wikiutil: good system page names accepted, bad rejected"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 for name in self.systemPages:
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
130 assert wikiutil.isSystemPage(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 for name in self.notSystemPages:
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
132 assert not wikiutil.isSystemPage(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
135 class TestTemplatePage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 good = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 'aTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 'MyTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140 bad = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 'Template',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 'ATemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 'TemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 'xTemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 'XTemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 def testTemplatePage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 """wikiutil: good template names accepted, bad rejected"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
150 for name in self.good:
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
151 assert wikiutil.isTemplatePage(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 for name in self.bad:
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
153 assert not wikiutil.isTemplatePage(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
154
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
156 class TestParmeterParser:
2052
1376525701c1 wikiutil.ParameterParser: tests added and bug fixed if args is empty and parameters wanted
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
157
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
158 def testParameterParser(self):
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
159 tests = [
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
160 # trivial
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
161 ('', '', 0, {}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
162
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
163 # fixed
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
164 ('%s%i%f%b', '"test",42,23.0,True', 4, {0: 'test', 1: 42, 2: 23.0, 3: True}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
165
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
166 # fixed and named
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
167 ('%s%(x)i%(y)i', '"test"', 1, {0: 'test', 'x': None, 'y': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
168 ('%s%(x)i%(y)i', '"test",1', 1, {0: 'test', 'x': 1, 'y': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
169 ('%s%(x)i%(y)i', '"test",1,2', 1, {0: 'test', 'x': 1, 'y': 2}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
170 ('%s%(x)i%(y)i', '"test",x=1', 1, {0: 'test', 'x': 1, 'y': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
171 ('%s%(x)i%(y)i', '"test",x=1,y=2', 1, {0: 'test', 'x': 1, 'y': 2}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
172 ('%s%(x)i%(y)i', '"test",y=2', 1, {0: 'test', 'x': None, 'y': 2}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
173
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
174 # test mixed acceptance
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
175 ("%ifs", '100', 1, {0: 100}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
176 ("%ifs", '100.0', 1, {0: 100.0}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
177 ("%ifs", '"100"', 1, {0: "100"}),
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
178
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
179 # boolean
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
180 ("%(t)b%(f)b", '', 0, {'t': None, 'f': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
181 ("%(t)b%(f)b", 't=1', 0, {'t': True, 'f': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
182 ("%(t)b%(f)b", 'f=False', 0, {'t': None, 'f': False}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
183 ("%(t)b%(f)b", 't=True, f=0', 0, {'t': True, 'f': False}),
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
184
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
185 # integer
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
186 ("%(width)i%(height)i", '', 0, {'width': None, 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
187 ("%(width)i%(height)i", 'width=100', 0, {'width': 100, 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
188 ("%(width)i%(height)i", 'height=200', 0, {'width': None, 'height': 200}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
189 ("%(width)i%(height)i", 'width=100, height=200', 0, {'width': 100, 'height': 200}),
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
190
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
191 # float
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
192 ("%(width)f%(height)f", '', 0, {'width': None, 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
193 ("%(width)f%(height)f", 'width=100.0', 0, {'width': 100.0, 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
194 ("%(width)f%(height)f", 'height=2.0E2', 0, {'width': None, 'height': 200.0}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
195 ("%(width)f%(height)f", 'width=1000.0E-1, height=200.0', 0, {'width': 100.0, 'height': 200.0}),
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
196
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
197 # string
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
198 ("%(width)s%(height)s", '', 0, {'width': None, 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
199 ("%(width)s%(height)s", 'width="really wide"', 0, {'width': 'really wide', 'height': None}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
200 ("%(width)s%(height)s", 'height="not too high"', 0, {'width': None, 'height': 'not too high'}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
201 ("%(width)s%(height)s", 'width="really wide", height="not too high"', 0, {'width': 'really wide', 'height': 'not too high'}),
2456
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
202 # conversion from given type to expected type
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
203 ("%(width)s%(height)s", 'width=100', 0, {'width': '100', 'height': None}),
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
204 ("%(width)s%(height)s", 'width=100, height=200', 0, {'width': '100', 'height': '200'}),
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
205
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
206 # complex test
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
207 ("%i%sf%s%ifs%(a)s|%(b)s", ' 4,"DI\'NG", b=retry, a="DING"', 2, {0: 4, 1: "DI'NG", 'a': 'DING', 'b': 'retry'}),
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
208
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
209 ]
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
210 for format, args, expected_fixed_count, expected_dict in tests:
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
211 argParser = wikiutil.ParameterParser(format)
2455
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
212 fixed_count, arg_dict = argParser.parse_parameters(args)
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
213 assert (fixed_count, arg_dict) == (expected_fixed_count, expected_dict)
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
214
2052
1376525701c1 wikiutil.ParameterParser: tests added and bug fixed if args is empty and parameters wanted
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
215 def testTooMuchWantedArguments(self):
1376525701c1 wikiutil.ParameterParser: tests added and bug fixed if args is empty and parameters wanted
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
216 args = 'width=100, height=200, alt=Example'
1376525701c1 wikiutil.ParameterParser: tests added and bug fixed if args is empty and parameters wanted
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
217 argParser = wikiutil.ParameterParser("%(width)s%(height)s")
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
218 py.test.raises(ValueError, argParser.parse_parameters, args)
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
219
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
220 def testMalformedArguments(self):
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
221 args = '='
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
222 argParser = wikiutil.ParameterParser("%(width)s%(height)s")
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
223 py.test.raises(ValueError, argParser.parse_parameters, args)
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
224
2456
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
225 def testWrongTypeFixedPosArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
226 args = '0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
227 argParser = wikiutil.ParameterParser("%b")
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
228 py.test.raises(ValueError, argParser.parse_parameters, args)
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
229
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
230 def testWrongTypeNamedArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
231 args = 'flag=0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
232 argParser = wikiutil.ParameterParser("%(flag)b")
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
233 py.test.raises(ValueError, argParser.parse_parameters, args)
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
234
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
235
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
236 class TestParamParsing:
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
237 def testMacroArgs(self):
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
238 abcd = [u'a', u'b', u'c', u'd']
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
239 abcd_dict = {u'a': u'1', u'b': u'2', u'c': u'3', u'd': u'4'}
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
240 tests = [
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
241 # regular and quoting tests
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
242 (u'd = 4,c=3,b=2,a= 1 ', ([], abcd_dict, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
243 (u'a,b,c,d', (abcd, {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
244 (u' a , b , c , d ', (abcd, {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
245 (u' a ', ([u'a'], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
246 (u'" a "', ([u' a '], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
247 (u'a,b,c,d, "a,b,c,d"', (abcd+[u'a,b,c,d'], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
248 (u'quote " :), b', ([u'quote " :)', u'b'], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
249 (u'"quote "" :)", b', ([u'quote " :)', u'b'], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
250 (u'=7', ([], {u'': u'7'}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
251 (u',,', ([None, None, None], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
252 (u',"",', ([None, u'', None], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
253 (u',"", ""', ([None, u'', u''], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
254 (u' "" ,"", ""', ([u'', u'', u''], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
255 # some name=value test
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
256 (u'd = 4,c=3,b=2,a= 1 ', ([], abcd_dict, [])),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
257 (u'd=d,e="a,b,c,d"', ([], {u'd': u'd',
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
258 u'e': u'a,b,c,d'}, [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
259 (u'd = d,e = "a,b,c,d"', ([], {u'd': u'd',
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
260 u'e': u'a,b,c,d'}, [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
261 (u'd = d, e = "a,b,c,d"', ([], {u'd': u'd',
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
262 u'e': u'a,b,c,d'}, [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
263 (u'd = , e = "a,b,c,d"', ([], {u'd': None,
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
264 u'e': u'a,b,c,d'}, [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
265 (u'd = "", e = "a,b,c,d"', ([], {u'd': u'',
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
266 u'e': u'a,b,c,d'}, [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
267 (u'd = "", e = ', ([], {u'd': u'', u'e': None},
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
268 [])),
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
269 (u'd=""', ([], {u'd': u''}, [])),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
270 (u'd = "", e = ""', ([], {u'd': u'', u'e': u''},
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
271 [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
272 # no, None as key isn't accepted
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
273 (u' = "", e = ""', ([], {u'': u'', u'e': u''},
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
274 [])),
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
275 # can quote both name and value:
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
276 (u'd = d," e "= "a,b,c,d"', ([], {u'd': u'd',
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
277 u' e ': u'a,b,c,d'}, [])),
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
278 # trailing args
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
279 (u'1,2,a=b,3,4', ([u'1', u'2'], {u'a': u'b'},
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
280 [u'3', u'4'])),
2544
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
281 # can quote quotes:
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
282 (u'd = """d"', ([], {u'd': u'"d'}, [])),
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
283 (u'd = """d"""', ([], {u'd': u'"d"'}, [])),
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
284 (u'd = "d"" ", e=7', ([], {u'd': u'd" ', u'e': u'7'},
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
285 [])),
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
286 (u'd = "d""", e=8', ([], {u'd': u'd"', u'e': u'8'},
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
287 [])),
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
288 ]
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
289 for args, expected in tests:
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
290 result = wikiutil.parse_quoted_separated(args)
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
291 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
292 for val in result[0]:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
293 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
294 for val in result[1].keys():
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
295 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
296 for val in result[1].values():
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
297 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
298 for val in result[2]:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
299 assert val is None or isinstance(val, unicode)
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
300
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
301 def testLimited(self):
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
302 tests = [
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
303 # regular and quoting tests
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
304 (u'd = 4,c=3,b=2,a= 1 ', ([], {u'd': u'4',
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
305 u'c': u'3,b=2,a= 1'}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
306 (u'a,b,c,d', ([u'a', u'b,c,d'], {}, [])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
307 (u'a=b,b,c,d', ([], {u'a': u'b'}, [u'b,c,d'])),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
308 ]
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
309 for args, expected in tests:
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
310 result = wikiutil.parse_quoted_separated(args, seplimit=1)
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
311 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
312 for val in result[0]:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
313 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
314 for val in result[1].keys():
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
315 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
316 for val in result[1].values():
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
317 assert val is None or isinstance(val, unicode)
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
318 for val in result[2]:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
319 assert val is None or isinstance(val, unicode)
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
320
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
321 def testNoNameValue(self):
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
322 abcd = [u'a', u'b', u'c', u'd']
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
323 tests = [
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
324 # regular and quoting tests
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
325 (u'd = 4,c=3,b=2,a= 1 ', [u'd = 4', u'c=3',
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
326 u'b=2', u'a= 1']),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
327 (u'a,b,c,d', abcd),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
328 (u' a , b , c , d ', abcd),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
329 (u' a ', [u'a']),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
330 (u'" a "', [u' a ']),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
331 (u'a,b,c,d, "a,b,c,d"', abcd + [u'a,b,c,d']),
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
332 (u'quote " :), b', [u'quote " :)', u'b']),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
333 (u'"quote "" :)", b', [u'quote " :)', u'b']),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
334 (u'd=d,e="a,b,c,d"', [u'd=d', u'e="a', u'b',
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
335 u'c', u'd"']),
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
336 ]
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
337 for args, expected in tests:
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
338 result = wikiutil.parse_quoted_separated(args, name_value=False)
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
339 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
340 for val in result:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
341 assert val is None or isinstance(val, unicode)
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
342
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
343
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
344 class TestArgGetters:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
345 def testGetBoolean(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
346 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
347 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
348 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
349 (None, None, False, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
350 (None, None, True, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
351
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
352 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
353 (u'0', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
354 (u'1', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
355 (u'false', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
356 (u'true', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
357 (u'FALSE', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
358 (u'TRUE', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
359 (u'no', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
360 (u'yes', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
361 (u'NO', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
362 (u'YES', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
363 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
364 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
365 assert wikiutil.get_bool(self.request, arg, name, default) == expected
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
366
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
367 def testGetBooleanRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
368 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
369 py.test.raises(AssertionError, wikiutil.get_bool, self.request, None, None, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
370
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
371 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
372 py.test.raises(TypeError, wikiutil.get_bool, self.request, True)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
373 py.test.raises(TypeError, wikiutil.get_bool, self.request, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
374 py.test.raises(TypeError, wikiutil.get_bool, self.request, 42.0)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
375 py.test.raises(TypeError, wikiutil.get_bool, self.request, '')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
376 py.test.raises(TypeError, wikiutil.get_bool, self.request, tuple())
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
377 py.test.raises(TypeError, wikiutil.get_bool, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
378 py.test.raises(TypeError, wikiutil.get_bool, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
379
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
380 # any value not convertable to boolean raises ValueError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
381 py.test.raises(ValueError, wikiutil.get_bool, self.request, u'')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
382 py.test.raises(ValueError, wikiutil.get_bool, self.request, u'42')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
383 py.test.raises(ValueError, wikiutil.get_bool, self.request, u'wrong')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
384 py.test.raises(ValueError, wikiutil.get_bool, self.request, u'"True"') # must not be quoted!
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
385
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
386 def testGetInt(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
387 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
388 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
389 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
390 (None, None, -23, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
391 (None, None, 42, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
392
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
393 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
394 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
395 (u'42', None, None, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
396 (u'-23', None, None, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
397 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
398 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
399 assert wikiutil.get_int(self.request, arg, name, default) == expected
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
400
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
401 def testGetIntRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
402 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
403 py.test.raises(AssertionError, wikiutil.get_int, self.request, None, None, 42.23)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
404
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
405 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
406 py.test.raises(TypeError, wikiutil.get_int, self.request, True)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
407 py.test.raises(TypeError, wikiutil.get_int, self.request, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
408 py.test.raises(TypeError, wikiutil.get_int, self.request, 42.0)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
409 py.test.raises(TypeError, wikiutil.get_int, self.request, '')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
410 py.test.raises(TypeError, wikiutil.get_int, self.request, tuple())
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
411 py.test.raises(TypeError, wikiutil.get_int, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
412 py.test.raises(TypeError, wikiutil.get_int, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
413
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
414 # any value not convertable to int raises ValueError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
415 py.test.raises(ValueError, wikiutil.get_int, self.request, u'')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
416 py.test.raises(ValueError, wikiutil.get_int, self.request, u'23.42')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
417 py.test.raises(ValueError, wikiutil.get_int, self.request, u'wrong')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
418 py.test.raises(ValueError, wikiutil.get_int, self.request, u'"4711"') # must not be quoted!
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
419
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
420 def testGetFloat(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
421 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
422 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
423 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
424 (None, None, -23.42, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
425 (None, None, 42.23, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
426
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
427 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
428 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
429 (u'42.23', None, None, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
430 (u'-23.42', None, None, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
431 (u'-23.42E3', None, None, -23.42E3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
432 (u'23.42E-3', None, None, 23.42E-3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
433 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
434 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
435 assert wikiutil.get_float(self.request, arg, name, default) == expected
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
436
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
437 def testGetFloatRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
438 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
439 py.test.raises(AssertionError, wikiutil.get_float, self.request, None, None, u'42')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
440
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
441 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
442 py.test.raises(TypeError, wikiutil.get_float, self.request, True)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
443 py.test.raises(TypeError, wikiutil.get_float, self.request, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
444 py.test.raises(TypeError, wikiutil.get_float, self.request, 42.0)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
445 py.test.raises(TypeError, wikiutil.get_float, self.request, '')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
446 py.test.raises(TypeError, wikiutil.get_float, self.request, tuple())
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
447 py.test.raises(TypeError, wikiutil.get_float, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
448 py.test.raises(TypeError, wikiutil.get_float, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
449
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
450 # any value not convertable to int raises ValueError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
451 py.test.raises(ValueError, wikiutil.get_float, self.request, u'')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
452 py.test.raises(ValueError, wikiutil.get_float, self.request, u'wrong')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
453 py.test.raises(ValueError, wikiutil.get_float, self.request, u'"47.11"') # must not be quoted!
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
454
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
455 def testGetComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
456 tests = [
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
457 # default testing for None value
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
458 (None, None, None, None),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
459 (None, None, -23.42, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
460 (None, None, 42.23, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
461
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
462 # some real values
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
463 (u'0', None, None, 0),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
464 (u'42.23', None, None, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
465 (u'-23.42', None, None, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
466 (u'-23.42E3', None, None, -23.42E3),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
467 (u'23.42E-3', None, None, 23.42E-3),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
468 (u'23.42E-3+3.04j', None, None, 23.42E-3+3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
469 (u'3.04j', None, None, 3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
470 (u'-3.04j', None, None, -3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
471 (u'23.42E-3+3.04i', None, None, 23.42E-3+3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
472 (u'3.04i', None, None, 3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
473 (u'-3.04i', None, None, -3.04j),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
474 (u'-3', None, None, -3L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
475 (u'-300000000000000000000', None, None, -300000000000000000000L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
476 ]
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
477 for arg, name, default, expected in tests:
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
478 assert wikiutil.get_complex(self.request, arg, name, default) == expected
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
479
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
480 def testGetComplexRaising(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
481 # wrong default type
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
482 py.test.raises(AssertionError, wikiutil.get_complex, self.request, None, None, u'42')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
483
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
484 # anything except None or unicode raises TypeError
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
485 py.test.raises(TypeError, wikiutil.get_complex, self.request, True)
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
486 py.test.raises(TypeError, wikiutil.get_complex, self.request, 42)
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
487 py.test.raises(TypeError, wikiutil.get_complex, self.request, 42.0)
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
488 py.test.raises(TypeError, wikiutil.get_complex, self.request, 3j)
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
489 py.test.raises(TypeError, wikiutil.get_complex, self.request, '')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
490 py.test.raises(TypeError, wikiutil.get_complex, self.request, tuple())
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
491 py.test.raises(TypeError, wikiutil.get_complex, self.request, [])
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
492 py.test.raises(TypeError, wikiutil.get_complex, self.request, {})
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
493
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
494 # any value not convertable to int raises ValueError
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
495 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
496 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3jj')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
497 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3Ij')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
498 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'3i-3i')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
499 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'wrong')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
500 py.test.raises(ValueError, wikiutil.get_complex, self.request, u'"47.11"') # must not be quoted!
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
501
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
502 def testGetUnicode(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
503 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
504 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
505 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
506 (None, None, u'', u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
507 (None, None, u'abc', u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
508
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
509 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
510 (u'', None, None, u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
511 (u'abc', None, None, u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
512 (u'"abc"', None, None, u'"abc"'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
513 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
514 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
515 assert wikiutil.get_unicode(self.request, arg, name, default) == expected
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
516
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
517 def testGetUnicodeRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
518 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
519 py.test.raises(AssertionError, wikiutil.get_unicode, self.request, None, None, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
520
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
521 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
522 py.test.raises(TypeError, wikiutil.get_unicode, self.request, True)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
523 py.test.raises(TypeError, wikiutil.get_unicode, self.request, 42)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
524 py.test.raises(TypeError, wikiutil.get_unicode, self.request, 42.0)
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
525 py.test.raises(TypeError, wikiutil.get_unicode, self.request, '')
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
526 py.test.raises(TypeError, wikiutil.get_unicode, self.request, tuple())
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
527 py.test.raises(TypeError, wikiutil.get_unicode, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
528 py.test.raises(TypeError, wikiutil.get_unicode, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
529
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
530
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
531 class TestExtensionInvoking:
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
532 def _test_invoke_bool(self, b=bool):
2551
f3b684afca81 make sourcecode checker happy on wikiutil tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2550
diff changeset
533 assert b is False
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
534
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
535 def _test_invoke_bool_def(self, v=bool, b=False):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
536 assert b == v
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
537 assert isinstance(b, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
538 assert isinstance(v, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
539
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
540 def _test_invoke_int_None(self, i=int):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
541 assert i == 1 or i is None
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
542
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
543 def _test_invoke_float_None(self, i=float):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
544 assert i == 1.4 or i is None
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
545
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
546 def _test_invoke_float_required(self, i=wikiutil.required_arg(float)):
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
547 assert i == 1.4
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
548
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
549 def _test_invoke_choice(self, a, choice=[u'a', u'b', u'c']):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
550 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
551 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
552
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
553 def _test_invoke_choicet(self, a, choice=(u'a', u'b', u'c')):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
554 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
555 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
556
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
557 def _test_trailing(self, a, _trailing_args=[]):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
558 assert _trailing_args == [u'a']
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
559
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
560 def _test_arbitrary_kw(self, expect, _kwargs={}):
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
561 assert _kwargs == expect
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
562
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
563 def testInvoke(self):
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
564 def _test_invoke_int(i=int):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
565 assert i == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
566
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
567 def _test_invoke_int_fixed(a, b, i=int):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
568 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
569 assert b == 8
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
570 assert i == 1 or i is None
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
571
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
572 ief = wikiutil.invoke_extension_function
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
573 ief(self.request, self._test_invoke_bool, u'False')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
574 ief(self.request, self._test_invoke_bool, u'b=False')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
575 ief(self.request, _test_invoke_int, u'1')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
576 ief(self.request, _test_invoke_int, u'i=1')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
577 ief(self.request, self._test_invoke_bool_def, u'False, False')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
578 ief(self.request, self._test_invoke_bool_def, u'b=False, v=False')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
579 ief(self.request, self._test_invoke_bool_def, u'False')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
580 ief(self.request, self._test_invoke_int_None, u'i=1')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
581 ief(self.request, self._test_invoke_int_None, u'i=')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
582 ief(self.request, self._test_invoke_int_None, u'')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
583 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
584 self._test_invoke_int_None, u'x')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
585 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
586 self._test_invoke_int_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
587 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
588 self._test_invoke_int_None, u'i=""')
2546
56dbfbde79fe better error checking in parameter parser, no more TypeError
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2544
diff changeset
589 py.test.raises(ValueError, ief, self.request,
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
590 _test_invoke_int_fixed, u'a=7', [7, 8])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
591 ief(self.request, _test_invoke_int_fixed, u'i=1', [7, 8])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
592 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
593 _test_invoke_int_fixed, u'i=""', [7, 8])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
594 ief(self.request, _test_invoke_int_fixed, u'i=', [7, 8])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
595
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
596 for choicefn in (self._test_invoke_choice, self._test_invoke_choicet):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
597 ief(self.request, choicefn, u'', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
598 ief(self.request, choicefn, u'choice=a', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
599 ief(self.request, choicefn, u'choice=', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
600 ief(self.request, choicefn, u'choice="a"', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
601 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
602 choicefn, u'x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
603 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
604 choicefn, u'choice=x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
605
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
606 ief(self.request, self._test_invoke_float_None, u'i=1.4')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
607 ief(self.request, self._test_invoke_float_None, u'i=')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
608 ief(self.request, self._test_invoke_float_None, u'')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
609 ief(self.request, self._test_invoke_float_None, u'1.4')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
610 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
611 self._test_invoke_float_None, u'x')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
612 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
613 self._test_invoke_float_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
614 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
615 self._test_invoke_float_None, u'i=""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
616 ief(self.request, self._test_trailing, u'a=7, a')
2550
2523642e9516 put extra additional arguments into _trailing_args in all cases
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2548
diff changeset
617 ief(self.request, self._test_trailing, u'7, a')
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
618 ief(self.request, self._test_arbitrary_kw, u'test=x, \xc3=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
619 [{u'\xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
620 ief(self.request, self._test_arbitrary_kw, u'test=x, "\xc3"=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
621 [{u'\xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
622 ief(self.request, self._test_arbitrary_kw, u'test=x, "7 \xc3"=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
623 [{u'7 \xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
624 ief(self.request, self._test_arbitrary_kw, u'test=x, 7 \xc3=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
625 [{u'7 \xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
626 ief(self.request, self._test_arbitrary_kw, u'7 \xc3=test, test= x ',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
627 [{u'7 \xc3': 'test', 'test': u'x'}])
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
628 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
629 self._test_invoke_float_required, u'')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
630 ief(self.request, self._test_invoke_float_required, u'1.4')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
631 ief(self.request, self._test_invoke_float_required, u'i=1.4')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
632 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
633 self._test_invoke_float_required, u',')
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
634
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
635 def testConstructors(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
636 ief = wikiutil.invoke_extension_function
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
637
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
638 # new style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
639 class TEST1(object):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
640 def __init__(self, a=int):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
641 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
642 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
643
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
644 class TEST2(TEST1):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
645 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
646
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
647 obj = ief(self.request, TEST1, u'a=7')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
648 assert isinstance(obj, TEST1)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
649 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
650 py.test.raises(ValueError, ief, self.request, TEST1, u'b')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
651
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
652 obj = ief(self.request, TEST2, u'a=7')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
653 assert isinstance(obj, TEST1)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
654 assert isinstance(obj, TEST2)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
655 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
656 py.test.raises(ValueError, ief, self.request, TEST2, u'b')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
657
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
658 # old style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
659 class TEST3:
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
660 def __init__(self, a=int):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
661 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
662 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
663
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
664 class TEST4(TEST3):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
665 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
666
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
667 obj = ief(self.request, TEST3, u'a=7')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
668 assert isinstance(obj, TEST3)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
669 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
670 py.test.raises(ValueError, ief, self.request, TEST3, u'b')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
671
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
672 obj = ief(self.request, TEST4, u'a=7')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
673 assert isinstance(obj, TEST3)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
674 assert isinstance(obj, TEST4)
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
675 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
676 py.test.raises(ValueError, ief, self.request, TEST4, u'b')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
677
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
678 def testFailing(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
679 ief = wikiutil.invoke_extension_function
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
680
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
681 py.test.raises(TypeError, ief, self.request, hex, u'15')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
682 py.test.raises(TypeError, ief, self.request, cmp, u'15')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
683 py.test.raises(AttributeError, ief, self.request, unicode, u'15')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
684
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
685 def testAllDefault(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
686 ief = wikiutil.invoke_extension_function
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
687
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
688 def has_many_defaults(a=1, b=2, c=3, d=4):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
689 assert a == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
690 assert b == 2
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
691 assert c == 3
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
692 assert d == 4
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
693 return True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
694
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
695 assert ief(self.request, has_many_defaults, u'1, 2, 3, 4')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
696 assert ief(self.request, has_many_defaults, u'2, 3, 4', [1])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
697 assert ief(self.request, has_many_defaults, u'3, 4', [1, 2])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
698 assert ief(self.request, has_many_defaults, u'4', [1, 2, 3])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
699 assert ief(self.request, has_many_defaults, u'', [1, 2, 3, 4])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
700 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2,a=1')
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
701 assert ief(self.request, has_many_defaults, u'd=4,c=3,b=2', [1])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
702 assert ief(self.request, has_many_defaults, u'd=4,c=3', [1, 2])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
703 assert ief(self.request, has_many_defaults, u'd=4', [1, 2, 3])
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
704
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
705 def testInvokeComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
706 ief = wikiutil.invoke_extension_function
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
707
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
708 def has_complex(a=complex, b=complex):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
709 assert a == b
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
710 return True
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
711
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
712 assert ief(self.request, has_complex, u'3-3i, 3-3j')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
713 assert ief(self.request, has_complex, u'2i, 2j')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
714 assert ief(self.request, has_complex, u'b=2i, a=2j')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
715 assert ief(self.request, has_complex, u'2.007, 2.007')
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
716 assert ief(self.request, has_complex, u'2.007', [2.007])
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
717 assert ief(self.request, has_complex, u'b=2.007', [2.007])
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
718
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
719
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
720 class TestAnchorNames:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
721 def test_anchor_name_encoding(self):
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
722 tests = [
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
723 # text expected output
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
724 (u'\xf6\xf6ll\xdf\xdf', '.2BAPYA9g-ll.2BAN8A3w-'),
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
725 (u'level 2', 'level_2'),
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
726 ]
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
727 for text, expected in tests:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
728 yield self._check, text, expected
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
729
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
730 def _check(self, text, expected):
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
731 encoded = wikiutil.anchor_name_from_text(text)
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
732 assert expected == encoded
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
733
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2378
diff changeset
734 coverage_modules = ['MoinMoin.wikiutil']