From 4fb7bf6902d11163970f18ec4ddfeb7a51127657 Mon Sep 17 00:00:00 2001 From: Laurent Franceschetti Date: Mon, 28 Oct 2024 20:16:05 +0100 Subject: [PATCH] Change tests: MkDocsPage.find() -> find_text() --- test/fixture.py | 3 ++- test/module/test_site.py | 28 ++++++++++++++-------------- test/opt_in/test_site.py | 6 +++--- test/register_macros/test_doc.py | 6 +++--- test/simple/test_site.py | 2 +- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/test/fixture.py b/test/fixture.py index 42b355f..b95c6ac 100644 --- a/test/fixture.py +++ b/test/fixture.py @@ -18,7 +18,8 @@ class MacrosPage(MkDocsPage): def has_error(self:MkDocsPage): "Predicate: check whether the page has an error" - return self.find('Macro Rendering Error') + return self.find_text('Macro Rendering Error') + @property def is_rendered(self): "Accomodate earlier formulation" diff --git a/test/module/test_site.py b/test/module/test_site.py index f88ecf6..828c8e7 100644 --- a/test/module/test_site.py +++ b/test/module/test_site.py @@ -50,10 +50,10 @@ def test_pages(): assert 'announcement' in meta assert meta.user == 'Joe' - assert page.find(meta.user, header='Installed', header_level=4) - assert page.find(meta.announcement, header='Accessing meta') - assert page.find(meta.bottles.lemonade, header='Dot notation') - assert not page.find(meta.user * 2, header='Macro') # negative test + assert page.find_text(meta.user, header='Installed', header_level=4) + assert page.find_text(meta.announcement, header='Accessing meta') + assert page.find_text(meta.bottles.lemonade, header='Dot notation') + assert not page.find_text(meta.user * 2, header='Macro') # negative test assert 'bottles' not in project.config.extra assert 'bottles' not in project.variables @@ -66,27 +66,27 @@ def test_pages(): # check that both on_pre/post_page_macro() worked assert "Added Footer (Pre-macro)" in page.markdown, f"Not in {page.markdown}" - assert page.find(r'is \d{4}-\d{2}-\d{2}', header='Pre-macro') + assert page.find_text(r'is \d{4}-\d{2}-\d{2}', header='Pre-macro') assert "Added Footer (Post-macro)" in page.markdown assert find_after(page.plain_text, 'name of the page', 'home') - assert page.find('Home', header='Post-macro') + assert page.find_text('Home', header='Post-macro') # ---------------- # Environment page # ---------------- page = project.get_page('environment') # read a few things that are in the tables - assert page.find('unit_price = 50', header='General list') + assert page.find_text('unit_price = 50', header='General list') # there are two headers containing 'Macros': - assert page.find('say_hello', header='Macros$') + assert page.find_text('say_hello', header='Macros$') # test the `include_file()` method (used for the mkdocs.yaml file) HEADER = r"^mkdocs.*portion" - assert page.find('site_name:', header=HEADER) - assert page.find('name: material', header=HEADER) - assert not page.find('foobar 417', header=HEADER) # negative control + assert page.find_text('site_name:', header=HEADER) + assert page.find_text('name: material', header=HEADER) + assert not page.find_text('foobar 417', header=HEADER) # negative control # ---------------- # Literal page @@ -99,11 +99,11 @@ def test_pages(): # Latex is not interpreted: latex = re.escape(r"\begin{tabular}{|ccc|}") - assert page.find(latex, header='Offending Latex') + assert page.find_text(latex, header='Offending Latex') # Footer is processed (but not rendered) - assert page.find(r'now()', header='Pre-macro') - assert page.find('Not interpreted', header='Post-macro') + assert page.find_text(r'now()', header='Pre-macro') + assert page.find_text('Not interpreted', header='Post-macro') def test_strict(): diff --git a/test/opt_in/test_site.py b/test/opt_in/test_site.py index 3d5f10d..3a78550 100644 --- a/test/opt_in/test_site.py +++ b/test/opt_in/test_site.py @@ -30,12 +30,12 @@ def test_opt_in(): page = project.get_page('render_this_one') assert page.title == "Render (by name)" assert page.is_markdown_rendered() - assert page.find(page.meta.signal), f"Did not find signal '{page.meta.signal}'" + assert page.find_text(page.meta.signal), f"Did not find signal '{page.meta.signal}'" print([page.source.markdown for page in project.pages.values()]) page2 = project.get_page('rendered/noname') assert page2.file.src_uri == 'rendered/noname.md', f"is: {page2.file.src_uri}" - assert page2.find("0: Hello world") + assert page2.find_text("0: Hello world") assert page2.is_markdown_rendered() @@ -45,4 +45,4 @@ def test_opt_in(): exception_page = project.get_page('rendered/exception') assert exception_page.meta.render_macros == False assert not exception_page.is_markdown_rendered() - assert exception_page.find('macros_info') + assert exception_page.find_text('macros_info') diff --git a/test/register_macros/test_doc.py b/test/register_macros/test_doc.py index 9ec2c77..5e9b7de 100644 --- a/test/register_macros/test_doc.py +++ b/test/register_macros/test_doc.py @@ -46,15 +46,15 @@ def test_pages(): # variable value = MY_VARIABLES['x2'] print(f"Check if x2 ('{value}') is present") - assert page.find(value, header="Variables") + assert page.find_text(value, header="Variables") # macro print("Check macro: bar") - assert page.find(bar(2, 5), header="Macros") + assert page.find_text(bar(2, 5), header="Macros") # filter message = page.meta.message result = scramble(message) print(f"Check filter: scramble('{message}') --> '{result}'") - assert page.find(result, header="Filters") + assert page.find_text(result, header="Filters") diff --git a/test/simple/test_site.py b/test/simple/test_site.py index c4b9cf7..9d363dc 100644 --- a/test/simple/test_site.py +++ b/test/simple/test_site.py @@ -44,7 +44,7 @@ def test_pages(): page = project.get_page('second') assert 'foo' not in project.config.extra assert page.is_markdown_rendered() - assert page.find('Macro Rendering Error') + assert page.find_text('Macro Rendering Error') def test_strict(): "This project must fail"