Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💬 test for text formatting #143

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/mock_html/large.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<p style="font-size: 31px">Large</p>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/mock_html/medium.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<p style="font-size: 30px">Medium</p>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/mock_html/small.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<p style="font-size: 12px">Small</p>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/mock_html/x_large.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<p style="font-size: 60px">XLarge</p>
</body>
</html>
10 changes: 10 additions & 0 deletions tests/mock_html/xx_large.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<p style="font-size: 72px">XXLarge</p>
</body>
</html>
28 changes: 28 additions & 0 deletions tests/test_text_formatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import pytest


@pytest.mark.asyncio
@pytest.mark.parametrize(
"html_file, expected_text_content",
[
("small.html", ["Small"]),
("medium.html", ["Medium"]),
("large.html", ["**Large**"]),
("x_large.html", ["**XLarge**"]),
("xx_large.html", ["**XXLarge**"]),
],
)
async def test_font_formatting(tarsier, async_page, html_file, expected_text_content):
font_formatting_html_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), f"mock_html/{html_file}")
)
await async_page.goto(f"file://{font_formatting_html_path}")
page_text, tag_to_xpath = await tarsier.page_to_text(
async_page, tagless=True, tag_text_elements=True
)

for expected_line in expected_text_content:
assert (
expected_line in page_text
), f"Expected text '{expected_line}' not found in the page content of {html_file}."