Skip to content

Commit

Permalink
Change tests: MkDocsPage.find() -> find_text()
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Franceschetti committed Oct 28, 2024
1 parent b906a36 commit 4fb7bf6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion test/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 14 additions & 14 deletions test/module/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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():
Expand Down
6 changes: 3 additions & 3 deletions test/opt_in/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand All @@ -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')
6 changes: 3 additions & 3 deletions test/register_macros/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")



Expand Down
2 changes: 1 addition & 1 deletion test/simple/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4fb7bf6

Please sign in to comment.