def test_undefined_variable(): db = DictDB(Art="{{Pipe}}", Pipe="{{{undefined_variable}}}") te = expander.Expander(db.normalize_and_get_page("Art", 0).rawtext, pagename="thispage", wikidb=db) res = te.expandTemplates() print "EXPANDED:", repr(res) assert u"{{{undefined_variable}}}" in res, "wrong expansion for undefined variable"
def test_alfred(): """I start to hate that Alfred_Gusenbauer""" db = DictDB( a="{{ibox2|birth_date=1960}}", ibox2="{{{birth{{#if:{{{birthdate|}}}||_}}date}}}" ) te = expander.Expander(db.normalize_and_get_page("a", 0).rawtext, pagename="thispage", wikidb=db) res = te.expandTemplates() print "EXPANDED:", repr(res) assert "1960" in res
def test_pipe_table(): db = DictDB(Foo=""" bla {{{ {{Pipe}}} blubb """, Pipe="|") te = expander.Expander(db.normalize_and_get_page("Foo", 0).rawtext, pagename="thispage", wikidb=db) res = te.expandTemplates() print "EXPANDED:", repr(res) assert "bla" in res assert "blubb" in res
def test_switch_default(): db = DictDB( Bonn="""{{Infobox |Bundesland = Nordrhein-Westfalen }} """, Infobox="""{{#switch: {{{Bundesland}}} | Bremen = [[Bremen (Land)|Bremen]] | #default = [[{{{Bundesland|Bayern}}}]] }} """) te = expander.Expander(db.normalize_and_get_page("Bonn", 0).rawtext, pagename="thispage", wikidb=db) res = te.expandTemplates() print "EXPANDED:", repr(res) assert "Nordrhein-Westfalen" in res
def test_1x_newline_and_spaces(): # see http://en.wikipedia.org/wiki/Help:Newlines_and_spaces#Spaces_and.2For_newlines_as_value_of_an_unnamed_parameter wikidb=DictDB() wikidb.d['1x'] = '{{{1}}}' def e(a,b): return expandstr(a,b,wikidb=wikidb) yield e, 'a{{#if:1|\n}}b', 'ab' yield e, 'a{{#if:1|b\n}}c', 'abc' yield e, 'a{{#if:1|\nb}}c', 'abc' yield e, 'a{{1x|\n}}b', 'a\nb' yield e, 'a{{1x|b\n}}c', 'ab\nc' yield e, 'a{{1x|\nb}}c', 'a\nbc' yield e, 'a{{1x|1=\n}}b', 'ab' yield e, 'a{{1x|1=b\n}}c', 'abc' yield e, 'a{{1x|1=\nb}}c', 'abc'
def test_implicit_newline_noinclude(): expandstr("foo {{tt}}", "foo \n{|", wikidb=DictDB(tt="<noinclude></noinclude>{|"))
def test_parser_func_from_template(): expandstr("{{ {{bla}} 1 + 1}}", "2", wikidb=DictDB(bla="#expr:"))
def test_five(): txt = "text of the tnext template" db = DictDB(t1="{{{{{1}}}}}", tnext=txt) expandstr("{{t1|tnext}}", expected=txt, wikidb=db)
def test_noinclude_end(): expandstr("{{foo}}", "foo", wikidb=DictDB(foo="foo<noinclude>bar should not be in expansion"))
def test_variable_alternative(): wikidb = DictDB(t1='{{{var|undefined}}}') expandstr('{{t1|var=}}', '', wikidb=wikidb)
def test_implicit_newline_ifeq(): expandstr("{{#ifeq: 1 | 1 | foo {{#if: 1 | {{{!}} }}}}", "foo \n{|", wikidb=DictDB({"!": "|"}))
def test_implicit_newline_colon(): expandstr("foo {{tt}}", "foo \n:", wikidb=DictDB(tt=":"))
def getdb(): return DictDB(**db)
def test_tag_expand_vs_uniq(): db = DictDB(Foo="""{{#tag:pre|inside pre}}""") r = uparser.parseString(title="Foo", wikidb=db) core.show(r) pre = r.find(parser.PreFormatted) assert len(pre) == 1, "expected a preformatted node"
def test_implicit_newline_includeonly(): expandstr("foo {{tt}}", "foo \n{|", wikidb=DictDB(tt="<includeonly>{|</includeonly>"))
def main(): db = DictDB(d4=d4) expandstr(d4, wikidb=db)
def test_implicit_newline_begintable(): expandstr("foo {{tt}}", "foo \n{|", wikidb=DictDB(tt="{|"))
def test_noexpansion_inside_pre(): res = expandstr("<pre>A{{Pipe}}B</pre>", "<pre>A{{Pipe}}B</pre>", wikidb=DictDB(Pipe="C")) print res
def test_implicit_newline_semicolon(): expandstr("foo {{tt}}", "foo \n;", wikidb=DictDB(tt=";"))
def test_named_variable_whitespace(): """http://code.pediapress.com/wiki/ticket/23""" expandstr("{{doit|notable roles=these are the notable roles}}", "these are the notable roles", wikidb=DictDB(doit="{{{notable roles}}}"))
def test_expand_after_named(): db = DictDB( show="{{{1}}}", a="a=bc") expandstr("{{show|{{a}}}}", "a=bc", wikidb=db)
def test_expand_parser_func_name(): expandstr("{{ {{NZ}}expr: 1+1}}", "2", wikidb=DictDB(NZ="#"))
def test_implicit_newline_after_expand(): wikidb = DictDB(tone='{{{1}}}{{{2}}}') expandstr('foo {{tone||:}} bar', 'foo \n: bar', wikidb=wikidb)
def test_expand_name_with_colon(): wikidb = DictDB() wikidb.d['bla:blubb'] = 'foo' expandstr("{{bla:blubb}}", "foo", wikidb=wikidb)
def test_monthnumber(): wikidb = DictDB(MONTHNUMBER="{{#if:{{{1|}}}|{{#switch:{{lc:{{{1}}}}}|january|jan=1|february|feb=2|march|mar=3|apr|april=4|may=5|june|jun=6|july|jul=7|august|aug=8|september|sep=9|october|oct=10|november|nov=11|december|dec=12|{{#ifexpr:{{{1}}}<0|{{#ifexpr:(({{{1}}})round 0)!=({{{1}}})|{{#expr:12-(((0.5-({{{1}}}))round 0)mod 12)}}|{{#expr:12-(((11.5-({{{1}}}))round 0)mod 12)}}}}|{{#expr:(((10.5+{{{1}}})round 0)mod 12)+1}}}}}}|Missing required parameter 1=''month''!}}") expandstr("{{MONTHNUMBER|12}}", "12", wikidb=wikidb)
def test_equal_inside_link(): db = DictDB(t1="{{{1}}}") expandstr("{{t1|[[abc|foo=5]]}}", "[[abc|foo=5]]", wikidb=db)