Beispiel #1
0
 def testTokenizeException(self):
     root = tokens.Token(None)
     content = page.PageNodeBase(None)
     reader = readers.Reader(lexers.RecursiveLexer('foo'))
     translator = Translator(content, reader, HTMLRenderer(), [])
     translator.init('')
     reader.add('foo', WordComponent())
     reader.parse(root, u'throw bar')
     self.assertIsInstance(root(0), tokens.ExceptionToken)
     self.assertIsInstance(root(1), tokens.Word)
     self.assertEqual(root(1).content, u'bar')
Beispiel #2
0
 def testReinit(self):
     ast = tokens.Paragraph(None)
     comp = ParComponent()
     content = page.PageNodeBase(None)
     renderer = renderers.HTMLRenderer()
     translator = Translator(content, MarkdownReader(), renderer, [])
     translator.init('')
     renderer.add(tokens.Paragraph, comp)
     renderer.render(ast)
     renderer.render(ast)
     self.assertEqual(comp.count, 2)
Beispiel #3
0
    def testBasic(self):
        root = tokens.Token(None)
        content = page.PageNodeBase(None)
        reader = readers.Reader(lexers.RecursiveLexer('block', 'inline'))
        translator = Translator(content, reader, HTMLRenderer(), [])
        translator.init('')
        reader.add('block', BlockComponent())
        reader.add('inline', WordComponent())
        reader.parse(root, u'foo bar')

        self.assertIsInstance(root(0), tokens.Token)
        self.assertIsInstance(root(0)(0), tokens.Word)
        self.assertEqual(root(0)(0).content, u'foo')
        self.assertIsInstance(root(0)(1), tokens.Word)
        self.assertEqual(root(0)(1).content, u'bar')
Beispiel #4
0
    def testExtend(self):
        """
        Test the extend method.
        """
        class ExtTester(Extension):
            """Dummy extension for testing."""
            def __init__(self, *args, **kwargs):
                Extension.__init__(self, *args, **kwargs)
                self.called = False
            def extend(self, reader, renderer):
                self.called = True

        ext = ExtTester()
        self.assertFalse(ext.called)
        content = pages.Page('foo', source='foo')
        t = Translator([content], Reader(RecursiveLexer('foo')), Renderer(), [ext])
        t.init()
        self.assertTrue(ext.called)
Beispiel #5
0
    def testRender(self):
        ast = tokens.Paragraph(None)
        tokens.String(ast, content=u'foo')
        content = page.PageNodeBase(None)
        renderer = renderers.HTMLRenderer()
        translator = Translator(content, MarkdownReader(), renderer, [])
        translator.init('')

        renderer.add(tokens.Paragraph, ParComponent())
        renderer.add(tokens.String, StringComponent())

        root = renderer.render(ast)
        self.assertIsInstance(root, html.Tag)
        self.assertEqual(root.name, 'body')
        self.assertIsInstance(root(0), html.Tag)
        self.assertEqual(root(0).name, 'p')
        self.assertIsInstance(root(0)(0), html.String)
        self.assertEqual(root(0)(0).content, u'foo')
    def testExtend(self):
        """
        Test the extend method.
        """
        class ExtTester(Extension):
            """Dummy extension for testing."""
            def __init__(self, *args, **kwargs):
                Extension.__init__(self, *args, **kwargs)
                self.called = False
            def extend(self, reader, renderer):
                self.called = True

        ext = ExtTester()
        self.assertFalse(ext.called)
        content = page.PageNodeBase(None)
        t = Translator(content, Reader(RecursiveLexer('foo')), Renderer(), [ext])
        t.init('')
        self.assertTrue(ext.called)
        self.assertIs(ext.translator, t)
Beispiel #7
0
    def testExtend(self):
        """
        Test the extend method.
        """
        class ExtTester(Extension):
            """Dummy extension for testing."""
            def __init__(self, *args, **kwargs):
                Extension.__init__(self, *args, **kwargs)
                self.called = False
            def extend(self, reader, renderer):
                self.called = True

        ext = ExtTester()
        self.assertFalse(ext.called)
        content = page.PageNodeBase(None)
        t = Translator(content, Reader(RecursiveLexer('foo')), Renderer(), [ext])
        t.init('')
        self.assertTrue(ext.called)
        self.assertIs(ext.translator, t)