def test_presenter_notes(): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n") assert svars['presenter_notes'] == "<p>bar</p>" # Check that presenter notes work even if the slide has no heading. # For example, if it is only an image: g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n")
def test_add_user_assets(): base_dir = os.path.join(DATA_DIR, 'test.md') g = Generator(base_dir, logger=logtest) g.add_user_css(os.path.join(DATA_DIR, 'test.css')) g.add_user_js(os.path.join(DATA_DIR, 'test.js')) assert g.user_css[0]['contents'] == '* {color: red;}' assert g.user_js[0]['contents'] == "alert('foo');"
def test_get_slide_vars(): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_slide_vars("<h1>heading</h1>\n<p>foo</p>\n<p>bar</p>\n", '') assert svars['title'] == 'heading' assert svars['level'] == 1 assert svars['header'] == '<h1>heading</h1>' assert svars['content'] == '<p>foo</p>\n<p>bar</p>' assert svars['source'] == {} assert svars['classes'] == []
def test_weird_filename(): path = os.path.join(DATA_DIR, u'căcăneață.rst') g = Generator(path) content = g.render() # check that the string is utf_8 assert u'țară' in content g.execute() with codecs.open(g.destination_file, encoding='utf_8') as file_object: file_contents = file_object.read() # check that the file was properly encoded in utf_8 assert u'țară' in file_contents
def test_inputencoding(): path = os.path.join(DATA_DIR, 'encoding.rst') g = Generator(path, encoding='koi8_r') content = g.render() # check that the string is utf_8 assert u'русский' in content g.execute() with codecs.open(g.destination_file, encoding='utf_8') as file_object: file_contents = file_object.read() # check that the file was properly encoded in utf_8 assert u'русский' in file_contents
def test_process_macros(): g = Generator(os.path.join(DATA_DIR, 'test.md')) # Notes r = g.process_macros('<p>foo</p>\n<p>.notes: bar</p>\n<p>baz</p>', '', {}) assert r[0].find('<p class="notes">bar</p>') == 11 assert r[1] == [u'has_notes'] # FXs content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>' r = g.process_macros(content, '', {}) assert r[0] == '<p>foo</p>\n<p>baz</p>' assert r[1][0] == 'blah' assert r[1][1] == 'blob'
def test_register_macro(): g = Generator(os.path.join(DATA_DIR, 'test.md')) class SampleMacro(macro.Macro): pass g.register_macro(SampleMacro) assert any(isinstance(i, SampleMacro) for i in g.macros) def plop(foo): pass raises(TypeError, g.register_macro, plop)
def test_process_macros(): g = Generator(os.path.join(DATA_DIR, 'test.md')) # Notes ctx = {} r = g.process_macros('<p>foo</p>\n<p>.notes: bar</p>\n<p>baz</p>', '', ctx) assert r[0].find('bar') == -1 assert r[1] == [] assert ctx == {'presenter_notes': '<p>bar</p>'} # FXs content = '<p>foo</p>\n<p>.fx: blah blob</p>\n<p>baz</p>' r = g.process_macros(content, '', {}) assert r[0] == '<p>foo</p>\n<p>baz</p>' assert r[1][0] == 'blah' assert r[1][1] == 'blob'
def test_get_template_vars(): g = Generator(os.path.join(DATA_DIR, 'test.md')) svars = g.get_template_vars([ { 'title': "slide1", 'level': 1 }, { 'title': "slide2", 'level': 1 }, { 'title': None, 'level': 1 }, ]) assert svars['head_title'] == 'slide1'
def test_get_toc(): base_dir = os.path.join(DATA_DIR, 'test.md') g = Generator(base_dir, logger=logtest) g.add_toc_entry('Section 1', 1, 1) g.add_toc_entry('Section 1.1', 2, 2) g.add_toc_entry('Section 1.2', 2, 3) g.add_toc_entry('Section 2', 1, 4) g.add_toc_entry('Section 2.1', 2, 5) g.add_toc_entry('Section 3', 1, 6) toc = g.toc assert len(toc) == 3 assert toc[0]['title'] == 'Section 1' assert len(toc[0]['sub']) == 2 assert toc[0]['sub'][1]['title'] == 'Section 1.2' assert toc[1]['title'] == 'Section 2' assert len(toc[1]['sub']) == 1 assert toc[2]['title'] == 'Section 3' assert len(toc[2]['sub']) == 0
def test_unicode(): g = Generator(os.path.join(DATA_DIR, 'test.md')) g.execute() s = g.render() assert s.find('<pre>') != -1 assert len(re.findall('<pre><span', s)) == 3
def test_skip_presenter_notes(): g = Generator(os.path.join(DATA_DIR, 'test.md'), presenter_notes=False) svars = g.get_slide_vars( "<h1>heading</h1>\n<p>foo</p>\n" "<h1>Presenter Notes</h1>\n<p>bar</p>\n", '') assert svars['presenter_notes'] == None
def test_direct(): g = Generator(os.path.join(DATA_DIR, 'test.md'), direct=True) g.execute()