annotate MoinMoin/_tests/test_wikiutil.py @ 3910:6fbfffffc4d1

Insert moins path more aggressively into sys.path to win the race against py.test, do insertions less often in make_test_wiki
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 31 Jul 2008 14:17:19 +0200
parents dcd932f8c4ec
children d9de4fa12f23 30ffb215bf6e
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 TestInterWiki:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
70 def testSplitWiki(self):
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
71 tests = [('SomePage', ('Self', 'SomePage')),
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
72 ('OtherWiki:OtherPage', ('OtherWiki', 'OtherPage')),
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
73 (':OtherPage', ('', 'OtherPage')),
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
74 # broken ('/OtherPage', ('Self', '/OtherPage')),
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
75 # wrong interpretation ('MainPage/OtherPage', ('Self', 'MainPage/OtherPage')),
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
76 ]
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
77 for markup, (wikiname, pagename) in tests:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
78 assert wikiutil.split_wiki(markup) == (wikiname, pagename)
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
79
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
80 def testJoinWiki(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
81 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
82 (('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
83 (('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
84 (('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
85 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
86 for (baseurl, pagename), url in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
87 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
88
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
89
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
90 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
91 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
92 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
93
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
94 class TestSystemPage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 systemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 # 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
97 'SystemPagesInEnglishGroup',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 # 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
99 'RecentChanges',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 'TitleIndex',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 notSystemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103 'NoSuchPageYetAndWillNeverBe',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 def testSystemPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 """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
108 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
109 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
110 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
111 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
112
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
114 class TestTemplatePage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 good = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 'aTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 'MyTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 bad = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 'Template',
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3407
diff changeset
121 'I want a Template',
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 'TemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 'xTemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 'XTemplateInFront',
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 testTemplatePage(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 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
129 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
130 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
131 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
132 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
133
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134
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
135 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
136
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
137 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
138 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
139 # 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
140 ('', '', 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
141
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
142 # 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
143 ('%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
144
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
145 # 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
146 ('%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
147 ('%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
148 ('%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
149 ('%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
150 ('%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
151 ('%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
152
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
153 # 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
154 ("%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
155 ("%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
156 ("%ifs", '"100"', 1, {0: "100"}),
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
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 # 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
159 ("%(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
160 ("%(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
161 ("%(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
162 ("%(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
163
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
164 # 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
165 ("%(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
166 ("%(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
167 ("%(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
168 ("%(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
169
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
170 # 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
171 ("%(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
172 ("%(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
173 ("%(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
174 ("%(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
175
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
176 # 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
177 ("%(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
178 ("%(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
179 ("%(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
180 ("%(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
181 # 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
182 ("%(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
183 ("%(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
184
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
185 # 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
186 ("%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
187
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 ]
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 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
190 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
191 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
192 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
193
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
194 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
195 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
196 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
197 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
198
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
199 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
200 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
201 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
202 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
203
2456
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
204 def testWrongTypeFixedPosArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
205 args = '0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
206 argParser = wikiutil.ParameterParser("%b")
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
207 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
208
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
209 def testWrongTypeNamedArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
210 args = 'flag=0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
211 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
212 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
213
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
214
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
215 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
216 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
217 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
218 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
219 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
220 # 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
221 (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
222 (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
223 (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
224 (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
225 (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
226 (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
227 (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
228 (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
229 (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
230 (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
231 (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
232 (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
233 (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
234 # 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
235 (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
236 (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
237 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
238 (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
239 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
240 (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
241 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
242 (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
243 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
244 (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
245 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
246 (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
247 [])),
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
248 (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
249 (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
250 [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
251 # 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
252 (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
253 [])),
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
254 # 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
255 (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
256 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
257 # 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
258 (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
259 [u'3', u'4'])),
2544
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
260 # can quote quotes:
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
261 (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
262 (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
263 (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
264 [])),
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
265 (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
266 [])),
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
267 ]
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
268 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
269 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
270 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
271 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
272 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
273 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
274 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
275 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
276 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
277 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
278 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
279
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 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
281 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
282 # 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
283 (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
284 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
285 (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
286 (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
287 ]
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 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
289 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
290 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299
3815
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
300 def testDoubleNameValueSeparator(self):
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
301 tests = [
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
302 # regular and quoting tests
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
303 (u'd==4,=3 ', ([], {u'd': u'=4', u'': u'3'}, [])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
304 (u'===a,b,c,d', ([], {u'': u'==a'}, [u'b', u'c', u'd'])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
305 (u'a,b,===,c,d', ([u'a', u'b'], {u'': u'=='}, [u'c', u'd'])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
306 ]
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
307
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
308 def _check(a, e):
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
309 r = wikiutil.parse_quoted_separated(a)
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
310 assert r == e
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
311
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
312 for args, expected in tests:
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
313 yield _check, args, expected
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
314
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
315 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
316 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
317 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
318 # 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
319 (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
320 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
321 (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
322 (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
323 (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
324 (u'" a "', [u' a ']),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
325 (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
326 (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
327 (u'"quote "" :)", b', [u'quote " :)', u'b']),
3404
e979e3cad972 parse_quoted_separated_ext: fix unclosed quotes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3403
diff changeset
328 (u'"unended quote', [u'"unended quote']),
e979e3cad972 parse_quoted_separated_ext: fix unclosed quotes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3403
diff changeset
329 (u'"', [u'"']),
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
330 (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
331 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
332 ]
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 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
334 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
335 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
336 for val in result:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
337 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
338
3259
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
339 def testUnitArgument(self):
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
340 result = wikiutil.UnitArgument('7mm', float, ['%', 'mm'])
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
341 assert result.get_default() == (7.0, 'mm')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
342 assert result.parse_argument('8%') == (8.0, '%')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
343 py.test.raises(ValueError, result.parse_argument, u'7m')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
344 py.test.raises(ValueError, result.parse_argument, u'7')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
345 py.test.raises(ValueError, result.parse_argument, u'mm')
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
346
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
347 def testExtendedParser(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
348 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
349 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
350 (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
351 (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
352 (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
353 (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
354 (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
355 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
356 (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
357 (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
358 (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
359 (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
360 (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
361 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
362 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
363 (u'" a" "b" "c"', None, u':', [u' a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
364 (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
365 (u' a:a ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
366 (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
367 (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
368 (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
369 (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
370 (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
3400
b12aba864312 fix bug in parse_quoted_separated_ext and add tests that caught the bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3399
diff changeset
371 (u'a:b:c d:e:f', None, u':', [(u'a', u'b:c'), (u'd', 'e:f')]),
b12aba864312 fix bug in parse_quoted_separated_ext and add tests that caught the bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3399
diff changeset
372 (u'a:b:c:d', None, u':', [(u'a', u'b:c:d')]),
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
373 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
374
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
375 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
376 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep)
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
377 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
378
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
379 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
380 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
381
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
382 def testExtendedParserBracketing(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
383 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
384 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
3402
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
385 (u'("a", "b", "c")', u',', None, [[u'(', u'a', u'b', u'c']]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
386 (u'("a"("b", "c"))', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
387 (u'("a"("b)))", "c"))', u',', None, [[u'(', u'a', [u'(', u'b)))', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
388 (u'("a"("b>>> ( ab )>", "c"))', u',', None, [[u'(', u'a', [u'(', u'b>>> ( ab )>', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
389 (u'("a" ("b" "c"))', None, None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
390 (u'("a"("b", "c") ) ', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
391 (u'("a", <"b", ("c")>)', u',', None, [[u'(', u'a', [u'<', u'b', [u'(', u'c']]]]),
3407
c3aa12fcdf12 add a parser test about leading None arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3405
diff changeset
392 (u',,,(a, b, c)', u',', None, [None, None, None, [u'(', u'a', u'b', u'c']]),
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
393 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
394
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
395 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
396 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, brackets=(u'<>', u'()'))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
397 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
398
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
399 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
400 yield [_check] + list(test)
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
401
3405
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
402 def testExtendedParserQuoting(self):
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
403 tests = [
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
404 (u'"a b" -a b-', u'"', [u'a b', u'-a', u'b-']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
405 (u'"a b" -a b-', u"-", [u'"a', u'b"', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
406 (u'"a b" -a b-', u'"-', [u'a b', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
407 (u'"a- b" -a b-', u'"-', [u'a- b', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
408 (u'"a- b" -a" b-', u'"-', [u'a- b', u'a" b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
409 ]
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
410
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
411 def _check(args, quotes, expected):
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
412 res = wikiutil.parse_quoted_separated_ext(args, quotes=quotes)
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
413 assert res == expected
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
414
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
415 for test in tests:
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
416 yield [_check] + list(test)
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
417
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
418 def testExtendedParserMultikey(self):
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
419 tests = [
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
420 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
421 (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
422 (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
423 (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
424 (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
425 (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
426 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
427 (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
428 (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
429 (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
430 (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
431 (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
432 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
433 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
434 (u'" a" "b" "c"', None, u':', [u' a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
435 (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
436 (u' a:a ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
437 (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
438 (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
439 (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
440 (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
441 (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
442 (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
443 (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
444 (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
445 ]
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
446
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
447 def _check(args, sep, kwsep, expected):
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
448 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True)
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
449 assert res == expected
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
450
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
451 for test in tests:
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
452 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
453
3403
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
454 def testExtendedParserPrefix(self):
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
455 P = wikiutil.ParserPrefix('+')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
456 M = wikiutil.ParserPrefix('-')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
457 tests = [
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
458 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
459 (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
460 (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
461 (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
462 (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
463 (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
464 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
465 (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
466 (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
467 (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
468 (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
469 (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
470 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
471 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
472 (u'" a" "b" "c"', None, u':', [u' a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
473 (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
474 (u' a:a ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
475 (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
476 (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
477 (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
478 (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
479 (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
480 (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
481 (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
482 (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
483
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
484 (u'-a:b:d', None, u':', [(M, u'a', u'b', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
485 (u'"-a:b:d"', None, u':', [(u'-a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
486 (u'-"a:b:d"', None, u':', [(M, u'a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
487 (u'-a:"b:c":"d e f g"', None, u':', [(M, u'a', u'b:c', u'd e f g')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
488 (u'+-a:b:d', None, u':', [(P, u'-a', u'b', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
489 (u'-"+a:b:d"', None, u':', [(M, u'+a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
490 # bit of a weird case...
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
491 (u'-+"a:b:d"', None, u':', [(M, u'+"a', u'b', u'd"')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
492 (u'-a:"b:c" a +b', None, u':', [(M, u'a', u'b:c'), u'a', (P, u'b')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
493 ]
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
494
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
495 def _check(args, sep, kwsep, expected):
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
496 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True, prefixes='-+')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
497 assert res == expected
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
498
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
499 for test in tests:
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
500 yield [_check] + list(test)
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
501
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
502 def testExtendedParserBracketingErrors(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
503 UCE = wikiutil.BracketUnexpectedCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
504 MCE = wikiutil.BracketMissingCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
505 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
506 (u'("a", "b", "c"', u',', None, MCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
507 (u'("a"("b", "c")', u',', None, MCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
508 (u'("a"<"b", "c")>', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
509 (u')("a" ("b" "c"))', None, None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
510 (u'("a", ("b", "c">))', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
511 (u'("a", ("b", <"c">>))', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
512 (u'(<(<)>)>', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
513 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
514
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
515 def _check(args, sep, kwsep, err):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
516 py.test.raises(err,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
517 wikiutil.parse_quoted_separated_ext,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
518 args, sep, kwsep,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
519 brackets=(u'<>', u'()'))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
520
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
521 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
522 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
523
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
524 class TestArgGetters:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
525 def testGetBoolean(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
526 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
527 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
528 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
529 (None, None, False, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
530 (None, None, True, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
531
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
532 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
533 (u'0', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
534 (u'1', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
535 (u'false', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
536 (u'true', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
537 (u'FALSE', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
538 (u'TRUE', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
539 (u'no', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
540 (u'yes', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
541 (u'NO', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
542 (u'YES', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
543 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
544 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
545 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
546
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
547 def testGetBooleanRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
548 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
549 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
550
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
551 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
552 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
553 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
554 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
555 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
556 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
557 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
558 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
559
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
560 # 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
561 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
562 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
563 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
564 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
565
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
566 def testGetInt(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
567 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
568 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
569 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
570 (None, None, -23, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
571 (None, None, 42, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
572
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
573 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
574 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
575 (u'42', None, None, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
576 (u'-23', None, None, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
577 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
578 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
579 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
580
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
581 def testGetIntRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
582 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
583 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
584
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
585 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
586 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
587 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
588 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
589 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
590 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
591 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
592 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
593
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
594 # 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
595 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
596 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
597 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
598 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
599
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
600 def testGetFloat(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
601 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
602 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
603 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
604 (None, None, -23.42, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
605 (None, None, 42.23, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
606
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
607 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
608 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
609 (u'42.23', None, None, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
610 (u'-23.42', None, None, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
611 (u'-23.42E3', None, None, -23.42E3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
612 (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
613 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
614 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
615 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
616
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
617 def testGetFloatRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
618 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
619 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
620
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
621 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
622 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
623 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
624 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
625 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
626 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
627 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
628 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
629
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
630 # 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
631 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
632 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
633 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
634
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
635 def testGetComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
636 tests = [
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
637 # default testing for None value
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
638 (None, None, None, None),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
639 (None, None, -23.42, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
640 (None, None, 42.23, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
641
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
642 # some real values
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
643 (u'0', None, None, 0),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
644 (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
645 (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
646 (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
647 (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
648 (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
649 (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
650 (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
651 (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
652 (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
653 (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
654 (u'-3', None, None, -3L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
655 (u'-300000000000000000000', None, None, -300000000000000000000L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
656 ]
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
657 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
658 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
659
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
660 def testGetComplexRaising(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
661 # wrong default type
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
662 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
663
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
664 # 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
665 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
666 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
667 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
668 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
669 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
670 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
671 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
672 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
673
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
674 # 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
675 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
676 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
677 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
678 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
679 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
680 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
681
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
682 def testGetUnicode(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
683 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
684 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
685 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
686 (None, None, u'', u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
687 (None, None, u'abc', u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
688
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
689 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
690 (u'', None, None, u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
691 (u'abc', None, None, u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
692 (u'"abc"', None, None, u'"abc"'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
693 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
694 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
695 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
696
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
697 def testGetUnicodeRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
698 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
699 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
700
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
701 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
702 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
703 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
704 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
705 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
706 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
707 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
708 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
709
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
710
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
711 class TestExtensionInvoking:
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
712 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
713 assert b is False
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
714
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
715 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
716 assert b == v
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
717 assert isinstance(b, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
718 assert isinstance(v, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
719
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
720 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
721 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
722
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
723 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
724 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
725
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
726 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
727 assert i == 1.4
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
728
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
729 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
730 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
731 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
732
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
733 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
734 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
735 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
736
3371
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
737 def _test_invoke_choice_required(self, i=wikiutil.required_arg((u'b', u'a'))):
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
738 assert i == u'a'
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
739
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
740 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
741 assert _trailing_args == [u'a']
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
742
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
743 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
744 assert _kwargs == expect
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
745
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
746 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
747 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
748 assert i == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
749
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
750 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
751 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
752 assert b == 8
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
753 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
754
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
755 ief = wikiutil.invoke_extension_function
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
756 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
757 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
758 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
759 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
760 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
761 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
762 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
763 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
764 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
765 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
766 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
767 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
768 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
769 self._test_invoke_int_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
770 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
771 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
772 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
773 _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
774 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
775 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
776 _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
777 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
778
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
779 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
780 ief(self.request, choicefn, u'', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
781 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
782 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
783 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
784 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
785 choicefn, u'x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
786 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
787 choicefn, u'choice=x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
788
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
789 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
790 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
791 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
792 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
793 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
794 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
795 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
796 self._test_invoke_float_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
797 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
798 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
799 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
800 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
801 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
802 [{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
803 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
804 [{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
805 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
806 [{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
807 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
808 [{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
809 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
810 [{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
811 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
812 self._test_invoke_float_required, u'')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
813 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
814 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
815 py.test.raises(ValueError, ief, self.request,
3371
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
816 self._test_invoke_choice_required, u'')
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
817 ief(self.request, self._test_invoke_choice_required, u'a')
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
818 ief(self.request, self._test_invoke_choice_required, u'i=a')
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
819 py.test.raises(ValueError, ief, self.request,
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
820 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
821
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
822 def testConstructors(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
823 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
824
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
825 # new style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
826 class TEST1(object):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
827 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
828 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
829 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
830
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
831 class TEST2(TEST1):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
832 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
833
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
834 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
835 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
836 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
837 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
838
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
839 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
840 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
841 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
842 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
843 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
844
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
845 # old style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
846 class TEST3:
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
847 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
848 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
849 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
850
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
851 class TEST4(TEST3):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
852 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
853
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
854 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
855 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
856 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
857 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
858
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
859 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
860 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
861 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
862 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
863 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
864
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
865 def testFailing(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
866 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
867
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
868 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
869 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
870 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
871
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
872 def testAllDefault(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
873 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
874
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
875 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
876 assert a == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
877 assert b == 2
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
878 assert c == 3
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
879 assert d == 4
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
880 return True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
881
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
882 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
883 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
884 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
885 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
886 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
887 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
888 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
889 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
890 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
891
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
892 def testInvokeComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
893 ief = wikiutil.invoke_extension_function
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
894
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
895 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
896 assert a == b
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
897 return True
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
898
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
899 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
900 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
901 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
902 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
903 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
904 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
905
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
906
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
907 class TestAnchorNames:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
908 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
909 tests = [
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
910 # text expected output
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
911 (u'\xf6\xf6ll\xdf\xdf', 'A.2BAPYA9g-ll.2BAN8A3w-'),
2571
a7dc3cc36362 apparently underscores aren't valid in IDs, fix this
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2568
diff changeset
912 (u'level 2', 'level2'),
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
913 (u'', 'A'),
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
914 (u'123', 'A123'),
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
915 ]
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
916 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
917 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
918
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
919 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
920 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
921 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
922
2771
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
923 class TestPageLinkMarkup:
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
924 def test_pagelinkmarkup(self):
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
925 tests = [
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
926 # pagename (no link text), expected markup
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
927 (('SomePage', ), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
928 (('Somepage', ), '[[Somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
929 (('somepage', ), '[[somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
930 (('Some Page', ), '[[Some Page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
931 # with link text
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
932 (('SomePage', 'SomePage'), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
933 (('SomePage', 'some page'), '[[SomePage|some page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
934 (('Some Page', 'Some Page'), '[[Some Page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
935 (('Some Page', 'some Page'), '[[Some Page|some Page]]'),
2771
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
936 ]
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
937 for params, expected in tests:
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
938 yield self._check, params, expected
2771
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
939
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
940 def _check(self, params, expected):
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
941 assert expected == wikiutil.pagelinkmarkup(*params)
2771
1134a5cc12c2 gui converter fixes for new markup, fix/extend tests, remove unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2745
diff changeset
942
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
943 class TestRelativeTools:
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
944 tests = [
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
945 # test expected output
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
946 # CHILD_PREFIX
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
947 (('MainPage', '/SubPage1'), 'MainPage/SubPage1'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
948 (('MainPage', '/SubPage1/SubPage2'), 'MainPage/SubPage1/SubPage2'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
949 (('MainPage/SubPage1', '/SubPage2/SubPage3'), 'MainPage/SubPage1/SubPage2/SubPage3'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
950 (('', '/OtherMainPage'), 'OtherMainPage'), # strange
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
951 # PARENT_PREFIX
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
952 (('MainPage/SubPage', '../SisterPage'), 'MainPage/SisterPage'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
953 (('MainPage/SubPage1/SubPage2', '../SisterPage'), 'MainPage/SubPage1/SisterPage'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
954 (('MainPage/SubPage1/SubPage2', '../../SisterPage'), 'MainPage/SisterPage'),
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
955 (('MainPage', '../SisterPage'), 'SisterPage'), # strange
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
956 ]
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
957 def test_abs_pagename(self):
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
958 for (current_page, relative_page), absolute_page in self.tests:
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
959 yield self._check_abs_pagename, current_page, relative_page, absolute_page
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
960
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
961 def _check_abs_pagename(self, current_page, relative_page, absolute_page):
2706
d2d4e74978bd remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2705
diff changeset
962 assert absolute_page == wikiutil.AbsPageName(current_page, relative_page)
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
963
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
964 def test_rel_pagename(self):
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
965 for (current_page, relative_page), absolute_page in self.tests:
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
966 yield self._check_rel_pagename, current_page, absolute_page, relative_page
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
967
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
968 def _check_rel_pagename(self, current_page, absolute_page, relative_page):
2706
d2d4e74978bd remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2705
diff changeset
969 assert relative_page == wikiutil.RelPageName(current_page, absolute_page)
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
970
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
971
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2378
diff changeset
972 coverage_modules = ['MoinMoin.wikiutil']