예제 #1
0
    def test_heading(self):
        """tests for building Heading nodes"""
        tests = [
            ([tokens.HeadingStart(level=2), tokens.Text(text="foobar"),
              tokens.HeadingEnd()],
             wrap([Heading(wraptext("foobar"), 2)])),

            ([tokens.HeadingStart(level=4), tokens.Text(text="spam"),
              tokens.Text(text="eggs"), tokens.HeadingEnd()],
             wrap([Heading(wraptext("spam", "eggs"), 4)])),
        ]
        for test, valid in tests:
            self.assertWikicodeEqual(valid, self.builder.build(test))
예제 #2
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)