annotate MoinMoin/_tests/test_wikiutil.py @ 4607:d8e5e9cfadf1

always do 'from werkzeug import ...', except for contrib, exceptions, routing, script
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 23 Feb 2009 22:39:32 +0100
parents 3caaa8c74c41
children 9b6b7ff7f5ac
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
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
12 from MoinMoin import config, wikiutil
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13
4607
d8e5e9cfadf1 always do 'from werkzeug import ...', except for contrib, exceptions, routing, script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4569
diff changeset
14 from werkzeug import MultiDict
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4566
diff changeset
15
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16
2265
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
17 class TestQueryStringSupport:
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
18 tests = [
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
19 ('', {}, {}),
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
20 ('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
21 ('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
22 ('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
23 ]
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
24 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
25 for qstr, expected_str, expected_unicode in self.tests:
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4566
diff changeset
26 assert wikiutil.parseQueryString(qstr) == MultiDict(expected_unicode)
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4566
diff changeset
27 assert wikiutil.parseQueryString(unicode(qstr)) == MultiDict(expected_unicode)
2265
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:
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4566
diff changeset
31 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_unicode)) == MultiDict(in_unicode)
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4566
diff changeset
32 assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_str)) == MultiDict(in_unicode)
2265
a607b0329922 add tests for parsing and making of query strings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2173
diff changeset
33
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
34
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
35 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
36 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
37 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
38 # 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
39 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
40 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
41 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
42 # 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
43 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
44 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
45 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
46 # 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
47 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
48 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
49 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
50 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
51
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 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
53 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
54
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
2267
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
56 class TestCleanInput:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
57 def testCleanInput(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
58 tests = [(u"", u""), # empty
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
59 (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
60 (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
61 (u"a"*500, u""), # too long
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
62 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
63 for instr, outstr in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
64 assert wikiutil.clean_input(instr) == outstr
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
65
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
66
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
67 class TestInterWiki:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
68 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
69 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
70 ('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
71 (':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
72 # 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
73 # 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
74 ]
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
75 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
76 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
77
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
78 def testJoinWiki(self):
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
79 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
80 (('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
81 (('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
82 (('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
83 ]
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
84 for (baseurl, pagename), url in tests:
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
85 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
86
463f3de3f981 more wikiutil tests, minor bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2266
diff changeset
87
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
88 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
89 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
90 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
91
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
92 class TestSystemPage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 systemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 # 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
95 'SystemPagesInEnglishGroup',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 # 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
97 'RecentChanges',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 'TitleIndex',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 notSystemPages = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 'NoSuchPageYetAndWillNeverBe',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 def testSystemPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105 """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
106 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
107 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
108 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
109 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
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111
2454
18c71299e2bb convert test_wikiutil to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2453
diff changeset
112 class TestTemplatePage:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 good = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 'aTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 'MyTemplate',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 bad = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 'Template',
3573
124d0ef138aa change page_*_regex processing, see docs/CHANGES (fixes Xapian category search for non-english)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3407
diff changeset
119 'I want a Template',
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 'TemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 'xTemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122 'XTemplateInFront',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125 def testTemplatePage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 """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
127 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
128 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
129 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
130 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
131
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132
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
133 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
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 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
136 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
137 # 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
138 ('', '', 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
139
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 # 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
141 ('%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
142
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 # 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
144 ('%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
145 ('%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
146 ('%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
147 ('%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
148 ('%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
149 ('%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
150
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 # 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
152 ("%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
153 ("%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
154 ("%ifs", '"100"', 1, {0: "100"}),
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
155
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
156 # 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
157 ("%(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
158 ("%(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
159 ("%(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
160 ("%(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
161
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
162 # 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
163 ("%(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
164 ("%(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
165 ("%(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
166 ("%(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
167
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
168 # 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
169 ("%(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
170 ("%(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
171 ("%(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
172 ("%(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
173
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
174 # 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
175 ("%(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
176 ("%(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
177 ("%(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
178 ("%(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
179 # 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
180 ("%(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
181 ("%(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
182
fe71235f1f7c ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2454
diff changeset
183 # 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
184 ("%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
185
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 ]
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 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
188 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
189 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
190 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
191
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
192 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
193 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
194 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
195 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
196
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
197 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
198 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
199 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
200 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
201
2456
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
202 def testWrongTypeFixedPosArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
203 args = '0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
204 argParser = wikiutil.ParameterParser("%b")
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
205 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
206
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
207 def testWrongTypeNamedArgument(self):
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
208 args = 'flag=0.0'
15502589ece6 ParameterParser: check types, remove unused code, tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
209 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
210 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
211
2164
7fed5edaa2a5 tests: some fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
212
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
213 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
214 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
215 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
216 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
217 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
218 # 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
219 (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
220 (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
221 (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
222 (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
223 (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
224 (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
225 (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
226 (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
227 (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
228 (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
229 (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
230 (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
231 (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
232 # 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
233 (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
234 (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
235 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
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 = , 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
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': u'',
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 = ', ([], {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
245 [])),
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
246 (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
247 (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
248 [])),
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
249 # 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
250 (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
251 [])),
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
252 # 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
253 (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
254 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
255 # 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
256 (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
257 [u'3', u'4'])),
2544
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
258 # can quote quotes:
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
259 (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
260 (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
261 (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
262 [])),
bc49e37d2649 quoting tests for the parameter parser
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2543
diff changeset
263 (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
264 [])),
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
265 ]
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
266 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
267 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
268 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
269 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
270 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
271 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
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].values():
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[2]:
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)
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
277
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
278 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
279 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
280 # 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
281 (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
282 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
283 (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
284 (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
285 ]
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 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
287 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
288 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
289 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
290 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
291 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
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].values():
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[2]:
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)
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
297
3815
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
298 def testDoubleNameValueSeparator(self):
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
299 tests = [
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
300 # regular and quoting tests
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
301 (u'd==4,=3 ', ([], {u'd': u'=4', u'': u'3'}, [])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
302 (u'===a,b,c,d', ([], {u'': u'==a'}, [u'b', u'c', u'd'])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
303 (u'a,b,===,c,d', ([u'a', u'b'], {u'': u'=='}, [u'c', u'd'])),
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
304 ]
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
305
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
306 def _check(a, e):
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
307 r = wikiutil.parse_quoted_separated(a)
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
308 assert r == e
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
309
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
310 for args, expected in tests:
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
311 yield _check, args, expected
dcd932f8c4ec fix MoinMoinBugs/TypeErrorInWikiutils
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3573
diff changeset
312
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
313 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
314 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
315 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
316 # 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
317 (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
318 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
319 (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
320 (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
321 (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
322 (u'" a "', [u' a ']),
2510
f6a777f45559 clarify None behaviour for keys, add tests
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2507
diff changeset
323 (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
324 (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
325 (u'"quote "" :)", b', [u'quote " :)', u'b']),
3404
e979e3cad972 parse_quoted_separated_ext: fix unclosed quotes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3403
diff changeset
326 (u'"unended quote', [u'"unended quote']),
e979e3cad972 parse_quoted_separated_ext: fix unclosed quotes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3403
diff changeset
327 (u'"', [u'"']),
2507
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
328 (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
329 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
330 ]
ea255685d6b0 add macro argument parser and use it to invoke macros with args directly
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2456
diff changeset
331 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
332 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
333 assert expected == result
2528
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
334 for val in result:
1ae621d83c5b fix arg parser bug, test for this bug
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2512
diff changeset
335 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
336
3259
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
337 def testUnitArgument(self):
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
338 result = wikiutil.UnitArgument('7mm', float, ['%', 'mm'])
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
339 assert result.get_default() == (7.0, 'mm')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
340 assert result.parse_argument('8%') == (8.0, '%')
c538d9029186 test_wikiutil: testUnitArgument added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2773
diff changeset
341 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
342 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
343 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
344
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
345 def testExtendedParser(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
346 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
347 (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
348 (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
349 (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
350 (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
351 (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
352 (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
353 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
354 (u'a:b; 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
355 (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
356 (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
357 (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
358 (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
359 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
360 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
361 (u'" a" "b" "c"', None, 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
362 (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
363 (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
364 (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
365 (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
366 (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
367 (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
368 (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
369 (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
370 (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
371 ]
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 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
374 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
375 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
376
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
377 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
378 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
379
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
380 def testExtendedParserBracketing(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
381 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
382 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
3402
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
383 (u'("a", "b", "c")', u',', None, [[u'(', u'a', u'b', u'c']]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
384 (u'("a"("b", "c"))', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
385 (u'("a"("b)))", "c"))', u',', None, [[u'(', u'a', [u'(', u'b)))', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
386 (u'("a"("b>>> ( ab )>", "c"))', u',', None, [[u'(', u'a', [u'(', u'b>>> ( ab )>', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
387 (u'("a" ("b" "c"))', None, None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
388 (u'("a"("b", "c") ) ', u',', None, [[u'(', u'a', [u'(', u'b', u'c']]]),
4b94ff6a4073 wikiutil.parse_quoted_separated_ext: make bracketing support indicate which bracket was used
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3401
diff changeset
389 (u'("a", <"b", ("c")>)', u',', None, [[u'(', u'a', [u'<', u'b', [u'(', u'c']]]]),
3407
c3aa12fcdf12 add a parser test about leading None arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3405
diff changeset
390 (u',,,(a, b, c)', u',', None, [None, None, None, [u'(', u'a', u'b', u'c']]),
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
391 ]
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 def _check(args, sep, kwsep, expected):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
394 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
395 assert res == expected
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
396
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
397 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
398 yield [_check] + list(test)
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
399
3405
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
400 def testExtendedParserQuoting(self):
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
401 tests = [
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
402 (u'"a b" -a b-', u'"', [u'a b', u'-a', u'b-']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
403 (u'"a b" -a b-', u"-", [u'"a', u'b"', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
404 (u'"a b" -a b-', u'"-', [u'a b', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
405 (u'"a- b" -a b-', u'"-', [u'a- b', u'a b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
406 (u'"a- b" -a" b-', u'"-', [u'a- b', u'a" b']),
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
407 ]
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
408
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
409 def _check(args, quotes, expected):
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
410 res = wikiutil.parse_quoted_separated_ext(args, quotes=quotes)
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
411 assert res == expected
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
412
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
413 for test in tests:
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
414 yield [_check] + list(test)
6f5e09f14525 parse_quoted_separated_ext: allow multiple/different quoting characters
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3404
diff changeset
415
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
416 def testExtendedParserMultikey(self):
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
417 tests = [
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
418 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
419 (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
420 (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
421 (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
422 (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
423 (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
424 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
425 (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
426 (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
427 (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
428 (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
429 (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
430 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
431 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
432 (u'" a" "b" "c"', None, u':', [u' a', u'b', u'c']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
433 (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
434 (u' a:a ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
435 (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
436 (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
437 (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
438 (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
439 (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
440 (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
441 (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
442 (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
443 ]
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
444
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
445 def _check(args, sep, kwsep, expected):
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
446 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True)
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
447 assert res == expected
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
448
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
449 for test in tests:
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
450 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
451
3403
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
452 def testExtendedParserPrefix(self):
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
453 P = wikiutil.ParserPrefix('+')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
454 M = wikiutil.ParserPrefix('-')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
455 tests = [
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
456 (u'"a", "b", "c"', u',', None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
457 (u'a:b, b:c, c:d', u',', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
458 (u'a:b, b:c, c:d', u',', None, [u'a:b', u'b:c', u'c:d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
459 (u'a=b, b=c, c=d', u',', None, [u'a=b', u'b=c', u'c=d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
460 (u'a=b, b=c, c=d', u',', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
461 (u'"a"; "b"; "c"', u';', None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
462 (u'a:b; b:c; c:d', u';', u':', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
463 (u'a:b; b:c; c:d', u';', None, [u'a:b', u'b:c', u'c:d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
464 (u'a=b; b=c; c=d', u';', None, [u'a=b', u'b=c', u'c=d']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
465 (u'a=b; b=c; c=d', u';', u'=', [(u'a', u'b'), (u'b', u'c'), (u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
466 (u'"a" "b" "c"', None, None, [u'a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
467 (u'" a " "b" "c"', None, None, [u' a ', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
468 (u'"a " "b" "c"', None, None, [u'a ', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
469 (u'" a" "b" "c"', None, None, [u' a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
470 (u'" a" "b" "c"', None, u':', [u' a', u'b', u'c']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
471 (u'"a:a" "b:b" "c:b"', None, u':', [u'a:a', u'b:b', u'c:b']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
472 (u' a:a ', None, u':', [None, None, None, (u'a', u'a'), None, None]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
473 (u'a a: a', None, u':', [u'a', (u'a', None), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
474 (u'a a:"b c d" a', None, u':', [u'a', (u'a', u'b c d'), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
475 (u'a a:"b "" d" a', None, u':', [u'a', (u'a', u'b " d'), u'a']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
476 (u'title:Help* dog cat', None, u':', [(u'title', u'Help*'), u'dog', u'cat']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
477 (u'title:Help* "dog cat"', None, u':', [(u'title', u'Help*'), u'dog cat']),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
478 (u'a:b:c d:e:f', None, u':', [(u'a', u'b', u'c'), (u'd', 'e', u'f')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
479 (u'a:b:c:d', None, u':', [(u'a', u'b', u'c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
480 (u'a:"b:c":d', None, u':', [(u'a', u'b:c', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
481
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
482 (u'-a:b:d', None, u':', [(M, u'a', u'b', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
483 (u'"-a:b:d"', None, u':', [(u'-a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
484 (u'-"a:b:d"', None, u':', [(M, u'a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
485 (u'-a:"b:c":"d e f g"', None, u':', [(M, u'a', u'b:c', u'd e f g')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
486 (u'+-a:b:d', None, u':', [(P, u'-a', u'b', u'd')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
487 (u'-"+a:b:d"', None, u':', [(M, u'+a:b:d')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
488 # bit of a weird case...
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
489 (u'-+"a:b:d"', None, u':', [(M, u'+"a', u'b', u'd"')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
490 (u'-a:"b:c" a +b', None, u':', [(M, u'a', u'b:c'), u'a', (P, u'b')]),
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
491 ]
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
492
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
493 def _check(args, sep, kwsep, expected):
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
494 res = wikiutil.parse_quoted_separated_ext(args, sep, kwsep, multikey=True, prefixes='-+')
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
495 assert res == expected
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
496
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
497 for test in tests:
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
498 yield [_check] + list(test)
d479e393e318 wikiutil.parse_quoted_separated_ext: allow for prefixes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3402
diff changeset
499
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
500 def testExtendedParserBracketingErrors(self):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
501 UCE = wikiutil.BracketUnexpectedCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
502 MCE = wikiutil.BracketMissingCloseError
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
503 tests = [
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
504 (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
505 (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
506 (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
507 (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
508 (u'("a", ("b", "c">))', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
509 (u'("a", ("b", <"c">>))', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
510 (u'(<(<)>)>', u',', None, UCE),
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
511 ]
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
512
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
513 def _check(args, sep, kwsep, err):
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
514 py.test.raises(err,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
515 wikiutil.parse_quoted_separated_ext,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
516 args, sep, kwsep,
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
517 brackets=(u'<>', u'()'))
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
518
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
519 for test in tests:
3401
d75e838f4b72 wikiutil.parse_quoted_separated_ext: allow multi-key stuff
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3400
diff changeset
520 yield [_check] + list(test)
3399
b6d727809985 introduce wikiutil.parse_quoted_separated_ext
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3371
diff changeset
521
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
522 class TestArgGetters:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
523 def testGetBoolean(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
524 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
525 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
526 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
527 (None, None, False, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
528 (None, None, True, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
529
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
530 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
531 (u'0', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
532 (u'1', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
533 (u'false', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
534 (u'true', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
535 (u'FALSE', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
536 (u'TRUE', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
537 (u'no', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
538 (u'yes', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
539 (u'NO', None, None, False),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
540 (u'YES', None, None, True),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
541 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
542 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
543 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
544
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
545 def testGetBooleanRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
546 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
547 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
548
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
549 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
550 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
551 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
552 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
553 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
554 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
555 py.test.raises(TypeError, wikiutil.get_bool, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
556 py.test.raises(TypeError, wikiutil.get_bool, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
557
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
558 # 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
559 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
560 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
561 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
562 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
563
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
564 def testGetInt(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
565 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
566 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
567 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
568 (None, None, -23, -23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
569 (None, None, 42, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
570
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
571 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
572 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
573 (u'42', None, None, 42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
574 (u'-23', None, None, -23),
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 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
577 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
578
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
579 def testGetIntRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
580 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
581 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
582
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
583 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
584 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
585 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
586 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
587 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
588 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
589 py.test.raises(TypeError, wikiutil.get_int, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
590 py.test.raises(TypeError, wikiutil.get_int, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
591
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
592 # 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
593 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
594 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
595 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
596 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
597
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
598 def testGetFloat(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
599 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
600 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
601 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
602 (None, None, -23.42, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
603 (None, None, 42.23, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
604
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
605 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
606 (u'0', None, None, 0),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
607 (u'42.23', None, None, 42.23),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
608 (u'-23.42', None, None, -23.42),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
609 (u'-23.42E3', None, None, -23.42E3),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
610 (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
611 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
612 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
613 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
614
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
615 def testGetFloatRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
616 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
617 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
618
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
619 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
620 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
621 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
622 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
623 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
624 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
625 py.test.raises(TypeError, wikiutil.get_float, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
626 py.test.raises(TypeError, wikiutil.get_float, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
627
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
628 # 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
629 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
630 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
631 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
632
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
633 def testGetComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
634 tests = [
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
635 # default testing for None value
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
636 (None, None, None, None),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
637 (None, None, -23.42, -23.42),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
638 (None, None, 42.23, 42.23),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
639
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
640 # some real values
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
641 (u'0', None, None, 0),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
642 (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
643 (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
644 (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
645 (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
646 (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
647 (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
648 (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
649 (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
650 (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
651 (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
652 (u'-3', None, None, -3L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
653 (u'-300000000000000000000', None, None, -300000000000000000000L),
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
654 ]
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
655 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
656 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
657
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
658 def testGetComplexRaising(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
659 # wrong default type
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
660 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
661
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
662 # 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
663 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
664 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
665 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
666 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
667 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
668 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
669 py.test.raises(TypeError, wikiutil.get_complex, self.request, [])
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
670 py.test.raises(TypeError, wikiutil.get_complex, self.request, {})
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
671
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
672 # 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
673 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
674 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
675 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
676 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
677 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
678 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
679
2512
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
680 def testGetUnicode(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
681 tests = [
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
682 # default testing for None value
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
683 (None, None, None, None),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
684 (None, None, u'', u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
685 (None, None, u'abc', u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
686
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
687 # some real values
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
688 (u'', None, None, u''),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
689 (u'abc', None, None, u'abc'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
690 (u'"abc"', None, None, u'"abc"'),
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
691 ]
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
692 for arg, name, default, expected in tests:
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
693 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
694
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
695 def testGetUnicodeRaising(self):
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
696 # wrong default type
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
697 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
698
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
699 # anything except None or unicode raises TypeError
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
700 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
701 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
702 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
703 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
704 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
705 py.test.raises(TypeError, wikiutil.get_unicode, self.request, [])
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
706 py.test.raises(TypeError, wikiutil.get_unicode, self.request, {})
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
707
68496057ee03 wikiutil.get_* tests + fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2510
diff changeset
708
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
709 class TestExtensionInvoking:
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
710 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
711 assert b is False
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
712
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
713 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
714 assert b == v
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
715 assert isinstance(b, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
716 assert isinstance(v, bool)
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
717
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
718 def _test_invoke_int_None(self, i=int):
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
719 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
720
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
721 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
722 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
723
2548
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
724 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
725 assert i == 1.4
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
726
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
727 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
728 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
729 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
730
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
731 def _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
732 assert a == 7
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
733 assert choice == u'a'
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
734
3371
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
735 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
736 assert i == u'a'
8ac95a64f1a8 really make required_arg take choices (including test)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 3259
diff changeset
737
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
738 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
739 assert _trailing_args == [u'a']
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
740
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
741 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
742 assert _kwargs == expect
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
743
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
744 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
745 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
746 assert i == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
747
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
748 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
749 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
750 assert b == 8
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
751 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
752
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
753 ief = wikiutil.invoke_extension_function
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
754 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
755 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
756 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
757 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
758 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
759 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
760 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
761 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
762 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
763 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
764 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
765 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
766 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
767 self._test_invoke_int_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
768 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
769 self._test_invoke_int_None, u'i=""')
2546
56dbfbde79fe better error checking in parameter parser, no more TypeError
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2544
diff changeset
770 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
771 _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
772 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
773 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
774 _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
775 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
776
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
777 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
778 ief(self.request, choicefn, u'', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
779 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
780 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
781 ief(self.request, choicefn, u'choice="a"', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
782 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
783 choicefn, u'x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
784 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
785 choicefn, u'choice=x', [7])
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
786
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
787 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
788 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
789 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
790 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
791 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
792 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
793 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
794 self._test_invoke_float_None, u'""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
795 py.test.raises(ValueError, ief, self.request,
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
796 self._test_invoke_float_None, u'i=""')
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
797 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
798 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
799 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
800 [{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
801 ief(self.request, self._test_arbitrary_kw, u'test=x, "\xc3"=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
802 [{u'\xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
803 ief(self.request, self._test_arbitrary_kw, u'test=x, "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
804 [{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
805 ief(self.request, self._test_arbitrary_kw, u'test=x, 7 \xc3=test',
2547
c2ef5800253f consolidate extra keyword args handling, no more **kw/_non_ascii_kw but rather just _kwargs
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2546
diff changeset
806 [{u'7 \xc3': 'test', 'test': u'x'}])
2543
116ab80df98b tests for the extension function invoker
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2528
diff changeset
807 ief(self.request, self._test_arbitrary_kw, u'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
808 [{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
809 py.test.raises(ValueError, ief, self.request,
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
810 self._test_invoke_float_required, u'')
5db66a25f0ba introduce required_arg wrapper class
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2547
diff changeset
811 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
812 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
813 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
814 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
815 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
816 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
817 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
818 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
819
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
820 def testConstructors(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
821 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
822
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
823 # new style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
824 class TEST1(object):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
825 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
826 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
827 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
828
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
829 class TEST2(TEST1):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
830 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
831
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
832 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
833 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
834 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
835 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
836
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
837 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
838 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
839 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
840 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
841 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
842
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
843 # old style class
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
844 class TEST3:
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
845 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
846 self.constructed = True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
847 assert a == 7
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
848
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
849 class TEST4(TEST3):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
850 pass
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
851
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
852 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
853 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
854 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
855 py.test.raises(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
856
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
857 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
858 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
859 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
860 assert obj.constructed
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
861 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
862
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
863 def testFailing(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
864 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
865
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
866 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
867 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
868 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
869
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
870 def testAllDefault(self):
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
871 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
872
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
873 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
874 assert a == 1
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
875 assert b == 2
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
876 assert c == 3
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
877 assert d == 4
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
878 return True
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
879
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
880 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
881 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
882 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
883 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
884 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
885 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
886 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
887 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
888 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
889
2558
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
890 def testInvokeComplex(self):
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
891 ief = wikiutil.invoke_extension_function
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
892
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
893 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
894 assert a == b
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
895 return True
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
896
fb05ca2c0bdc allow using complex datatype in macros
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2557
diff changeset
897 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
898 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
899 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
900 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
901 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
902 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
903
2557
cc5a81bda460 allow the invoke_extension_function to invoke constructors too
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2551
diff changeset
904
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
905 class TestAnchorNames:
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
906 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
907 tests = [
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
908 # text expected output
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
909 (u'\xf6\xf6ll\xdf\xdf', 'A.2BAPYA9g-ll.2BAN8A3w-'),
4555
30ffb215bf6e allow underscore in IDs, replace blanks by underscore (revert changeset a7dc3cc36362)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3815
diff changeset
910 (u'level 2', 'level_2'),
30ffb215bf6e allow underscore in IDs, replace blanks by underscore (revert changeset a7dc3cc36362)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3815
diff changeset
911 (u'level_2', 'level_2'),
2568
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
912 (u'', 'A'),
80eac6fc152a make anchor names always start with a letter
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2567
diff changeset
913 (u'123', 'A123'),
4559
1f5b1e0423fb id generation: do not quote colon as it is valid in IDs, add test for identity transformation of valid IDs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4555
diff changeset
914 # make sure that a valid anchor is not modified:
1f5b1e0423fb id generation: do not quote colon as it is valid in IDs, add test for identity transformation of valid IDs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4555
diff changeset
915 (u'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_.-',
1f5b1e0423fb id generation: do not quote colon as it is valid in IDs, add test for identity transformation of valid IDs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4555
diff changeset
916 u'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:_.-')
2567
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
917 ]
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
918 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
919 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
920
b403a24f7c8f (xorAxAx, johill) make saner looking anchors, no more sha hash
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2558
diff changeset
921 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
922 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
923 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
924
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
925 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
926 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
927 tests = [
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
928 # 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
929 (('SomePage', ), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
930 (('Somepage', ), '[[Somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
931 (('somepage', ), '[[somepage]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
932 (('Some Page', ), '[[Some Page]]'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
933 # with link text
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
934 (('SomePage', 'SomePage'), 'SomePage'),
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
935 (('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
936 (('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
937 (('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
938 ]
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
939 for params, expected in tests:
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
940 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
941
2773
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
942 def _check(self, params, expected):
2bbf611f4f2c add link text parameter to pagelinkmarkup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2771
diff changeset
943 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
944
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
945 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
946 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
947 # 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
948 # 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
949 (('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
950 (('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
951 (('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
952 (('', '/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
953 # 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
954 (('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
955 (('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
956 (('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
957 (('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
958 ]
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
959 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
960 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
961 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
962
2705
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
963 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
964 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
965
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
966 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
967 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
968 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
969
4a4d84273ae1 new function RelPageName to calculate a relative pagename from 2 absolute pagenames
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2704
diff changeset
970 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
971 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
972
2704
c6b5c2d813b6 fix AbsPageName(), add tests for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2571
diff changeset
973
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
974 class TestNormalizePagename(object):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
975
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
976 def testPageInvalidChars(self):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
977 """ request: normalize pagename: remove invalid unicode chars
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
978
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
979 Assume the default setting
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
980 """
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
981 test = u'\u0000\u202a\u202b\u202c\u202d\u202e'
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
982 expected = u''
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
983 result = wikiutil.normalize_pagename(test, self.request.cfg)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
984 assert result == expected
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
985
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
986 def testNormalizeSlashes(self):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
987 """ request: normalize pagename: normalize slashes """
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
988 cases = (
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
989 (u'/////', u''),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
990 (u'/a', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
991 (u'a/', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
992 (u'a/////b/////c', u'a/b/c'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
993 (u'a b/////c d/////e f', u'a b/c d/e f'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
994 )
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
995 for test, expected in cases:
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
996 result = wikiutil.normalize_pagename(test, self.request.cfg)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
997 assert result == expected
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
998
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
999 def testNormalizeWhitespace(self):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1000 """ request: normalize pagename: normalize whitespace """
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1001 cases = (
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1002 (u' ', u''),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1003 (u' a', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1004 (u'a ', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1005 (u'a b c', u'a b c'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1006 (u'a b / c d / e f', u'a b/c d/e f'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1007 # All 30 unicode spaces
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1008 (config.chars_spaces, u''),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1009 )
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1010 for test, expected in cases:
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
1011 result = wikiutil.normalize_pagename(test, self.request.cfg)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1012 assert result == expected
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1013
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1014 def testUnderscoreTestCase(self):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1015 """ request: normalize pagename: underscore convert to spaces and normalized
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1016
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1017 Underscores should convert to spaces, then spaces should be
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1018 normalized, order is important!
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1019 """
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1020 cases = (
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1021 (u' ', u''),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1022 (u' a', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1023 (u'a ', u'a'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1024 (u'a b c', u'a b c'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1025 (u'a b / c d / e f', u'a b/c d/e f'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1026 )
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1027 for test, expected in cases:
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
1028 result = wikiutil.normalize_pagename(test, self.request.cfg)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1029 assert result == expected
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1030
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1031 class TestGroupPages(object):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1032
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1033 def testNormalizeGroupName(self):
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1034 """ request: normalize pagename: restrict groups to alpha numeric Unicode
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1035
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1036 Spaces should normalize after invalid chars removed!
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1037 """
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1038 cases = (
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1039 # current acl chars
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1040 (u'Name,:Group', u'NameGroup'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1041 # remove than normalize spaces
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1042 (u'Name ! @ # $ % ^ & * ( ) + Group', u'Name Group'),
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1043 )
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1044 for test, expected in cases:
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1045 # validate we are testing valid group names
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1046 if wikiutil.isGroupPage(test, self.request.cfg):
4199
04c37245e12d Fix tests: wikiutil.normalize_pagename (missing 2nd param, missing import)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4146
diff changeset
1047 result = wikiutil.normalize_pagename(test, self.request.cfg)
4146
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1048 assert result == expected
3b36f0cfc656 (Re)moved normalizePagename from Request into wikiutil library
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3573
diff changeset
1049
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2378
diff changeset
1050 coverage_modules = ['MoinMoin.wikiutil']