-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PPF-750: Improve Integer and Float Input Handling in PdfWrapper.fill(…
…) Method (#750) * PPF-749: add integer and float input handling to PdfWrapper.fill() method * PPF-749: add new filled sample pdf files * PPF-749: add new tests in 'tests/test_fill_method.py'
- Loading branch information
1 parent
b851988
commit 65c5c8d
Showing
8 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import os | ||
from PyPDFForm import PdfWrapper | ||
|
||
|
||
def test_fill_with_varied_int_values(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_varied_ints.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": 100, | ||
"test_2": -250, | ||
"test_3": 0, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected | ||
|
||
|
||
def test_fill_with_boolean_and_int_values(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_boolean_and_ints.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": 42, | ||
"test_2": True, | ||
"test_3": False, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected | ||
|
||
|
||
def test_fill_with_empty_string_and_int(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_with_empty_string_and_int.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": 42, | ||
"test_2": "", | ||
"test_3": 33, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected | ||
|
||
|
||
def test_fill_with_large_and_small_ints(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_large_and_small_ints.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": 999999999999, | ||
"test_2": -999999999999, | ||
"test_3": 1, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected | ||
|
||
|
||
def test_fill_with_varied_float_values(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_varied_float_values.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": 1.5, | ||
"test_2": 13.8, | ||
"test_3": 543, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected | ||
|
||
|
||
def test_fill_with_negative_and_positive_floats_and_int(pdf_samples, request): | ||
expected_path = os.path.join(pdf_samples, "sample_filled_negative_and_positive_floats_and_int.pdf") | ||
with open(expected_path, "rb+") as f: | ||
obj = PdfWrapper(os.path.join(pdf_samples, "sample_template.pdf")).fill( | ||
{ | ||
"test": -1.5, | ||
"test_2": -6.9, | ||
"test_3": 22, | ||
} | ||
) | ||
|
||
request.config.results["expected_path"] = expected_path | ||
request.config.results["stream"] = obj.read() | ||
|
||
expected = f.read() | ||
|
||
assert len(obj.read()) == len(expected) | ||
assert obj.read() == expected |