class TestRenderer(TestCase): def setUp(self): self.renderer = HTMLRenderer() self.renderer.render_inner = mock.Mock(return_value='inner') self.renderer.__enter__() self.addCleanup(self.renderer.__exit__, None, None, None) def _test_token(self, token_path, output, children=True, **kwargs): def mock_render(token_path): def inner(token): _, token_name = token_path.split('.') return self.renderer.render_map[token_name](token) return inner self.renderer.render = mock_render(token_path) path = 'mistletoe.{}'.format(token_path) MockToken = mock.Mock(path, name=token_path) if children: MockToken.return_value = mock.Mock(children=mock.MagicMock(), **kwargs) else: MockToken.return_value = mock.Mock(**kwargs) self.assertEqual(self.renderer.render(MockToken()), output)
class TestHTMLRendererFootnotes(TestCase): def setUp(self): self.renderer = HTMLRenderer() self.renderer.__enter__() self.addCleanup(self.renderer.__exit__, None, None, None) def test_footnote_image(self): from mistletoe import Document token = Document(['![alt] [foo]\n', '\n', '[foo]: bar "title"\n']) output = '<p><img src="bar" title="title" alt="alt">\n</p>\n' self.assertEqual(self.renderer.render(token), output) def test_footnote_link(self): from mistletoe import Document token = Document(['[name] [foo]\n', '\n', '[foo]: target\n']) output = '<p><a href="target">name</a>\n</p>\n' self.assertEqual(self.renderer.render(token), output)