Example #1
0
 def test_integration2(self):
     """an even more audacious test for building a horrible wikicode mess"""
     # {{a|b|{{c|[[d]]{{{e}}}}}}}[[f|{{{g}}}<!--h-->]]{{i|j=&nbsp;}}
     test = [tokens.TemplateOpen(), tokens.Text(text="a"),
             tokens.TemplateParamSeparator(), tokens.Text(text="b"),
             tokens.TemplateParamSeparator(), tokens.TemplateOpen(),
             tokens.Text(text="c"), tokens.TemplateParamSeparator(),
             tokens.WikilinkOpen(), tokens.Text(text="d"),
             tokens.WikilinkClose(), tokens.ArgumentOpen(),
             tokens.Text(text="e"), tokens.ArgumentClose(),
             tokens.TemplateClose(), tokens.TemplateClose(),
             tokens.WikilinkOpen(), tokens.Text(text="f"),
             tokens.WikilinkSeparator(), tokens.ArgumentOpen(),
             tokens.Text(text="g"), tokens.ArgumentClose(),
             tokens.CommentStart(), tokens.Text(text="h"),
             tokens.CommentEnd(), tokens.WikilinkClose(),
             tokens.TemplateOpen(), tokens.Text(text="i"),
             tokens.TemplateParamSeparator(), tokens.Text(text="j"),
             tokens.TemplateParamEquals(), tokens.HTMLEntityStart(),
             tokens.Text(text="nbsp"), tokens.HTMLEntityEnd(),
             tokens.TemplateClose()]
     valid = wrap(
         [Template(wraptext("a"), params=[Parameter(wraptext("1"), wraptext(
         "b"), showkey=False), Parameter(wraptext("2"), wrap([Template(
         wraptext("c"), params=[Parameter(wraptext("1"), wrap([Wikilink(
         wraptext("d")), Argument(wraptext("e"))]), showkey=False)])]),
         showkey=False)]), Wikilink(wraptext("f"), wrap([Argument(wraptext(
         "g")), Comment("h")])), Template(wraptext("i"), params=[
         Parameter(wraptext("j"), wrap([HTMLEntity("nbsp",
         named=True)]))])])
     self.assertWikicodeEqual(valid, self.builder.build(test))
Example #2
0
 def test_params(self):
     """test getter for the params attribute"""
     node1 = Template(wraptext("foobar"))
     plist = [pgenh("1", "bar"), pgens("abc", "def")]
     node2 = Template(wraptext("foo"), plist)
     self.assertEqual([], node1.params)
     self.assertIs(plist, node2.params)
Example #3
0
 def test_unicode(self):
     """test Template.__unicode__()"""
     node = Template(wraptext("foobar"))
     self.assertEqual("{{foobar}}", str(node))
     node2 = Template(wraptext("foo"),
                      [pgenh("1", "bar"), pgens("abc", "def")])
     self.assertEqual("{{foo|bar|abc=def}}", str(node2))
Example #4
0
 def test_strip(self):
     """test Template.__strip__()"""
     node1 = Template(wraptext("foobar"))
     node2 = Template(wraptext("foo"),
                      [pgenh("1", "bar"), pgens("abc", "def")])
     for a in (True, False):
         for b in (True, False):
             self.assertEqual(None, node1.__strip__(a, b))
             self.assertEqual(None, node2.__strip__(a, b))
Example #5
0
 def test_name(self):
     """test getter/setter for the name attribute"""
     name = wraptext("foobar")
     node1 = Template(name)
     node2 = Template(name, [pgenh("1", "bar")])
     self.assertIs(name, node1.name)
     self.assertIs(name, node2.name)
     node1.name = "asdf"
     node2.name = "téstïng"
     self.assertWikicodeEqual(wraptext("asdf"), node1.name)
     self.assertWikicodeEqual(wraptext("téstïng"), node2.name)
Example #6
0
 def test_nodes(self):
     """test getter/setter for the nodes attribute"""
     code = parse("Have a {{template}}")
     self.assertEqual(["Have a ", "{{template}}"], code.nodes)
     L1 = SmartList([Text("foobar"), Template(wraptext("abc"))])
     L2 = [Text("barfoo"), Template(wraptext("cba"))]
     L3 = "abc{{def}}"
     code.nodes = L1
     self.assertIs(L1, code.nodes)
     code.nodes = L2
     self.assertIs(L2, code.nodes)
     code.nodes = L3
     self.assertEqual(["abc", "{{def}}"], code.nodes)
     self.assertRaises(ValueError, setattr, code, "nodes", object)
Example #7
0
 def test_parse_anything_valid(self):
     """tests for valid input to utils.parse_anything()"""
     tests = [
         (wraptext("foobar"), wraptext("foobar")),
         (Template(wraptext("spam")), wrap([Template(wraptext("spam"))])),
         ("fóóbar", wraptext("fóóbar")),
         (b"foob\xc3\xa1r", wraptext("foobár")), (123, wraptext("123")),
         (True, wraptext("True")), (None, wrap([])),
         ([Text("foo"), Text("bar"),
           Text("baz")], wraptext("foo", "bar", "baz")),
         ([wraptext("foo"), Text("bar"), "baz", 123,
           456], wraptext("foo", "bar", "baz", "123", "456")),
         ([[[([[((("foo", ), ), )], "bar"], )]]], wraptext("foo", "bar"))
     ]
     for test, valid in tests:
         self.assertWikicodeEqual(valid, parse_anything(test))
Example #8
0
 def test_add(self):
     """test Tag.add()"""
     node = Tag(wraptext("ref"), wraptext("cite"))
     node.add("name", "value")
     node.add("name", "value", quotes=None)
     node.add("name", "value", quotes="'")
     node.add("name")
     node.add(1, False)
     node.add("style", "{{foobar}}")
     node.add("name", "value", '"', "\n", " ", "   ")
     attr1 = ' name="value"'
     attr2 = " name=value"
     attr3 = " name='value'"
     attr4 = " name"
     attr5 = ' 1="False"'
     attr6 = ' style="{{foobar}}"'
     attr7 = '\nname =   "value"'
     self.assertEqual(attr1, node.attributes[0])
     self.assertEqual(attr2, node.attributes[1])
     self.assertEqual(attr3, node.attributes[2])
     self.assertEqual(attr4, node.attributes[3])
     self.assertEqual(attr5, node.attributes[4])
     self.assertEqual(attr6, node.attributes[5])
     self.assertEqual(attr7, node.attributes[6])
     self.assertEqual(attr7, node.get("name"))
     self.assertWikicodeEqual(wrap([Template(wraptext("foobar"))]),
                              node.attributes[5].value)
     self.assertEqual(
         "".join(("<ref", attr1, attr2, attr3, attr4, attr5, attr6, attr7,
                  ">cite</ref>")), node)
     self.assertRaises(ValueError, node.add, "name", "foo", quotes="bar")
     self.assertRaises(ValueError, node.add, "name", "a bc d", quotes=None)
Example #9
0
def add_old_cfd(
    page: pywikibot.Page,
    cfd_page: CfdPage,
    action: str,
    result: str,
    summary: str,
) -> None:
    """Add {{Old CfD}} to the talk page."""
    date = cfd_page.title(with_section=False).rpartition('/')[2]
    if page.exists():
        wikicode = mwparserfromhell.parse(page.text, skip_style_tags=True)
        for tpl in wikicode.ifilter_templates():
            try:
                template = pywikibot.Page(page.site, str(tpl.name), ns=10)
                if template not in TPL['old cfd'] or not tpl.has(
                        'date', ignore_empty=True):
                    continue
            except pywikibot.InvalidTitle:
                continue
            if tpl.get('date').value.strip() == date:
                # Template already present.
                return
    old_cfd = Template('Old CfD')
    old_cfd.add('action', action)
    old_cfd.add('date', date)
    old_cfd.add('section', cfd_page.section())
    old_cfd.add('result', result)
    page.text = str(old_cfd) + '\n' + page.text
    page.save(summary=summary)
Example #10
0
 def test_name(self):
     """test getter/setter for the name attribute"""
     name = wraptext("id")
     node = Attribute(name, wraptext("bar"))
     self.assertIs(name, node.name)
     node.name = "{{id}}"
     self.assertWikicodeEqual(wrap([Template(wraptext("id"))]), node.name)
Example #11
0
 def test_add(self):
     """test Tag.add()"""
     node = Tag(wraptext("ref"), wraptext("cite"))
     node.add("name", "value")
     node.add("name", "value", quoted=False)
     node.add("name")
     node.add(1, False)
     node.add("style", "{{foobar}}")
     node.add("name", "value", True, "\n", " ", "   ")
     attr1 = ' name="value"'
     attr2 = " name=value"
     attr3 = " name"
     attr4 = ' 1="False"'
     attr5 = ' style="{{foobar}}"'
     attr6 = '\nname =   "value"'
     self.assertEqual(attr1, node.attributes[0])
     self.assertEqual(attr2, node.attributes[1])
     self.assertEqual(attr3, node.attributes[2])
     self.assertEqual(attr4, node.attributes[3])
     self.assertEqual(attr5, node.attributes[4])
     self.assertEqual(attr6, node.attributes[5])
     self.assertEqual(attr6, node.get("name"))
     self.assertWikicodeEqual(wrap([Template(wraptext("foobar"))]),
                              node.attributes[4].value)
     self.assertEqual(
         "".join(("<ref", attr1, attr2, attr3, attr4, attr5, attr6,
                  ">cite</ref>")), node)
Example #12
0
 def create_wikitext(self, vals):
     wikitext = ''
     empty_pages = []
     first_page = ''
     for ind, val in vals.items():
         t_name, = val[1]
         if t_name != self.template_name:
             raise ValueError(
                 f"Unexpected template name {t_name} instead of {self.template_name}"
             )
         t_params = val[1][t_name]
         t_params2 = {
             k: t_params[k]
             for k in t_params if k not in self.ignore_params
         }
         if t_params:
             if not first_page:
                 first_page = val[0]
             wikitext += f"* _INDEX_={ind}\n"
             wikitext += str(
                 Template(t_name,
                          params=[
                              Parameter(k, v) for k, v in t_params2.items()
                          ]))
             wikitext += '\n'
         else:
             empty_pages.append(
                 PageContent(title=val[0],
                             timestamp=datetime.utcnow(),
                             data={}))
     if wikitext:
         wikitext += f"* _INDEX_=END\n"
     return empty_pages, wikitext, first_page
Example #13
0
    def test_children(self):
        """test Template.__children__()"""
        node2p1 = Parameter(wraptext("1"), wraptext("bar"), showkey=False)
        node2p2 = Parameter(wraptext("abc"), wrap([Text("def"), Text("ghi")]),
                            showkey=True)
        node1 = Template(wraptext("foobar"))
        node2 = Template(wraptext("foo"), [node2p1, node2p2])

        gen1 = node1.__children__()
        gen2 = node2.__children__()
        self.assertEqual(node1.name, next(gen1))
        self.assertEqual(node2.name, next(gen2))
        self.assertEqual(node2.params[0].value, next(gen2))
        self.assertEqual(node2.params[1].name, next(gen2))
        self.assertEqual(node2.params[1].value, next(gen2))
        self.assertRaises(StopIteration, next, gen1)
        self.assertRaises(StopIteration, next, gen2)
def creditline_from_row(row):
    t = Template(parse('Credit line\n '))
    t.add("DUMMY ", " VALUE\n ") # to set the formatting
    t.add("Author", wikify(row['realname']))
    t.add("Other", Tag('i', wikify(row['title']), wiki_markup="''"))
    t.add("License", "CC-BY-SA-2.0")
    t.remove("DUMMY")
    return t
Example #15
0
 def test_integration(self):
     """a test for building a combination of templates together"""
     # {{{{{{{{foo}}bar|baz=biz}}buzz}}usr|{{bin}}}}
     test = [
         tokens.TemplateOpen(),
         tokens.TemplateOpen(),
         tokens.TemplateOpen(),
         tokens.TemplateOpen(),
         tokens.Text(text="foo"),
         tokens.TemplateClose(),
         tokens.Text(text="bar"),
         tokens.TemplateParamSeparator(),
         tokens.Text(text="baz"),
         tokens.TemplateParamEquals(),
         tokens.Text(text="biz"),
         tokens.TemplateClose(),
         tokens.Text(text="buzz"),
         tokens.TemplateClose(),
         tokens.Text(text="usr"),
         tokens.TemplateParamSeparator(),
         tokens.TemplateOpen(),
         tokens.Text(text="bin"),
         tokens.TemplateClose(),
         tokens.TemplateClose()
     ]
     valid = wrap([
         Template(wrap([
             Template(
                 wrap([
                     Template(wrap([Template(wraptext("foo")),
                                    Text("bar")]),
                              params=[
                                  Parameter(wraptext("baz"),
                                            wraptext("biz"))
                              ]),
                     Text("buzz")
                 ])),
             Text("usr")
         ]),
                  params=[
                      Parameter(wraptext("1"),
                                wrap([Template(wraptext("bin"))]),
                                showkey=False)
                  ])
     ])
     self.assertWikicodeEqual(valid, self.builder.build(test))
Example #16
0
 def test_showtree(self):
     """test Template.__showtree__()"""
     output = []
     getter, marker = object(), object()
     get = lambda code: output.append((getter, code))
     mark = lambda: output.append(marker)
     node1 = Template(wraptext("foobar"))
     node2 = Template(wraptext("foo"),
                      [pgenh("1", "bar"), pgens("abc", "def")])
     node1.__showtree__(output.append, get, mark)
     node2.__showtree__(output.append, get, mark)
     valid = [
         "{{", (getter, node1.name), "}}", "{{", (getter, node2.name),
         "    | ", marker, (getter, node2.params[0].name), "    = ", marker,
         (getter, node2.params[0].value), "    | ", marker,
         (getter, node2.params[1].name), "    = ", marker,
         (getter, node2.params[1].value), "}}"]
     self.assertEqual(valid, output)
 def test_value(self):
     """test getter/setter for the value attribute"""
     value = wraptext("foo")
     node = Attribute(wraptext("id"), value)
     self.assertIs(value, node.value)
     node.value = "{{bar}}"
     self.assertWikicodeEqual(wrap([Template(wraptext("bar"))]), node.value)
     node.value = None
     self.assertIs(None, node.value)
Example #18
0
 def test_closing_tag(self):
     """test getter/setter for the closing_tag attribute"""
     tag = wraptext("ref")
     node = Tag(tag, wraptext("foobar"))
     self.assertIs(tag, node.closing_tag)
     node.closing_tag = "ref {{ignore me}}"
     parsed = wrap([Text("ref "), Template(wraptext("ignore me"))])
     self.assertWikicodeEqual(parsed, node.closing_tag)
     self.assertEqual("<ref>foobar</ref {{ignore me}}>", node)
Example #19
0
 def test_contents(self):
     """test getter/setter for the contents attribute"""
     contents = wraptext("text")
     node = Tag(wraptext("ref"), contents)
     self.assertIs(contents, node.contents)
     node.contents = "text and a {{template}}"
     parsed = wrap([Text("text and a "), Template(wraptext("template"))])
     self.assertWikicodeEqual(parsed, node.contents)
     self.assertEqual("<ref>text and a {{template}}</ref>", node)
Example #20
0
 def test_get(self):
     """test Template.get()"""
     node1 = Template(wraptext("foobar"))
     node2p1 = pgenh("1", "bar")
     node2p2 = pgens("abc", "def")
     node2 = Template(wraptext("foo"), [node2p1, node2p2])
     node3p1 = pgens("b", "c")
     node3p2 = pgens("1", "d")
     node3 = Template(wraptext("foo"), [pgenh("1", "a"), node3p1, node3p2])
     node4p1 = pgens(" b", " ")
     node4 = Template(wraptext("foo"), [pgenh("1", "a"), node4p1])
     self.assertRaises(ValueError, node1.get, "foobar")
     self.assertIs(node2p1, node2.get(1))
     self.assertIs(node2p2, node2.get("abc"))
     self.assertRaises(ValueError, node2.get, "def")
     self.assertIs(node3p1, node3.get("b"))
     self.assertIs(node3p2, node3.get("1"))
     self.assertIs(node4p1, node4.get("b "))
Example #21
0
 def test_has(self):
     """test Template.has()"""
     node1 = Template(wraptext("foobar"))
     node2 = Template(wraptext("foo"),
                      [pgenh("1", "bar"), pgens("\nabc ", "def")])
     node3 = Template(wraptext("foo"),
                      [pgenh("1", "a"), pgens("b", "c"), pgens("1", "d")])
     node4 = Template(wraptext("foo"), [pgenh("1", "a"), pgens("b", " ")])
     self.assertFalse(node1.has("foobar", False))
     self.assertTrue(node2.has(1, False))
     self.assertTrue(node2.has("abc", False))
     self.assertFalse(node2.has("def", False))
     self.assertTrue(node3.has("1", False))
     self.assertTrue(node3.has(" b ", False))
     self.assertTrue(node4.has("b", False))
     self.assertTrue(node3.has("b", True))
     self.assertFalse(node4.has("b", True))
     self.assertFalse(node1.has_param("foobar", False))
     self.assertTrue(node2.has_param(1, False))
Example #22
0
    def test_strip(self):
        """test Template.__strip__()"""
        node1 = Template(wraptext("foobar"))
        node2 = Template(
            wraptext("foo"),
            [pgenh("1", "bar"),
             pgens("foo", ""),
             pgens("abc", "def")])
        node3 = Template(wraptext("foo"), [
            pgenh("1", "foo"),
            Parameter(wraptext("2"),
                      wrap([Template(wraptext("hello"))]),
                      showkey=False),
            pgenh("3", "bar")
        ])

        self.assertEqual(None, node1.__strip__(keep_template_params=False))
        self.assertEqual(None, node2.__strip__(keep_template_params=False))
        self.assertEqual("", node1.__strip__(keep_template_params=True))
        self.assertEqual("bar def", node2.__strip__(keep_template_params=True))
        self.assertEqual("foo bar", node3.__strip__(keep_template_params=True))
Example #23
0
 def test_parsing(self):
     """integration test for parsing overall"""
     text = "this is text; {{this|is=a|template={{with|[[links]]|in}}it}}"
     expected = wrap([
         Text("this is text; "),
         Template(wraptext("this"), [
             Parameter(wraptext("is"), wraptext("a")),
             Parameter(wraptext("template"), wrap([
                 Template(wraptext("with"), [
                     Parameter(wraptext("1"),
                               wrap([Wikilink(wraptext("links"))]),
                               showkey=False),
                     Parameter(wraptext("2"),
                               wraptext("in"), showkey=False)
                 ]),
                 Text("it")
             ]))
         ])
     ])
     actual = parser.Parser().parse(text)
     self.assertWikicodeEqual(expected, actual)
Example #24
0
def redirect_cat(cat: pywikibot.Category, target: pywikibot.Category,
                 summary: str) -> None:
    """
    Redirect a category to another category.

    @param cat: Category to redirect
    @param target: Category redirect target
    @param summary: Edit summary
    """
    tpl = Template('Category redirect')
    tpl.add('1', target.title(with_ns=False))
    cat.text = str(tpl)
    cat.save(summary=summary)
Example #25
0
def handle_template(tpl, code, namespace=None):
    if tpl.has('sprache'):
        if tpl.get('sprache').value.strip().lower() in ('englisch', 'english'):
            set_param_value(tpl, 'sprache', 'en')
        if tpl.get('sprache').value.strip().lower() in ('deutsch', 'german'):
            set_param_value(tpl, 'sprache', 'de')

    if tpl.has('wann'):
        if tpl.get('wann').value.strip() in ('Sommersemester', 'ss'):
            set_param_value(tpl, 'wann', 'SS')
        elif tpl.get('wann').value.strip() in ('Wintersemester', 'ws'):
            set_param_value(tpl, 'wann', 'WS')
        elif tpl.get('wann').value.strip() in ('Winter- und Sommersemester',
                                               'Sommer- und Wintersemester'):
            set_param_value(tpl, 'wann', 'beide')
    if tpl.has('tiss'):
        if tpl.get('tiss').value.strip() == '1234567890':
            tpl.remove('tiss')

    archived = False
    successor = None
    if tpl.has('veraltet'):
        archived = True
        tpl.remove('veraltet')
    if tpl.has('nachfolger'):
        archived = True
        successor = tpl.get('nachfolger').value.strip()
        tpl.remove('nachfolger')
    for t in code.ifilter_templates(
            matches=lambda t: t.name.matches('Veraltet')):
        archived = True
        code.remove(t)
    archivedFlag = code.filter_templates(
        matches=lambda t: t.name.matches('Archiv'))
    if archived and not archivedFlag:
        tpl = Template(Wikicode([Text('Archiv')]))
        if successor:
            tpl.add('nachfolger', successor)
        code.insert(0, tpl)
        code.insert(1, '\n\n')

    if tpl.has('zuordnungen'):
        rels = tpl.get('zuordnungen').value.filter_templates()
        for rel in rels:
            if rel.has('2'):
                rel.get('2').value = str(rel.get('2').value).replace('–', '-')
        rels.sort(key=lambda x: x.get('1'))
        tpl.get('zuordnungen').value = '\n' + '\n'.join(
            [' ' * 4 + str(r) for r in rels]) + '\n'

    return 'fixe LVA-Daten'
Example #26
0
    def __init__(self, site: EsportsClient, title: str, bestof=1):
        self.site = site
        self.event = self.site.target(title).strip()
        self.toornament = self.site.cargo_client.query_one_result(
            tables='Tournaments',
            where='OverviewPage="{}"'.format(self.event),
            fields='ScrapeLink')
        self.summary = "Edit made by web scraping!"
        self.parser = Parser(self.toornament)

        self.intro_template = Template(name="MatchSchedule/Start")
        self.intro_template.add('bestof', str(bestof))
        self.sandbox_page = self.site.client.pages[
            'User:RheingoldRiver/Toornament_Sandbox']
Example #27
0
 def treat_page(self) -> None:
     """Process one page."""
     self.check_disabled()
     try:
         errors = self.validate_svg()
     except (AssertionError, RequestException, RuntimeError):
         pywikibot.exception()
         return
     if errors:
         n_errors = len(errors)
         new_tpl = Template('Invalid SVG')
         new_tpl.add('1', n_errors)
         summary = 'W3C invalid SVG: {} error{}'.format(
             n_errors, 's' if n_errors > 1 else '')
     else:
         new_tpl = Template('Valid SVG')
         summary = 'W3C valid SVG'
     wikicode = mwparserfromhell.parse(self.current_page.text,
                                       skip_style_tags=True)
     for tpl in wikicode.ifilter_templates():
         try:
             template = pywikibot.Page(
                 self.site,
                 removeDisabledParts(str(tpl.name), site=self.site).strip(),
                 ns=10,
             )
             template.title()
         except pywikibot.InvalidTitle:
             continue
         if template in self.templates:
             wikicode.replace(tpl, new_tpl)
             break
     else:
         wikicode.insert(0, '\n')
         wikicode.insert(0, new_tpl)
     self.put_current(str(wikicode), summary=summary, minor=not errors)
Example #28
0
 def print(self):
     template = Template(name="MatchSchedule")
     self.add_field(template, 'date', self.timestamp.cet_date)
     self.add_field(template, 'time', self.timestamp.cet_time)
     self.add_field(template, 'timezone', 'CET')
     self.add_field(template, 'dst', self.timestamp.dst)
     self.add_field(template, 'stream', '  ')
     self.add_field(template, 'team1', self.team1)
     self.add_field(template, 'team2', self.team2)
     self.add_field(template, 'team1score', self.team1score)
     self.add_field(template, 'team2score', self.team2score)
     if self.is_forfeit:
         template.add('ff', self.forfeit)
     self.add_field(template, 'winner', self.winner)
     self.add_field(template, 'direct_link', self.url)
     self.add_field(template, 'page', self.page)
     self.add_field(template, 'n_in_page', self.index_in_page)
     return str(template)
Example #29
0
    def test_template(self):
        """tests for building Template nodes"""
        tests = [
            ([tokens.TemplateOpen(), tokens.Text(text="foobar"),
              tokens.TemplateClose()],
             wrap([Template(wraptext("foobar"))])),

            ([tokens.TemplateOpen(), tokens.Text(text="spam"),
              tokens.Text(text="eggs"), tokens.TemplateClose()],
             wrap([Template(wraptext("spam", "eggs"))])),

            ([tokens.TemplateOpen(), tokens.Text(text="foo"),
              tokens.TemplateParamSeparator(), tokens.Text(text="bar"),
              tokens.TemplateClose()],
             wrap([Template(wraptext("foo"), params=[
                 Parameter(wraptext("1"), wraptext("bar"), showkey=False)])])),

            ([tokens.TemplateOpen(), tokens.Text(text="foo"),
              tokens.TemplateParamSeparator(), tokens.Text(text="bar"),
              tokens.TemplateParamEquals(), tokens.Text(text="baz"),
              tokens.TemplateClose()],
             wrap([Template(wraptext("foo"), params=[
                 Parameter(wraptext("bar"), wraptext("baz"))])])),

            ([tokens.TemplateOpen(), tokens.TemplateParamSeparator(),
              tokens.TemplateParamSeparator(), tokens.TemplateParamEquals(),
              tokens.TemplateParamSeparator(), tokens.TemplateClose()],
             wrap([Template(wrap([]), params=[
                 Parameter(wraptext("1"), wrap([]), showkey=False),
                 Parameter(wrap([]), wrap([]), showkey=True),
                 Parameter(wraptext("2"), wrap([]), showkey=False)])])),

            ([tokens.TemplateOpen(), tokens.Text(text="foo"),
              tokens.TemplateParamSeparator(), tokens.Text(text="bar"),
              tokens.TemplateParamEquals(), tokens.Text(text="baz"),
              tokens.TemplateParamSeparator(), tokens.Text(text="biz"),
              tokens.TemplateParamSeparator(), tokens.Text(text="buzz"),
              tokens.TemplateParamSeparator(), tokens.Text(text="3"),
              tokens.TemplateParamEquals(), tokens.Text(text="buff"),
              tokens.TemplateParamSeparator(), tokens.Text(text="baff"),
              tokens.TemplateClose()],
             wrap([Template(wraptext("foo"), params=[
                 Parameter(wraptext("bar"), wraptext("baz")),
                 Parameter(wraptext("1"), wraptext("biz"), showkey=False),
                 Parameter(wraptext("2"), wraptext("buzz"), showkey=False),
                 Parameter(wraptext("3"), wraptext("buff")),
                 Parameter(wraptext("3"), wraptext("baff"),
                           showkey=False)])])),
        ]
        for test, valid in tests:
            self.assertWikicodeEqual(valid, self.builder.build(test))
Example #30
0
 def test_value(self):
     """test getter/setter for the value attribute"""
     value = wraptext("foo")
     node = Attribute(wraptext("id"), value)
     self.assertIs(value, node.value)
     node.value = "{{bar}}"
     self.assertWikicodeEqual(wrap([Template(wraptext("bar"))]), node.value)
     node.value = None
     self.assertIs(None, node.value)
     node2 = Attribute(wraptext("id"), wraptext("foo"), None)
     node2.value = "foo bar baz"
     self.assertWikicodeEqual(wraptext("foo bar baz"), node2.value)
     self.assertEqual('"', node2.quotes)
     node2.value = 'foo "bar" baz'
     self.assertWikicodeEqual(wraptext('foo "bar" baz'), node2.value)
     self.assertEqual("'", node2.quotes)
     node2.value = "foo 'bar' baz"
     self.assertWikicodeEqual(wraptext("foo 'bar' baz"), node2.value)
     self.assertEqual('"', node2.quotes)
     node2.value = "fo\"o 'bar' b\"az"
     self.assertWikicodeEqual(wraptext("fo\"o 'bar' b\"az"), node2.value)
     self.assertEqual('"', node2.quotes)