annotate MoinMoin/_tests/test_wikiutil.py @ 3400:b12aba864312

fix bug in parse_quoted_separated_ext and add tests that caught the bug
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sat, 22 Mar 2008 01:37:49 +0100
parents b6d727809985
children d75e838f4b72
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',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 'ATemplate',
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']),
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
313 (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
314 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
315 ]
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 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
317 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
318 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
319 for val in result:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
320 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
321
3259
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
322 def testUnitArgument(self):
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
323 result = wikiutil.UnitArgument('7mm', float, ['%', 'mm'])
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
324 assert result.get_default() == (7.0, 'mm')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
325 assert result.parse_argument('8%') == (8.0, '%')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
326 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
327 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
328 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
329
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
330 def testExtendedParser(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
331 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
332 (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
333 (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
334 (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
335 (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
336 (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
337 (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
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; 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
340 (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
341 (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
342 (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
343 (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
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, 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
347 (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
348 (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
349 (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
350 (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
351 (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
352 (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
353 (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
354 (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
355 (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
356 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
357
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
358 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
359 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
360 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
361
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
362 for test in tests:
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
363 yield tuple([_check] + list(test))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
364
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
365 def testExtendedParserBracketing(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
366 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
367 (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
368 (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
369 (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
370 (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
371 (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
372 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
373
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
374 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
375 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
376 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
377
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
378 for test in tests:
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
379 yield tuple([_check] + list(test))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
380
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
381 def testExtendedParserBracketingErrors(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
382 UCE = wikiutil.BracketUnexpectedCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
383 MCE = wikiutil.BracketMissingCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
384 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
385 (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
386 (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
387 (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
388 (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
389 (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
390 (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
391 (u'(<(<)>)>', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
392 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
393
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
394 def _check(args, sep, kwsep, err):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
395 py.test.raises(err,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
396 wikiutil.parse_quoted_separated_ext,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
397 args, sep, kwsep,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
398 brackets=(u'<>', u'()'))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
400 for test in tests:
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
401 yield tuple([_check] + list(test))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
402
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
403 class TestArgGetters:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
404 def testGetBoolean(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
405 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
406 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
407 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
408 (None, None, False, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
409 (None, None, True, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
410
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
411 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
412 (u'0', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
413 (u'1', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
414 (u'false', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
415 (u'true', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
416 (u'FALSE', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
417 (u'TRUE', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
418 (u'no', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
419 (u'yes', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
420 (u'NO', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
421 (u'YES', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
422 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
423 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
424 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
425
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
426 def testGetBooleanRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
427 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
428 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
429
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
430 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
431 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
432 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
433 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
434 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
435 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
436 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
437 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
438
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
439 # 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
440 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
441 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
442 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
443 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
444
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
445 def testGetInt(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
446 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
447 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
448 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
449 (None, None, -23, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
450 (None, None, 42, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
451
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
452 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
453 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
454 (u'42', None, None, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
455 (u'-23', None, None, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
456 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
457 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
458 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
459
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
460 def testGetIntRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
461 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
462 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
463
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
464 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
473 # 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
474 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
475 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
476 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
477 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
478
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
479 def testGetFloat(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
480 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
481 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
482 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
483 (None, None, -23.42, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
484 (None, None, 42.23, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
485
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
486 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
487 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
488 (u'42.23', None, None, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
489 (u'-23.42', None, None, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
490 (u'-23.42E3', None, None, -23.42E3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
491 (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
492 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
493 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
494 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
495
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
496 def testGetFloatRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
497 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
498 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
499
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
500 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
501 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
502 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
503 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
504 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
505 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
506 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
507 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
508
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
509 # 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
510 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
511 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
512 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
513
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
514 def testGetComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
515 tests = [
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
516 # default testing for None value
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
517 (None, None, None, None),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
518 (None, None, -23.42, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
519 (None, None, 42.23, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
520
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
521 # some real values
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
522 (u'0', None, None, 0),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
523 (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
524 (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
525 (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
526 (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
527 (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
528 (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
529 (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
530 (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
531 (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
532 (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
533 (u'-3', None, None, -3L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
534 (u'-300000000000000000000', None, None, -300000000000000000000L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
535 ]
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
536 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
537 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
538
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
539 def testGetComplexRaising(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
540 # wrong default type
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
541 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
542
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
543 # 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
544 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
545 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
546 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
547 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
548 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
549 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
550 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
551 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
552
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
553 # 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
554 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
555 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
556 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
557 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
558 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
559 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
560
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
561 def testGetUnicode(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
562 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
563 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
564 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
565 (None, None, u'', u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
566 (None, None, u'abc', u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
567
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
568 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
569 (u'', None, None, u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
570 (u'abc', None, None, u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
571 (u'"abc"', None, None, u'"abc"'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
572 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
573 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
574 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
575
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
576 def testGetUnicodeRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
577 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
578 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
579
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
580 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
581 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
582 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
583 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
584 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
585 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
586 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
587 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
588
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
589
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
590 class TestExtensionInvoking:
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
591 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
592 assert b is False
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
593
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
594 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
595 assert b == v
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
596 assert isinstance(b, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
597 assert isinstance(v, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
598
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
599 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
600 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
601
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
602 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
603 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
604
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
605 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
606 assert i == 1.4
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
607
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
608 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
609 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
610 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
611
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
612 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
613 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
614 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
615
3371
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
616 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
617 assert i == u'a'
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
618
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
619 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
620 assert _trailing_args == [u'a']
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
621
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
622 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
623 assert _kwargs == expect
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
624
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
625 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
626 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
627 assert i == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
628
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
629 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
630 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
631 assert b == 8
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
632 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
633
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
634 ief = wikiutil.invoke_extension_function
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
635 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
636 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
637 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
638 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
639 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
640 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
641 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
642 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
643 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
644 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
645 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
646 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
647 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
648 self._test_invoke_int_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
649 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
650 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
651 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
652 _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
653 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
654 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
655 _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
656 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
657
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
658 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
659 ief(self.request, choicefn, u'', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
660 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
661 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
662 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
663 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
664 choicefn, u'x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
665 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
666 choicefn, u'choice=x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
667
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
668 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
669 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
670 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
671 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
672 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
673 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
674 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
675 self._test_invoke_float_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
676 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
677 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
678 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
679 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
680 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
681 [{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
682 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
683 [{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
684 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
685 [{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
686 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
687 [{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
688 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
689 [{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
690 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
691 self._test_invoke_float_required, u'')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
701 def testConstructors(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
702 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
703
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
704 # new style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
705 class TEST1(object):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
706 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
707 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
708 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
709
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
710 class TEST2(TEST1):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
711 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
712
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
713 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
714 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
715 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
716 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
717
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
718 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
719 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
720 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
721 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
722 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
723
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
724 # old style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
725 class TEST3:
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
726 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
727 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
728 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
729
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
730 class TEST4(TEST3):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
731 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
732
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
733 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
734 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
735 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
736 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
737
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
738 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
739 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
740 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
741 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
742 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
743
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
744 def testFailing(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
745 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
746
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
747 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
748 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
749 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
750
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
751 def testAllDefault(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
752 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
753
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
754 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
755 assert a == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
756 assert b == 2
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
757 assert c == 3
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
758 assert d == 4
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
759 return True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
760
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
761 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
762 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
763 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
764 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
765 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
766 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
767 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
768 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
769 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
770
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
771 def testInvokeComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
772 ief = wikiutil.invoke_extension_function
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
773
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
774 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
775 assert a == b
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
776 return True
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
777
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
778 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
779 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
780 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
781 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
782 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
783 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
784
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
785
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
786 class TestAnchorNames:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
787 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
788 tests = [
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
789 # text expected output
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
790 (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
791 (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
792 (u'', 'A'),
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
793 (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
794 ]
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
795 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
796 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
797
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
798 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
799 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
800 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
801
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
802 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
803 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
804 tests = [
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
805 # 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
806 (('SomePage', ), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
807 (('Somepage', ), '[[Somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
808 (('somepage', ), '[[somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
809 (('Some Page', ), '[[Some Page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
810 # with link text
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
811 (('SomePage', 'SomePage'), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
812 (('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
813 (('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
814 (('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
815 ]
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
816 for params, expected in tests:
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
817 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
818
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
819 def _check(self, params, expected):
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
820 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
821
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
822 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
823 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
824 # 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
825 # 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
826 (('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
827 (('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
828 (('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
829 (('', '/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
830 # 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
831 (('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
832 (('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
833 (('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
834 (('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
835 ]
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
836 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
837 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
838 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
839
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
840 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
841 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
842
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
843 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
844 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
845 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
846
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
847 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
848 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
849
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
850
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2378
diff changeset
851 coverage_modules = ['MoinMoin.wikiutil']