Mercurial > silorider
diff tests/test_format.py @ 27:c898b4df0f29
Use context for html stripping, with support for custom URL sizes
For instance in Twitter URLs are 23 characters long since they use their
own URL shortening service. Without taking this into account, post lengths
would not be calculated correctly.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 19 Apr 2023 12:46:58 -0700 |
parents | fb93d3fbff4e |
children | 9e4eb3f2754e |
line wrap: on
line diff
--- a/tests/test_format.py Sun May 22 21:31:36 2022 -0700 +++ b/tests/test_format.py Wed Apr 19 12:46:58 2023 -0700 @@ -1,5 +1,7 @@ import pytest -from silorider.format import format_entry, strip_html +from silorider.format import ( + format_entry, strip_html, HtmlStrippingContext, + URLMODE_INLINE, URLMODE_LAST, URLMODE_BOTTOM_LIST) test_url = 'https://example.org/article' @@ -34,7 +36,11 @@ "Something with one link here http://example.org/first and another there http://example.org/second...") # NOQA ]) def test_strip_html(text, expected): - actual = strip_html(text) + ctx = HtmlStrippingContext() + ctx.url_mode = URLMODE_INLINE + actual = strip_html(text, ctx) + print(actual) + print(expected) assert actual == expected @@ -42,12 +48,14 @@ ("<p>Something with <a href=\"http://example.org/blah\">a link</a>", "Something with a link\nhttp://example.org/blah"), ("<p>Something with a link <a href=\"http://example.org/blah\">http://example.org</a>", # NOQA - "Something with a link http://example.org/blah"), + "Something with a link\nhttp://example.org/blah"), ("<p>Something with <a href=\"http://example.org/first\">one link here</a> and <a href=\"http://example.org/second\">another there</a>...</p>", # NOQA "Something with one link here and another there...\nhttp://example.org/first\nhttp://example.org/second") # NOQA ]) def test_strip_html_with_bottom_urls(text, expected): - actual = strip_html(text, inline_urls=False) + ctx = HtmlStrippingContext() + ctx.url_mode = URLMODE_BOTTOM_LIST + actual = strip_html(text, ctx) print(actual) print(expected) assert actual == expected