From 2cafc3c1bcf6ff98c6a56dfc3b931601d2743be1 Mon Sep 17 00:00:00 2001 From: tiosgz Date: Tue, 13 Feb 2024 17:18:05 +0000 Subject: [PATCH] tests: add test cases for abstract_delimiter One thing not entirely obvious from the changes is that tests/fixtures/docs/page_without_meta_early_delimiter.md together with test_simple_build_item_length_unlimited() checks the priority of abstract_chars_count: -1 versus abstract_delimiter. --- .../docs/page_without_meta_early_delimiter.md | 5 ++ .../fixtures/mkdocs_item_delimiter_empty.yml | 23 ++++++++ tests/test_build.py | 52 +++++++++++++++++-- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/docs/page_without_meta_early_delimiter.md create mode 100644 tests/fixtures/mkdocs_item_delimiter_empty.yml diff --git a/tests/fixtures/docs/page_without_meta_early_delimiter.md b/tests/fixtures/docs/page_without_meta_early_delimiter.md new file mode 100644 index 0000000..934c7bc --- /dev/null +++ b/tests/fixtures/docs/page_without_meta_early_delimiter.md @@ -0,0 +1,5 @@ +# Page without meta with early delimiter + + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. diff --git a/tests/fixtures/mkdocs_item_delimiter_empty.yml b/tests/fixtures/mkdocs_item_delimiter_empty.yml new file mode 100644 index 0000000..3d25ab6 --- /dev/null +++ b/tests/fixtures/mkdocs_item_delimiter_empty.yml @@ -0,0 +1,23 @@ +# Project information +site_name: MkDocs RSS Plugin - TEST +site_description: Basic setup to test against MkDocs RSS plugin +site_author: Julien Moura (Guts) +site_url: https://guts.github.io/mkdocs-rss-plugin +copyright: "Guts - In Geo Veritas" + +# Repository +repo_name: "guts/mkdocs-rss-plugin" +repo_url: "https://github.com/guts/mkdocs-rss-plugin" + +use_directory_urls: true + +plugins: + - rss: + abstract_delimiter: "" + +theme: + name: readthedocs + +# Extensions to enhance markdown +markdown_extensions: + - meta diff --git a/tests/test_build.py b/tests/test_build.py index d2a00a5..efbb970 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -403,9 +403,55 @@ def test_simple_build_item_length_unlimited(self): "Page without meta with short text", "Blog sample", ): - self.assertGreaterEqual( - len(feed_item.description), 150, feed_item.title - ) + self.assertGreater(len(feed_item.description), 150, feed_item.title) + + def test_simple_build_item_delimiter(self): + with tempfile.TemporaryDirectory() as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path("tests/fixtures/mkdocs_minimal.yml"), + output_path=tmpdirname, + strict=True, + ) + if cli_result.exception is not None: + e = cli_result.exception + logger.debug(format_exception(type(e), e, e.__traceback__)) + + self.assertEqual(cli_result.exit_code, 0) + self.assertIsNone(cli_result.exception) + + # created items + feed_parsed = feedparser.parse(Path(tmpdirname) / OUTPUT_RSS_FEED_CREATED) + self.assertEqual(feed_parsed.bozo, 0) + + for feed_item in feed_parsed.entries: + if feed_item.title in ("Page without meta with early delimiter",): + self.assertLess(len(feed_item.description), 50, feed_item.title) + + def test_simple_build_item_delimiter_empty(self): + with tempfile.TemporaryDirectory() as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path( + "tests/fixtures/mkdocs_item_delimiter_empty.yml" + ), + output_path=tmpdirname, + strict=True, + ) + if cli_result.exception is not None: + e = cli_result.exception + logger.debug(format_exception(type(e), e, e.__traceback__)) + + self.assertEqual(cli_result.exit_code, 0) + self.assertIsNone(cli_result.exception) + + # created items + feed_parsed = feedparser.parse(Path(tmpdirname) / OUTPUT_RSS_FEED_CREATED) + self.assertEqual(feed_parsed.bozo, 0) + + for feed_item in feed_parsed.entries: + if feed_item.title in ("Page without meta with early delimiter",): + self.assertGreater(len(feed_item.description), 150, feed_item.title) def test_simple_build_locale_with_territory(self): with tempfile.TemporaryDirectory() as tmpdirname: