Skip to content

Commit

Permalink
Merge pull request #377 from chinapandaman/PPF-376
Browse files Browse the repository at this point in the history
PPF-376: refactor out paragraph tests
  • Loading branch information
chinapandaman authored Jul 17, 2023
2 parents c37eb91 + 8d8b1c6 commit bd9ad07
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 202 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed pdf_samples/sample_filled_offset_100.pdf
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ def sejda_template(pdf_samples):
@pytest.fixture
def sejda_template_complex(pdf_samples):
with open(
os.path.join(pdf_samples, "sample_template_sejda_complex.pdf"), "rb+"
os.path.join(pdf_samples, "paragraph", "sample_template_sejda_complex.pdf"), "rb+"
) as f:
return f.read()


@pytest.fixture
def sample_template_paragraph_complex(pdf_samples):
with open(
os.path.join(pdf_samples, "sample_template_paragraph_complex.pdf"), "rb+"
os.path.join(pdf_samples, "paragraph", "sample_template_paragraph_complex.pdf"), "rb+"
) as f:
return f.read()


@pytest.fixture
def sample_template_with_paragraph_max_length(pdf_samples):
with open(
os.path.join(pdf_samples, "sample_template_with_paragraph_max_length.pdf"),
os.path.join(pdf_samples, "paragraph", "sample_template_with_paragraph_max_length.pdf"),
"rb+",
) as f:
return f.read()
Expand Down Expand Up @@ -135,7 +135,7 @@ def sample_template_with_right_aligned_text_field(pdf_samples):
@pytest.fixture
def sample_template_with_paragraph(pdf_samples):
with open(
os.path.join(pdf_samples, "sample_template_with_paragraph.pdf"),
os.path.join(pdf_samples, "paragraph", "sample_template_with_paragraph.pdf"),
"rb+",
) as f:
return f.read()
Expand All @@ -144,7 +144,7 @@ def sample_template_with_paragraph(pdf_samples):
@pytest.fixture
def sample_template_with_paragraph_auto_font(pdf_samples):
with open(
os.path.join(pdf_samples, "sample_template_with_paragraph_auto_font.pdf"),
os.path.join(pdf_samples, "paragraph", "sample_template_with_paragraph_auto_font.pdf"),
"rb+",
) as f:
return f.read()
Expand Down
197 changes: 0 additions & 197 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,200 +376,3 @@ def test_fill_right_aligned(

for _, elements in template_core.get_elements_by_page(obj.read()).items():
assert not elements


def test_paragraph_y_coordinate(sample_template_with_paragraph, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "test_paragraph_y_coordinate.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_paragraph).fill(
{"paragraph_1": "test paragraph"}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_paragraph_auto_wrap(sample_template_with_paragraph, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "test_paragraph_auto_wrap.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_paragraph).fill(
{
"paragraph_1": "t xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx t"
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected
assert obj.elements["paragraph_1"].text_wrap_length is not None


def test_paragraph_auto_font(
sample_template_with_paragraph_auto_font, pdf_samples, request
):
expected_path = os.path.join(pdf_samples, "test_paragraph_auto_font.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_paragraph_auto_font).fill(
{"paragraph": "test paragraph"}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_paragraph_auto_font_auto_wrap(
sample_template_with_paragraph_auto_font, pdf_samples, request
):
expected_path = os.path.join(pdf_samples, "test_paragraph_auto_font_auto_wrap.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_paragraph_auto_font).fill(
{
"paragraph": "t xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx t"
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected
assert obj.elements["paragraph"].text_wrap_length is not None


def test_fill_sejda_complex(sejda_template_complex, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "sample_filled_sejda_complex.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sejda_template_complex).fill(
{
"checkbox": True,
"radio": 0,
"dropdown_font_auto_left": 0,
"dropdown_font_auto_center": 1,
"dropdown_font_auto_right": 2,
"dropdown_font_ten_left": 0,
"dropdown_font_ten_center": 1,
"dropdown_font_ten_right": 2,
"paragraph_font_auto_left": "paragraph_font_auto_left",
"paragraph_font_auto_center": "paragraph_font_auto_center",
"paragraph_font_auto_right": "paragraph_font_auto_right",
"paragraph_font_ten_left": "paragraph_font_ten_left",
"paragraph_font_ten_center": "paragraph_font_ten_center",
"paragraph_font_ten_right": "paragraph_font_ten_right",
"text__font_auto_left": "test text",
"text_font_auto_center": "test text",
"text_font_auto_right": "test text",
"text_font_ten_left": "text_font_ten_left",
"text_font_ten_center": "text_font_ten_center",
"text_font_ten_right": "text_font_ten_right",
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_sejda_complex_paragraph_multiple_line_alignment(
sejda_template_complex, pdf_samples, request
):
expected_path = os.path.join(
pdf_samples, "sample_filled_sejda_complex_paragraph_multiple_line_alignment.pdf"
)
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sejda_template_complex).fill(
{
"paragraph_font_auto_left": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_auto_right": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_auto_center": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_left": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_right": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_center": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_paragraph_complex(sample_template_paragraph_complex, pdf_samples, request):
expected_path = os.path.join(pdf_samples, "test_paragraph_complex.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_paragraph_complex).fill(
{
"paragraph_font_auto_left": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_auto_right": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_auto_center": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_left": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_right": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"paragraph_font_ten_center": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected


def test_paragraph_max_length(
sample_template_with_paragraph_max_length, pdf_samples, request
):
expected_path = os.path.join(pdf_samples, "test_paragraph_max_length.pdf")
with open(expected_path, "rb+") as f:
obj = PyPDFForm(sample_template_with_paragraph_max_length).fill(
{
"paragraph": "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
}
)

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
assert len(obj.read()) == len(obj.stream)
assert obj.read() == obj.stream

expected = f.read()

assert len(obj.stream) == len(expected)
assert obj.stream == expected
Loading

0 comments on commit bd9ad07

Please sign in to comment.