Coverage for gws-app/gws/lib/htmlx/_test.py: 100%
45 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 22:59 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 22:59 +0200
1import pytest
2import gws
3import gws.test.util as u
4import gws.lib.htmlx as htmlx
5from pathlib import Path
8def test_render_to_pdf(tmp_path):
9 html_content = "<html><body><h1>Test PDF</h1></body></html>"
10 out_path = str(tmp_path / "output.pdf")
11 result = htmlx.render_to_pdf(html_content, out_path)
13 assert Path(out_path).exists(), "PDF file was not created"
14 assert result == out_path
17def test_render_to_pdf_with_page_size(tmp_path):
18 html_content = "<html><body><h1>Test PDF</h1></body></html>"
19 out_path = str(tmp_path / "output.pdf")
20 page_size = (100, 200, gws.Uom.mm)
21 result = htmlx.render_to_pdf(html_content, out_path, page_size=page_size)
23 assert Path(out_path).exists(), "PDF file was not created with custom size"
24 assert result == out_path
27def test_render_to_pdf_with_margin(tmp_path):
28 html_content = "<html><body><h1>Test PDF</h1></body></html>"
29 out_path = str(tmp_path / "output.pdf")
30 page_margin = (10, 10, 10, 10, gws.Uom.mm)
31 result = htmlx.render_to_pdf(html_content, out_path, page_margin=page_margin)
33 assert Path(out_path).exists(), "PDF file was not created with margins"
34 assert result == out_path
37def test_render_to_png(tmp_path):
38 html_content = "<html><body><h1>Test PNG</h1></body></html>"
39 out_path = str(tmp_path / "output.png")
40 result = htmlx.render_to_png(html_content, out_path)
42 assert Path(out_path).exists(), "PNG file was not created"
43 assert result == out_path
46def test_render_to_png_with_page_size(tmp_path):
47 html_content = "<html><body><h1>Test PNG</h1></body></html>"
48 out_path = str(tmp_path / "output.png")
49 page_size = (500, 500, gws.Uom.px)
50 result = htmlx.render_to_png(html_content, out_path, page_size=page_size)
52 assert Path(out_path).exists(), "PNG file was not created with custom size"
53 assert result == out_path
56def test_render_to_png_with_margin(tmp_path):
57 html_content = "<html><body><h1>Test PNG</h1></body></html>"
58 out_path = str(tmp_path / "output.png")
59 page_margin = [10, 10, 10, 10]
60 result = htmlx.render_to_png(html_content, out_path, page_margin=page_margin)
62 assert Path(out_path).exists(), "PNG file was not created with margins"
63 assert result == out_path