Skip to content

Commit

Permalink
Increase test coverage for fpdf.py (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedShy authored May 23, 2022
1 parent f8b462c commit 8803666
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Binary file added test/break_or_add_page_draw_fill.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions test/errors/test_FPDF_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ def test_repeated_calls_to_output(tmp_path):
pdf = fpdf.FPDF()
assert_pdf_equal(pdf, HERE / "repeated_calls_to_output.pdf", tmp_path)
assert_pdf_equal(pdf, HERE / "repeated_calls_to_output.pdf", tmp_path)


def test_incorrent_number_of_pages_toc():
pdf = fpdf.FPDF()
pdf.add_page()
pdf.insert_toc_placeholder(lambda a, b: None, 10)
with pytest.raises(FPDFException):
pdf.close()
Binary file added test/fonts/Quicksand-Regular.otf
Binary file not shown.
8 changes: 8 additions & 0 deletions test/fonts/test_add_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ def test_render_en_dash(tmp_path): # issue-166
pdf.add_page()
pdf.cell(w=pdf.epw, txt="–") # U+2013
assert_pdf_equal(pdf, HERE / "render_en_dash.pdf", tmp_path)


def test_add_font_otf():
pdf = FPDF()
font_file_path = HERE / "Quicksand-Regular.otf"
with pytest.raises(RuntimeError) as error:
pdf.add_font("Quicksand", fname=font_file_path)
assert str(error.value) == "Postscript outlines are not supported"
25 changes: 25 additions & 0 deletions test/test_add_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fpdf
from test.conftest import assert_pdf_equal
from fpdf.drawing import DeviceGray


HERE = Path(__file__).resolve().parent
Expand Down Expand Up @@ -45,3 +46,27 @@ def test_break_or_add_page(tmp_path):
pdf.set_x(100)
pdf.multi_cell(50, 10, f"Text {i} - Page {pdf.page}", 1, "C")
assert_pdf_equal(pdf, HERE / "break_or_add_page.pdf", tmp_path)


def test_break_or_add_page_with_different_draw_and_fill_color(tmp_path):
class CustomHeader(fpdf.FPDF):
def header(self):
self.line_width = 0
self.draw_color = DeviceGray(0.2)
self.fill_color = DeviceGray(0.2)

pdf = CustomHeader()
pdf.set_auto_page_break(auto=True, margin=0)
pdf.draw_color = DeviceGray(0.5)
pdf.set_stretching(101)
pdf.add_page()
pdf.set_font("Helvetica", "", 16)
for i in range(1, 51):
pdf.set_x(10)
pdf.multi_cell(50, 10, f"Text {i} - Page {pdf.page}", 1, "C")
pdf.page = 1
pdf.set_xy(100, 10)
for i in range(51, 101):
pdf.set_x(100)
pdf.multi_cell(50, 10, f"Text {i} - Page {pdf.page}", 1, "C")
assert_pdf_equal(pdf, HERE / "break_or_add_page_draw_fill.pdf", tmp_path)

0 comments on commit 8803666

Please sign in to comment.