def test_gen_block_quote(self): """Tests a simple case for generating a block quote.""" doc = md.Document() doc.add_block_quote("one\ntwo\nthree") self.assertEqual("> one\n> two\n> three\n", doc.get_markdown_text()) doc = md.Document() doc.add_block_quote("one\ntwo\nthree", True) self.assertEqual("> one\ntwo\nthree\n", doc.get_markdown_text())
def test_amps_and_ange_encoding(self): """Create a text that represents the expected file.""" md_document = md_doc.Document() md_document.add_text("AT&T has an ampersand in their name.") md_document.add_section() md_document.add_text("AT&T is another way to write it.") md_document.add_section() md_document.add_text("This & that.") md_document.add_section() md_document.add_text("4 < 5.") md_document.add_section() md_document.add_text("6 > 5.") md_document.add_section() md_document.add_text("Here\'s a ") md_document.add_reference("1", "http://example.com/?foo=1&bar=2", "link") md_document.add_text(" with an ampersand in the URL.") md_document.add_section() md_document.add_text( "Here's a link with an ampersand in the link text: ") md_document.add_reference("2", "http://att.com/", "AT&T") md_document.add_section() md_document.add_text("Here's an inline ") md_document.add_link("/script?foo=1&bar=2", "link") md_document.add_section() md_document.add_text("Here's an inline ") md_document.add_link("</script?foo=1&bar=2>", "link") self.assertEqual(self.expected_output_text, md_document.get_markdown_text(True))
def test_strong_and_emphasis(self): """Tests of combination of attributes.""" expected_output_text = get_expected_markdown_text( "Strong and em together.text") md_doc = doc.Document() text = md.gen_bold("This is strong and em.") text = md.gen_italic(text) md_doc.add_text(text) md_doc.add_section() md_doc.add_text("So is ") text = md.gen_bold("this") text = md.gen_italic(text) md_doc.add_text(text) md_doc.add_text(" word.") md_doc.add_section() text = md.gen_bold("This is strong and em.", True) text = md.gen_italic(text, True) md_doc.add_text(text) md_doc.add_section() md_doc.add_text("So is ") text = md.gen_bold("this", True) text = md.gen_italic(text, True) md_doc.add_text(text) md_doc.add_text(" word.\n") self.assertEqual(expected_output_text, md_doc.get_markdown_text())
def test_document_generation(self): """Tests a simple case of the document based API.""" doc = md.Document() doc.add_heading("Test", 1, True) self.assertEqual("Test\n====\n", doc.get_markdown_text())
def test_html_comments(self): """Test the generation of HTML comments.""" expected_output_text = get_expected_markdown_text( "Inline HTML comments.text") md_doc = doc.Document() md_doc.add_text("Paragraph one.") md_doc.add_section() md_doc.add_html_comments("This is a simple comment") md_doc.add_section() md_doc.add_html_comments("\n\tThis is another comment.\n") md_doc.add_section() md_doc.add_text("Paragraph two.") md_doc.add_section() md_doc.add_html_comments("one comment block -- -- with two comments") md_doc.add_section() md_doc.add_text("The end.\n") self.assertEqual(expected_output_text, md_doc.get_markdown_text())
def test_gen_ordered_list(self): """Tests a simple case for generating a ordered list.""" doc = md.Document() doc.add_heading("Test", 1, True) doc.add_ordered_list(["one", "two", "three"]) self.assertEqual("Test\n====\n1. one\n2. two\n3. three\n", doc.get_markdown_text())
def test_gen_new_line(self): """Tests a simple case for generating a new line.""" doc = md.Document() doc.add_heading("Test", 1, True) doc.add_text("blabla") doc.add_new_line() self.assertEqual("Test\n====\nblabla \n", doc.get_markdown_text())
def test_list_in_block_quote(self): """Tests tidyness with list in block quote.""" expected_output_text = get_expected_markdown_text("Tidyness.text") text = "A list within a blockquote:" text += md.gen_section() text += md.gen_un_ordered_list(["asterisk 1", "asterisk 2", "asterisk 3"]) md_doc = doc.Document() md_doc.add_block_quote(text) self.assertEqual(expected_output_text, md_doc.get_markdown_text())
def test_nested_block_quotes(self): """Test for nested block quotes.""" expected_output_text = get_expected_markdown_text("Nested blockquotes.text") text = "foo" text += md.gen_section() text += md.gen_block_quote("bar") text += "\n" text += "foo" md_doc = doc.Document() md_doc.add_block_quote(text) self.assertEqual(expected_output_text, md_doc.get_markdown_text())
def test_lists_eneration(self): """Tests the generation of ordered and unordered lists.""" expected_output_text = get_expected_markdown_text( "Ordered and unordered lists.text") md_doc = doc.Document() md_doc.add_heading("Unordered", 2) md_doc.add_text("\n") md_doc.add_text("Asterisks tight:") md_doc.add_section() md_doc.add_un_ordered_list(["asterisk 1", "asterisk 2", "asterisk 3"]) md_doc.add_section() md_doc.add_text("* * *") md_doc.add_section() md_doc.add_text("Pluses tight:") md_doc.add_section() md_doc.add_un_ordered_list(["Plus 1", "Plus 2", "Plus 3"], '+') md_doc.add_section() md_doc.add_text("Minuses tight:") md_doc.add_section() md_doc.add_un_ordered_list(["Minus 1", "Minus 2", "Minus 3"], '-') md_doc.add_section() md_doc.add_heading("Ordered", 2) md_doc.add_text("\n") md_doc.add_text("Tight:") md_doc.add_section() md_doc.add_ordered_list(["One", "Two", "Three"]) md_doc.add_section() self.assertEqual(expected_output_text, md_doc.get_markdown_text())
def test_something(self): """Define a text and create a block quote from it.""" expected_output_text = get_expected_markdown_text("Blockquotes with code blocks.text") text = \ """Example: sub status { print "working"; } Or: sub status { return "working"; } """ md_document = doc.Document() md_document.add_block_quote(text) self.assertEqual(expected_output_text, md_document.get_markdown_text())
def test_readme_gen(self): """Tests the generation of the readme with the OOP API.""" md_document = md_doc.Document() md_document.add_heading("Markdown Generator for Python", alternative=True) md_document.add_heading("Status", 2, True) md_document.add_image_link( "https://travis-ci.org/LukasWoodtli/PyMarkdownGen.svg?branch=master", "Build Status", "Travis CI Build Status") md_document.add_section() md_document.add_heading("Objective", 2, True) md_document.add_text("This is a small Python library that helps generating ") md_document.add_link("http://en.wikipedia.org/wiki/Markdown", "Markdown") md_document.add_text(" documents.") md_document.add_section() md_document.add_heading("Examples", 2, True) md_document.add_heading("Text Attributes", 3) md_document.add_text("Text can be formatted with the attributes ") md_document.add_italic("italc") md_document.add_text(" and ") md_document.add_bold("bold") md_document.add_text(".\n") md_document.add_text("There is also ") md_document.add_monospace("monospace text") md_document.add_text(" or ") md_document.add_strikethrough("striketrough") md_document.add_text(".") md_document.add_section() md_document.add_heading("Features", 2, True) table_data = [["Feature", "Implemented", "Tested"], ["Headers", "✓", "✓"], ["Links", "✓", "✓"], ["References", "✓", "✓"], ["Images", "✓", "✓"], ["Tables", "✓", "✓"], ["Lists", "✓", "✓"], ["Nested Lists", "✗", "✗"], ["Blockquotes", "✓", "✓"], ["Emphasis", "✓", "✓"], ["Code and Syntax", "✗", "✗"]] md_document.add_table(table_data, ["<", "^", "^"]) md_document.add_section() md_document.add_heading("To Do's", 2, True) md_document.add_un_ordered_list(["Docstrings", "Document based API (OOP)", "Documentation (ReadTheDocs)", "More unit tests"]) md_document.add_section() md_document.add_heading("Further Notes", 2, True) md_document.add_text("...") self.assertEqual(self.expected_output_text, md_document.get_markdown_text(False)) # try to save to disc md_document.save_to_file(ACTUAL_OUTPUT_FILE) expected_output_file = dirname(realpath(__file__)) expected_output_file = join(expected_output_file, "expected_output") expected_output_file = join(expected_output_file, "expected_readme.text") self.assertTrue(filecmp.cmp(ACTUAL_OUTPUT_FILE, expected_output_file))