From 3c20d726cf94550a6cc2b4bc9059815b216aa1e9 Mon Sep 17 00:00:00 2001 From: Denis-Cosmin NUTIU Date: Thu, 1 Jun 2023 22:19:57 +0300 Subject: [PATCH] add tests for test_fix_html_tags_stripe_tag --- app/converter/regex_heuristics.py | 2 +- app/converter/wordpress_markdown.py | 2 +- .../converter/wordpress_markdown_test.py | 36 +++++++++++++++++++ config.yaml | 6 ++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/converter/regex_heuristics.py b/app/converter/regex_heuristics.py index 2d03e21..f47a352 100644 --- a/app/converter/regex_heuristics.py +++ b/app/converter/regex_heuristics.py @@ -1,5 +1,5 @@ def handle_regex_heuristics(line: str) -> str: """ - Manipulates a line without tags by using regex heuristics. + Manipulates a line by using regex heuristics. """ return line diff --git a/app/converter/wordpress_markdown.py b/app/converter/wordpress_markdown.py index 9eba560..c9c363c 100644 --- a/app/converter/wordpress_markdown.py +++ b/app/converter/wordpress_markdown.py @@ -82,7 +82,7 @@ class WordpressMarkdownConverter: if tags: fixed_tags = self.fix_html_tags(tags) if fixed_tags: - fixed_lines.extend(fixed_tags) + fixed_lines.append("".join(fixed_tags)) def convert_post_content(self, post_content: str) -> str: """ diff --git a/app/tests/converter/wordpress_markdown_test.py b/app/tests/converter/wordpress_markdown_test.py index 57c46ca..1a34a5e 100644 --- a/app/tests/converter/wordpress_markdown_test.py +++ b/app/tests/converter/wordpress_markdown_test.py @@ -15,6 +15,9 @@ from app.tests.utils import make_fake_configurator ], ) def test_header_rewrite_author(author_rewrite, input_header, expected_header): + """ + Test the header rewrite author functionality. + """ configurator = make_fake_configurator( "wordpress_markdown_converter", ConverterOptions( @@ -35,6 +38,9 @@ def test_header_rewrite_author(author_rewrite, input_header, expected_header): ], ) def test_header_fields_drop(header_fields_drop, input_header, expected_header): + """ + Test the header fields drop functionality. + """ configurator = make_fake_configurator( "wordpress_markdown_converter", ConverterOptions( @@ -63,6 +69,36 @@ def test_header_fields_drop(header_fields_drop, input_header, expected_header): ], ) def test_fix_html_tags_detect_youtube_links(input_lines, expected_lines): + """ + Ensure fix_html_tags detects youtube links. + """ + configurator = make_fake_configurator( + "wordpress_markdown_converter", + ConverterOptions(), + ) + converter = WordpressMarkdownConverter(configurator) + assert converter.fix_html_tags(input_lines) == expected_lines + + +@pytest.mark.parametrize( + "input_lines, expected_lines", + [ + ([], []), + ([""], ["\n"]), + (["

Test

"], ["Test"]), + (["

Test

", "

Test

"], ["Test", "Test"]), + (["

Test

"], ["Test"]), + (["

Test

"], ["Test"]), + ( + ["
preTest
"], + ["preTest"], + ), + ], +) +def test_fix_html_tags_stripe_tag(input_lines, expected_lines): + """ + Ensure fix_html_tags removes the tag and tested tags. + """ configurator = make_fake_configurator( "wordpress_markdown_converter", ConverterOptions(), diff --git a/config.yaml b/config.yaml index dd8be8b..0d468b5 100644 --- a/config.yaml +++ b/config.yaml @@ -1,6 +1,6 @@ logging_level: "INFO" -source_path: "/home/denis/PycharmProjects/jekyll-to-hugo/my_test_data/_posts" -output_path: "/home/denis/PycharmProjects/jekyll-to-hugo/my_test_data/quickstart/content/posts" +source_path: "/Users/dnutiu/PycharmProjects/jekyll-to-hugo/my_test_data/_posts" +output_path: "/Users/dnutiu/NucuLabsProjects/NucuLabsDevBlog/content/posts" converter: "wordpress_markdown_converter" converter_options: author_rewrite: "NucuLabs.dev" @@ -9,6 +9,8 @@ converter_options: target: "/" - source: "https://nuculabs.wordpress.com/" target: "https://nuculabs.dev/posts/" + - source: "https://twitter.com/metonymyqt" + target: "https://twitter.com/nuculabs" header_fields_drop: - restapi_import_id - original_post_id