From 9ef3a6669bbc1c94855e868d439249f84e7c7591 Mon Sep 17 00:00:00 2001 From: crossdark Date: Tue, 15 Oct 2024 22:16:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20Test.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test.py | 79 --------------------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 Test.py diff --git a/Test.py b/Test.py deleted file mode 100644 index cd535ae..0000000 --- a/Test.py +++ /dev/null @@ -1,79 +0,0 @@ -import unittest -import markdown - - -def convert_markdown_to_html(markdown_text): - return markdown.markdown(markdown_text, extensions=['markdown.extensions.extra']) - - -class TestMarkdownToHtmlConversion(unittest.TestCase): - - def test_simple_conversion(self): - markdown_text = "# Hello, World!" - expected_html = "

Hello, World!

\n" - self.assert_conversion(markdown_text, expected_html) - - def test_paragraph_conversion(self): - markdown_text = "This is a paragraph." - expected_html = "

This is a paragraph.

\n" - self.assert_conversion(markdown_text, expected_html) - - def test_bold_and_italic_conversion(self): - markdown_text = "**Bold** and *Italic*" - expected_html = "

Bold and Italic

\n" - self.assert_conversion(markdown_text, expected_html) - - def test_list_conversion(self): - markdown_text = """ - - Item 1 - - Item 2 - - Item 3 - """ - expected_html = """ - \n - """ - self.assert_conversion(markdown_text, expected_html) - - def test_code_block_conversion(self): - markdown_text = """ - -```python\nprint('Hello, World!')\n -```" -expected_html = ''' -
print('Hello, World!')
-        
\n - """ # 注意:实际输出可能包含额外的空白或换行符,这取决于markdown库的处理方式 - self.assert_conversion(markdown_text, expected_html) - - -def test_link_conversion(self): - markdown_text = "[Google](https://www.google.com)" - expected_html = '

Google

\n' - self.assert_conversion(markdown_text, expected_html) - - -def test_image_conversion(self): - markdown_text = "![Alt Text](https://www.example.com/image.jpg)" - expected_html = '

Alt Text

\n' - self.assert_conversion(markdown_text, expected_html) - - -def test_blockquote_conversion(self): - markdown_text = "> This is a quote." - expected_html = '
\n

This is a quote.

\n
\n' - self.assert_conversion(markdown_text, expected_html) - - -def assert_conversion(self, markdown_text, expected_html): - converted_html = convert_markdown_to_html(markdown_text) - # 使用replace方法去除不必要的空白字符,以便更灵活地比较输出 - self.assertEqual(converted_html.replace('\n', '').replace('\r', ''), - expected_html.replace('\n', '').replace('\r', '')) - - -if __name__ == '__main__': - unittest.main()