コード例 #1
0
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)
コード例 #2
0
ファイル: test_parser.py プロジェクト: aarddict/mwlib
def test_parse_comment():
    ex = """foo
<!-- comment --->
bar"""
    expanded = expander.expandstr(ex)
    print "EXPANDED:", expanded
    assert "\n\n" not in expanded
コード例 #3
0
ファイル: test_parser.py プロジェクト: aarddict/mwlib
def test_comment_inside_nowiki():
    comment = 'this is a comment'
    s=expander.expandstr('<pre><!-- this is a comment --></pre>')
    assert comment in s
    r=parse(s)
    txt = r.asText()
    assert 'this is a comment' in txt
コード例 #4
0
ファイル: test_parser.py プロジェクト: hpschry/mwlib
def test_comment_inside_nowiki():
    comment = "this is a comment"
    s = expander.expandstr("<pre><!-- this is a comment --></pre>")
    assert comment in s
    r = parse(s)
    txt = r.asText()
    assert "this is a comment" in txt
コード例 #5
0
ファイル: test_parser.py プロジェクト: vprusa/mwlib
def test_parse_comment():
    ex = """foo
<!-- comment --->
bar"""
    expanded = expander.expandstr(ex)
    print "EXPANDED:", expanded
    assert "\n\n" not in expanded
コード例 #6
0
ファイル: test_parser.py プロジェクト: vprusa/mwlib
def test_comment_inside_nowiki():
    comment = 'this is a comment'
    s = expander.expandstr('<pre><!-- this is a comment --></pre>')
    assert comment in s
    r = parse(s)
    txt = r.asText()
    assert 'this is a comment' in txt
コード例 #7
0
ファイル: test_expr.py プロジェクト: vprusa/mwlib
def ee(s, expected=None):
    s = expandstr("{{#expr:%s}}" % (s, ))
    if isinstance(expected, (float, int, long)):
        assert math.fabs(float(s) - expected) < 1e-5
    elif expected is not None:
        assert s == expected, "expected %r, got %r" % (expected, s)

    return s
コード例 #8
0
ファイル: test_expr.py プロジェクト: hexmode/mwlib
def ee(s, expected=None):
    s = expandstr("{{#expr:%s}}" % (s,))
    if isinstance(expected, (float, int, long)):
        assert math.fabs(float(s) - expected) < 1e-5
    elif expected is not None:
        assert s == expected, "expected %r, got %r" % (expected, s)

    return s
コード例 #9
0
def test_parmpart():
    parmpart = """{{#ifeq:/{{{2|}}}
|{{#titleparts:/{{{2|}}}|1|{{#expr:1+{{{1|1}}}}}}}
|
|{{#titleparts:/{{{2|}}}|1|{{#expr:1+{{{1|1}}}}}}}
}}"""
    expandstr("{{ParmPart|0|a/b}}", "", wikidb=DictDB(ParmPart=parmpart))
    expandstr("{{ParmPart|1|a/b}}", "a", wikidb=DictDB(ParmPart=parmpart))
    expandstr("{{ParmPart|2|a/b}}", "b", wikidb=DictDB(ParmPart=parmpart))
    expandstr("{{ParmPart|3|a/b}}", "", wikidb=DictDB(ParmPart=parmpart))
コード例 #10
0
ファイル: primer.py プロジェクト: sdetwiler/primer
    def get_article(self, topic):
        global usejsoncache
        global threaded
        
        cacheDir = "./json_cache/{}".format(self.wiki_version)
        try:
            os.mkdir(cacheDir)
        except:
            pass
            
        filename = "{}/{}".format(cacheDir, topic)
        if usejsoncache is True and os.path.isfile(filename):
            print "cache hit for " + topic
            js = open(filename).read()
        else:
            markup = self.get_markup_for_topic(topic)

            templParser = mwlib.templ.parser.Parser(markup)
            templates = templParser.parse()
            print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
            markup = ""
            for t in templates:
                # print "==>{} {}<==".format(type(t), t)
                if isinstance(t, unicode):
                    markup+= t

                elif isinstance(t, mwlib.templ.nodes.Template):
                    print "==>{}<==".format(t[0])
                    if t[0] == "Wide image":
                        print "  -->{}<--".format(t[1][0])
                        markup+= " [[File:{}]] ".format(t[1][0])

            # print article
            print "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"

            markup = expandstr(markup)
            # print markup
            article = compat.parse_txt(markup)

            self.reset()
            if threaded:
                self.build_related_media(article)
            else:
                print "Not performing threaded processing"
            self.depth_first(article)
        
            obj = {"content":self.content, "title":topic, "url":"https://{}.wikipedia.org/wiki/{}".format(self.wiki_version, topic), "url":"https://{}.wikipedia.org/wiki/{}".format(self.wiki_version, topic)}
            js = json.dumps(obj, indent=2)
            
            open(filename, "w").write(js)
        return js
コード例 #11
0
def test_pipe_inside_imagemap():
    """pipes inside image maps should not separate template arguments
    well, they do not separate arguments with the version running on en.wikipedia.org.
    they do separate arguments with the version running on pediapress.com:8080.
    (which is hopefully a newer version)
    """

    db = DictDB(sp="""{{#ifeq: {{{1}}} | 1
| <imagemap>
 Image:Padlock-silver-medium.svg|20px
 rect 0 0 1000 1000 [[Wikipedia:Protection policy|This page has been semi-protected from editing]]
 desc none
 </imagemap>
|bla
}}
""")
    result = expandstr("{{sp|1}}", wikidb=db)
    assert "</imagemap>" in result
コード例 #12
0
def test_birth_date_and_age():
    db = DictDB({
        "birth date and age": '[[ {{{3|{{{day|{{{3}}}}}}}}}]] [[{{{1|{{{year|{{{1}}}}}}}}}]]<font class="noprint"> (age&nbsp;{{age | {{{1|{{{year|{{{1}}}}}}}}} | {{{2|{{{month|{{{2}}}}}}}}} | {{{3|{{{day|{{{3}}}}}}}}} }})</font>',

        "age": '<includeonly>{{#expr:({{{4|{{CURRENTYEAR}}}}})-({{{1}}})-(({{{5|{{CURRENTMONTH}}}}})<({{{2}}})or({{{5|{{CURRENTMONTH}}}}})=({{{2}}})and({{{6|{{CURRENTDAY}}}}})<({{{3}}}))}}</includeonly>',
    })
    res = expandstr('{{birth date and age|1960|02|8}}', wikidb=db)

    print "EXPANDED:", repr(res)
    import datetime
    now = datetime.datetime.now()
    b = datetime.datetime(1960, 2, 8)
    age = now.year - b.year
    if now.month * 32 + now.day < b.month * 32 + b.day:
        age -= 1

    expected = u"age&nbsp;%s" % age
    assert expected in res
コード例 #13
0
ファイル: test_expander.py プロジェクト: pediapress/mwlib
def test_pipe_inside_imagemap():
    """pipes inside image maps should not separate template arguments
    well, they do not separate arguments with the version running on en.wikipedia.org.
    they do separate arguments with the version running on pediapress.com:8080.
    (which is hopefully a newer version)
    """

    db = DictDB(
        sp="""{{#ifeq: {{{1}}} | 1
| <imagemap>
 Image:Padlock-silver-medium.svg|20px
 rect 0 0 1000 1000 [[Wikipedia:Protection policy|This page has been semi-protected from editing]]
 desc none
 </imagemap>
|bla
}}
""")
    result = expandstr("{{sp|1}}", wikidb=db)
    assert "</imagemap>" in result
コード例 #14
0
def test_noinclude_end():
    expandstr("{{foo}}", "foo", wikidb=DictDB(foo="foo<noinclude>bar should not be in expansion"))
コード例 #15
0
 def e(a, b):
     return expandstr(a, b, pagename=u'L\xe9onie s')
コード例 #16
0
def test_convert_ft_in_m_int():
    expandstr("{{convert|12|ft|m}}", "12&nbsp;feet (3.7&nbsp;m)\n", wikidb=getdb())
コード例 #17
0
def test_round_plus_2():
    expandstr("{{rnd/+|1.056|2|5}}", "5", wikidb=getdb())
コード例 #18
0
def test_precision_plus_1():
    expandstr("{{precision/+|0.77}}", "2", wikidb=getdb())
コード例 #19
0
def test_switch_numeric_comparison():
    expandstr("{{ #switch: +07 | 7 = Yes | 007 = Bond | No }}", "Yes")
コード例 #20
0
def test_round():
    expandstr("{{rnd|2.0004|3}}", "2.000", wikidb=getdb())
    expandstr("{{rnd|0.000020004|8}}", "2.0E-5000", wikidb=getdb())
    expandstr("{{rnd|0|8}}", "0.00000000", wikidb=getdb())
コード例 #21
0
 def expand_talk(tpl, expected):
     return expandstr('{{%s:%s}}' % (tpl, 'Benutzer Diskussion:Anonymous user!/sandbox/my page'),
                      expected, pagename='Help:Irrelevant')
コード例 #22
0
 def expand_page(tpl, expected):
     return expandstr('{{%s}}' % tpl, expected,
                      pagename='Benutzer:Anonymous user!/sandbox/my page')
コード例 #23
0
def test_equal_inside_link():
    db = DictDB(t1="{{{1}}}")
    expandstr("{{t1|[[abc|foo=5]]}}", "[[abc|foo=5]]", wikidb=db)
コード例 #24
0
def test_preserve_space_in_tag():
    expandstr("{{#tag:imagemap|cd }}", "<imagemap>cd </imagemap>")
コード例 #25
0
ファイル: test_expander.py プロジェクト: pediapress/mwlib
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)
コード例 #26
0
def test_switch_default_template():
    expandstr("{{#switch:1|{{#if:1|5|12}}}}", "5")
コード例 #27
0
def test_urlencode_non_ascii():
    expandstr(u'{{urlencode:L\xe9onie}}', 'L%C3%A9onie')
コード例 #28
0
def test_localurle_umlaut():
    """http://code.pediapress.com/wiki/ticket/473"""
    r = expandstr(u"{{LOCALURLE:F\xfcbar}}")
    assert r.endswith('/F%C3%BCbar')
コード例 #29
0
def test_anchorencode():
    """http://code.pediapress.com/wiki/ticket/213"""
    expandstr('{{anchorencode:x #y @}}', 'x_.23y_.40')
コード例 #30
0
def test_five():
    txt = "text of the tnext template"
    db = DictDB(
        t1="{{{{{1}}}}}",
        tnext=txt)
    expandstr("{{t1|tnext}}", expected=txt, wikidb=db)
コード例 #31
0
def test_anchorencode_non_ascii():
    expandstr(u"{{anchorencode:\u0107}}", ".C4.87")
コード例 #32
0
 def expand_talk(tpl, expected):
     return expandstr('{{%s}}' % tpl, expected,
                      pagename='Benutzer Diskussion:Anonymous user!/sandbox/my page')
コード例 #33
0
def test_fullurl():
    expandstr('{{fullurl:x y @}}', 'http://en.wikipedia.org/wiki/X_y_%40')
コード例 #34
0
def test_switch_empty_fallback():
    expandstr("{{#switch:||foo=good}}", "good")
コード例 #35
0
def test_fullurl_nonascii():
    expandstr(u'{{fullurl:L\xe9onie}}', 'http://en.wikipedia.org/wiki/L%C3%A9onie')
コード例 #36
0
def test_switch_case_sensitive2():
    expandstr("{{ #switch: A | a=lower | UPPER }}", "UPPER")
コード例 #37
0
def test_server():
    expandstr('{{server}}', 'http://en.wikipedia.org')
コード例 #38
0
def test_max_2():
    expandstr("{{max/2|-1|1}}", "1", wikidb=getdb())
    expandstr("{{max/2|1|-1}}", "1", wikidb=getdb())
コード例 #39
0
def test_servername():
    expandstr('{{servername}}', 'en.wikipedia.org')
コード例 #40
0
def test_round_plus_3():
    expandstr("{{rnd/+|1.056|2|abc}}", "1.06", wikidb=getdb())
コード例 #41
0
 def e(a, b):
     return expandstr(a, b, wikidb=wikidb)
コード例 #42
0
def test_convert_ft_in_m_float():
    expandstr("{{convert|2.5|ft|m}}", "2.5&nbsp;feet (0.76&nbsp;m)\n", wikidb=getdb())
コード例 #43
0
def test_variable_alternative():
    wikidb = DictDB(t1='{{{var|undefined}}}')
    expandstr('{{t1|var=}}', '', wikidb=wikidb)
コード例 #44
0
def test_round_minus():
    expandstr("{{rnd/-|0.00002|8}}", "2.0E-5000", wikidb=getdb())
コード例 #45
0
def test_implicit_newline_after_expand():
    wikidb = DictDB(tone='{{{1}}}{{{2}}}')
    expandstr('foo {{tone||:}} bar', 'foo \n: bar', wikidb=wikidb)