annotate MoinMoin/_tests/test_wikiutil.py @ 3573:124d0ef138aa

change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 10 May 2008 23:37:00 +0200
parents c3aa12fcdf12
children dcd932f8c4ec 3b36f0cfc656
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
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
300 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
301 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
302 tests = [
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
303 # regular and quoting tests
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
304 (u'd = 4,c=3,b=2,a= 1 ', [u'd = 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
305 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
306 (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
307 (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
308 (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
309 (u'" a "', [u' a ']),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
310 (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
311 (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
312 (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
313 (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
314 (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
315 (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
316 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 ]
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 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
319 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
320 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
321 for val in result:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
322 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
323
3259
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
324 def testUnitArgument(self):
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
325 result = wikiutil.UnitArgument('7mm', float, ['%', 'mm'])
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
326 assert result.get_default() == (7.0, 'mm')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
327 assert result.parse_argument('8%') == (8.0, '%')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
328 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
329 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
330 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
331
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
332 def testExtendedParser(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
333 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
334 (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
335 (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
336 (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
337 (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
338 (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
339 (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
340 (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
341 (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
342 (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
343 (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
344 (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
345 (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
346 (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
347 (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
348 (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
349 (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
350 (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
351 (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
352 (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
353 (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
354 (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
355 (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
356 (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
357 (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
358 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
359
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
360 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
361 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
362 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
363
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
364 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
365 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
366
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
367 def testExtendedParserBracketing(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
368 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
369 (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
370 (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
371 (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
372 (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
373 (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
374 (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
375 (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
376 (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
377 (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
378 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
379
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
380 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
381 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
382 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
383
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
384 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
385 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
386
3405
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
387 def testExtendedParserQuoting(self):
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
388 tests = [
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
389 (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
390 (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
391 (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
392 (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
393 (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
394 ]
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
395
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
396 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
397 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
398 assert res == expected
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
399
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
400 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
401 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
402
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
403 def testExtendedParserMultikey(self):
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
404 tests = [
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
405 (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
406 (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
407 (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
408 (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
409 (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
410 (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
411 (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
412 (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
413 (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
414 (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
415 (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
416 (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
417 (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
418 (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
419 (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
420 (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
421 (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
422 (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
423 (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
424 (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
425 (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
426 (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
427 (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
428 (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
429 (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
430 ]
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
431
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
432 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
433 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
434 assert res == expected
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
435
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
436 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
437 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
438
3403
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
439 def testExtendedParserPrefix(self):
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
440 P = wikiutil.ParserPrefix('+')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
441 M = wikiutil.ParserPrefix('-')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
442 tests = [
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
443 (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
444 (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
445 (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
446 (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
447 (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
448 (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
449 (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
450 (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
451 (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
452 (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
453 (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
454 (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
455 (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
456 (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
457 (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
458 (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
459 (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
460 (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
461 (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
462 (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
463 (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
464 (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
465 (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
466 (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
467 (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
468
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
469 (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
470 (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
471 (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
472 (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
473 (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
474 (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
475 # 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
476 (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
477 (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
478 ]
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
479
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
480 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
481 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
482 assert res == expected
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 for test in tests:
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
485 yield [_check] + list(test)
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
486
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
487 def testExtendedParserBracketingErrors(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
488 UCE = wikiutil.BracketUnexpectedCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
489 MCE = wikiutil.BracketMissingCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
490 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
491 (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
492 (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
493 (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
494 (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
495 (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
496 (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
497 (u'(<(<)>)>', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
498 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
499
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
500 def _check(args, sep, kwsep, err):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
501 py.test.raises(err,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
502 wikiutil.parse_quoted_separated_ext,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
503 args, sep, kwsep,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
504 brackets=(u'<>', u'()'))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
505
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
506 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
507 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
508
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
509 class TestArgGetters:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
510 def testGetBoolean(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
511 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
512 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
513 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
514 (None, None, False, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
515 (None, None, True, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
516
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
517 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
518 (u'0', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
519 (u'1', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
520 (u'false', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
521 (u'true', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
522 (u'FALSE', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
523 (u'TRUE', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
524 (u'no', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
525 (u'yes', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
526 (u'NO', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
527 (u'YES', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
528 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
529 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
530 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
531
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
532 def testGetBooleanRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
533 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
534 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
535
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
536 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
537 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
538 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
539 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
540 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
541 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
542 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
543 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
544
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
545 # 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
546 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
547 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
548 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
549 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
550
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
551 def testGetInt(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
552 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
553 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
554 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
555 (None, None, -23, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
556 (None, None, 42, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
557
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
558 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
559 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
560 (u'42', None, None, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
561 (u'-23', None, None, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
562 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
563 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
564 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
565
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
566 def testGetIntRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
567 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
568 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
569
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
570 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
571 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
572 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
573 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
574 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
575 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
576 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
577 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
578
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
579 # 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
580 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
581 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
582 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
583 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
584
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
585 def testGetFloat(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
586 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
587 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
588 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
589 (None, None, -23.42, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
590 (None, None, 42.23, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
591
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
592 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
593 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
594 (u'42.23', None, None, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
595 (u'-23.42', None, None, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
596 (u'-23.42E3', None, None, -23.42E3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
597 (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
598 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
599 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
600 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
601
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
602 def testGetFloatRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
603 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
604 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
605
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
606 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
607 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
608 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
609 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
610 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
611 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
612 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
613 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
614
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
615 # 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
616 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
617 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
618 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
619
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
620 def testGetComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
621 tests = [
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
622 # default testing for None value
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
623 (None, None, None, None),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
624 (None, None, -23.42, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
625 (None, None, 42.23, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
626
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
627 # some real values
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
628 (u'0', None, None, 0),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
629 (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
630 (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
631 (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
632 (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
633 (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
634 (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
635 (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
636 (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
637 (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
638 (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
639 (u'-3', None, None, -3L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
640 (u'-300000000000000000000', None, None, -300000000000000000000L),
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 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
643 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
644
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
645 def testGetComplexRaising(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
646 # wrong default type
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
647 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
648
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
649 # 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
650 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
651 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
652 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
653 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
654 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
655 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
656 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
657 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
658
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
659 # 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
660 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
661 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
662 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
663 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
664 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
665 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
666
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
667 def testGetUnicode(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
668 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
669 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
670 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
671 (None, None, u'', u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
672 (None, None, u'abc', u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
673
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
674 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
675 (u'', None, None, u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
676 (u'abc', None, None, u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
677 (u'"abc"', None, None, u'"abc"'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
678 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
679 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
680 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
681
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
682 def testGetUnicodeRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
683 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
684 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
685
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
686 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
687 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
688 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
689 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
690 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
691 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
692 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
693 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
694
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
695
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
696 class TestExtensionInvoking:
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
697 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
698 assert b is False
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
699
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
700 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
701 assert b == v
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
702 assert isinstance(b, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
703 assert isinstance(v, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
704
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
705 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
706 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
707
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
708 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
709 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
710
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
711 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
712 assert i == 1.4
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
713
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
714 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
715 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
716 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
717
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
718 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
719 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
720 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
721
3371
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
722 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
723 assert i == u'a'
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
724
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
725 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
726 assert _trailing_args == [u'a']
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
727
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
728 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
729 assert _kwargs == expect
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
730
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
731 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
732 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
733 assert i == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
734
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
735 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
736 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
737 assert b == 8
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
738 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
739
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
740 ief = wikiutil.invoke_extension_function
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
741 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
742 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
743 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
744 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
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 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
754 self._test_invoke_int_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
755 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
756 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
757 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
758 _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
759 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
760 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
761 _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
762 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
763
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
764 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
765 ief(self.request, choicefn, u'', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
766 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
767 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
768 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
769 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
770 choicefn, u'x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
771 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
772 choicefn, u'choice=x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
773
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
774 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
775 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
776 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
777 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
778 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
779 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
780 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
781 self._test_invoke_float_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
782 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
783 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
784 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
785 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
786 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
787 [{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
788 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
789 [{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
790 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
791 [{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
792 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
793 [{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
794 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
795 [{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
796 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
797 self._test_invoke_float_required, u'')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
798 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
799 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
800 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
801 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
802 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
803 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
804 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
805 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
806
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
807 def testConstructors(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
808 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
809
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
810 # new style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
811 class TEST1(object):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
812 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
813 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
814 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
815
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
816 class TEST2(TEST1):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
817 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
818
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
819 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
820 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
821 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
822 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
823
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
824 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
825 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
826 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
827 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
828 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
829
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
830 # old style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
831 class TEST3:
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
832 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
833 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
834 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
835
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
836 class TEST4(TEST3):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
837 pass
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, 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
840 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
841 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
842 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
843
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
844 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
845 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
846 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
847 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
848 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
849
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
850 def testFailing(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
851 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
852
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
853 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
854 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
855 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
856
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
857 def testAllDefault(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
858 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
859
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
860 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
861 assert a == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
862 assert b == 2
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
863 assert c == 3
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
864 assert d == 4
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
865 return True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
866
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
867 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
868 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
869 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
870 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
871 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
872 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
873 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
874 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
875 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
876
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
877 def testInvokeComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
878 ief = wikiutil.invoke_extension_function
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
879
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
880 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
881 assert a == b
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
882 return True
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
883
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
884 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
885 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
886 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
887 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
888 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
889 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
890
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
891
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
892 class TestAnchorNames:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
893 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
894 tests = [
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
895 # text expected output
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
896 (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
897 (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
898 (u'', 'A'),
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
899 (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
900 ]
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
901 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
902 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
903
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
904 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
905 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
906 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
907
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
908 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
909 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
910 tests = [
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
911 # 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
912 (('SomePage', ), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
913 (('Somepage', ), '[[Somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
914 (('somepage', ), '[[somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
915 (('Some Page', ), '[[Some Page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
916 # with link text
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
917 (('SomePage', 'SomePage'), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
918 (('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
919 (('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
920 (('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
921 ]
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
922 for params, expected in tests:
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
923 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
924
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
925 def _check(self, params, expected):
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
926 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
927
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
928 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
929 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
930 # 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
931 # 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
932 (('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
933 (('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
934 (('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
935 (('', '/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
936 # 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
937 (('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
938 (('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
939 (('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
940 (('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
941 ]
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
942 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
943 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
944 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
945
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
946 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
947 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
948
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 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
950 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
951 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
952
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 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
954 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
955
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
956
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2378
diff changeset
957 coverage_modules = ['MoinMoin.wikiutil']