From d3d3b80d3dd2dc615a9e9334fc1d333fddca84fc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 15 Dec 2023 16:41:27 +0100 Subject: [PATCH] Introduce `TestContent` to represent what to rewrite and what is expected. --- tests/test_html_rewriting.py | 109 ++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 40 deletions(-) diff --git a/tests/test_html_rewriting.py b/tests/test_html_rewriting.py index 830638df..f3777e85 100644 --- a/tests/test_html_rewriting.py +++ b/tests/test_html_rewriting.py @@ -1,15 +1,30 @@ import pytest from warc2zim.content_rewriting import HtmlRewriter from textwrap import dedent +from collections import namedtuple + + +class TestContent(namedtuple("TestContent", ["input", "expected", "article_url"])): + def __new__(cls, input, expected=None, article_url="kiwix.org"): + expected = expected or input + return super().__new__(cls, input, expected, article_url) @pytest.fixture( params=[ - "A simple string without url", - "

This is a sentence with a http://exemple.com/path link

", - 'A link we should not rewrite', - '

A url (relative) in a inline style

', - '', + TestContent("A simple string without url"), + TestContent( + "

This is a sentence with a http://exemple.com/path link

" + ), + TestContent( + 'A link we should not rewrite' + ), + TestContent( + '

A url (relative) in a inline style

' + ), + TestContent( + '' + ), ] ) def no_rewrite_content(request): @@ -18,22 +33,24 @@ def no_rewrite_content(request): def test_no_rewrite(no_rewrite_content): assert ( - HtmlRewriter("kiwix.org", "", "").rewrite(no_rewrite_content).content - == no_rewrite_content + HtmlRewriter(no_rewrite_content.article_url, "", "") + .rewrite(no_rewrite_content.input) + .content + == no_rewrite_content.expected ) @pytest.fixture( params=[ - ( + TestContent( "

A link in a inline style

", '

A link in a inline style

', ), - ( + TestContent( "

A link in a inline style

", '

A link in a inline style

', ), - ( + TestContent( "