Пример #1
0
 def test_argument(self):
     """tests for building Argument nodes"""
     tests = [
         ([
             tokens.ArgumentOpen(),
             tokens.Text(text="foobar"),
             tokens.ArgumentClose()
         ], wrap([Argument(wraptext("foobar"))])),
         ([
             tokens.ArgumentOpen(),
             tokens.Text(text="spam"),
             tokens.Text(text="eggs"),
             tokens.ArgumentClose()
         ], wrap([Argument(wraptext("spam", "eggs"))])),
         ([
             tokens.ArgumentOpen(),
             tokens.Text(text="foo"),
             tokens.ArgumentSeparator(),
             tokens.Text(text="bar"),
             tokens.ArgumentClose()
         ], wrap([Argument(wraptext("foo"), wraptext("bar"))])),
         ([
             tokens.ArgumentOpen(),
             tokens.Text(text="foo"),
             tokens.Text(text="bar"),
             tokens.ArgumentSeparator(),
             tokens.Text(text="baz"),
             tokens.Text(text="biz"),
             tokens.ArgumentClose()
         ], wrap([Argument(wraptext("foo", "bar"), wraptext("baz",
                                                            "biz"))])),
     ]
     for test, valid in tests:
         self.assertWikicodeEqual(valid, self.builder.build(test))
Пример #2
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))
Пример #3
0
    def test_parser_errors(self):
        """test whether ParserError gets thrown for bad input"""
        missing_closes = [[
            tokens.TemplateOpen(),
            tokens.TemplateParamSeparator()
        ], [tokens.TemplateOpen()], [tokens.ArgumentOpen()],
                          [tokens.WikilinkOpen()], [tokens.ExternalLinkOpen()],
                          [tokens.HeadingStart()], [tokens.CommentStart()],
                          [tokens.TagOpenOpen(),
                           tokens.TagAttrStart()], [tokens.TagOpenOpen()]]

        func = self.assertRaisesRegex if py3k else self.assertRaisesRegexp
        msg = r"_handle_token\(\) got unexpected TemplateClose"
        func(ParserError, msg, self.builder.build, [tokens.TemplateClose()])
        for test in missing_closes:
            self.assertRaises(ParserError, self.builder.build, test)