-
Notifications
You must be signed in to change notification settings - Fork 252
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
Added Cell level control for Table Borders #1285
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import gzip | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from fpdf import FPDF, FPDFException | ||
|
@@ -362,3 +361,239 @@ def test_cell_speed_with_long_text(): # issue #907 | |
assert len(LONG_TEXT_LINES) == 26862 | ||
for line in LONG_TEXT_LINES: | ||
pdf.cell(0, 3, line, new_x="LMARGIN", new_y="NEXT") | ||
|
||
|
||
def test_cell_border_none(tmp_path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you regroup all or most of those tests in a single one, with one case per page, in order to limit the number of reference PDF files, please? All the right/left/top/bottom cases could form a single unit test I think.
|
||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="None") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_none.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
for datum in data_row: | ||
row.cell(datum, border="left") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_right(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="right") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_right.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_top(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="top") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_top.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="bottom") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_all(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="all") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_all.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_inherit(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border="inherit") | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_inherit.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_right(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=3) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_right.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_top(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=5) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_top.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=9) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_right_top(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=6) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_right_top.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_right_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=10) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_right_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_right_top(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=7) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_right_top.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_right_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=11) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_right_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_left_top_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=13) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_left_top_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_right_top_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=13) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_right_top_bottom.pdf", tmp_path) | ||
|
||
|
||
def test_cell_border_top_bottom(tmp_path): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
pdf.set_font("Times", size=16) | ||
with pdf.table(gutter_height=3, gutter_width=3) as table: | ||
for data_row in TABLE_DATA: | ||
row = table.row() | ||
|
||
for datum in data_row: | ||
print(datum, end=" ") | ||
row.cell(datum, border=12) | ||
assert_pdf_equal(pdf, HERE / "test_cell_border_top_bottom.pdf", tmp_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed if you perform the call to
.coerce()
inRow.cell()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that those
hasattr
&CellBordersLayout.coerce
calls are needed.