def test(self): comp = RenderComponent() renderer = Renderer() content = page.PageNodeBase(None) t = Translator(content, Reader(RecursiveLexer('foo')), renderer, []) comp.init(t) self.assertEqual(comp.renderer, renderer)
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)
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)
def testDefault(self): """ Test basic construction and errors. """ comp = TokenComponent() reader = Reader(RecursiveLexer('foo')) content = page.PageNodeBase(None) t = Translator(content, reader, Renderer(), []) comp.init(t) self.assertIsNone(comp.settings) self.assertIs(comp.reader, reader) self.assertEqual(comp.attributes, dict()) defaults = comp.defaultSettings() for key in ['id', 'class', 'style']: self.assertIn(key, defaults) self.assertIsInstance(defaults[key], tuple) self.assertEqual(len(defaults[key]), 2) self.assertEqual(defaults[key][0], u'') self.assertIsInstance(defaults[key][1], unicode)
def testExceptions(self): """ Test that exceptions are raised. """ comp = TokenComponent() reader = Reader(RecursiveLexer('foo')) content = page.PageNodeBase(None) t = Translator(content, reader, Renderer(), []) comp.init(t) with self.assertRaises(NotImplementedError): comp.createToken([], []) # Test defaultSettings return type check class TestToken(TokenComponent): @staticmethod def defaultSettings(): pass with self.assertRaises(exceptions.MooseDocsException) as e: TestToken() self.assertIn("must return a dict", e.exception.message)
def test(self): """ Test basic construction and errors. """ comp = Component() with self.assertRaises(exceptions.MooseDocsException) as e: comp.translator self.assertIn("The init() method of", e.exception.message) with self.assertRaises(exceptions.MooseDocsException) as e: comp.init(42) self.assertIn("The argument 'translator' must be of type", e.exception.message) content = page.PageNodeBase(None) t = Translator(content, Reader(RecursiveLexer('foo')), Renderer(), []) comp.init(t) with self.assertRaises(exceptions.MooseDocsException) as e: comp.init(t) self.assertIn("already been", e.exception.message) self.assertIs(comp.translator, t)