Skip to content

Commit

Permalink
[skip ci]: black/isort
Browse files Browse the repository at this point in the history
  • Loading branch information
black-isort-bot committed Feb 16, 2024
1 parent 6f6c1f9 commit 89d46f8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
4 changes: 3 additions & 1 deletion PyPDFForm/core/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def get_draw_checkbox_radio_coordinates(
)


def get_draw_sig_coordinates_resolutions(widget: dict) -> Tuple[float, float, float, float]:
def get_draw_sig_coordinates_resolutions(
widget: dict,
) -> Tuple[float, float, float, float]:
"""
Returns coordinates and resolutions to draw signature at given a PDF form signature widget.
"""
Expand Down
24 changes: 13 additions & 11 deletions PyPDFForm/core/filler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from ..middleware.radio import Radio
from ..middleware.signature import Signature
from .coordinate import (get_draw_checkbox_radio_coordinates,
get_draw_sig_coordinates_resolutions,
get_draw_text_coordinates,
get_text_line_x_coordinates,
get_draw_sig_coordinates_resolutions)
get_text_line_x_coordinates)
from .font import checkbox_radio_font_size
from .image import any_image_to_jpg
from .template import get_widget_key, get_widgets_by_page
Expand Down Expand Up @@ -61,14 +61,14 @@ def fill(
stream = any_image_to_jpg(stream)
x, y, width, height = get_draw_sig_coordinates_resolutions(_widget)
images_to_draw[page].append(
[
stream,
x,
y,
width,
height,
]
)
[
stream,
x,
y,
width,
height,
]
)
text_needs_to_be_drawn = False
else:
widgets[key].text_line_x_coordinates = get_text_line_x_coordinates(
Expand Down Expand Up @@ -97,7 +97,9 @@ def fill(

if any_image_to_draw:
for page, images in images_to_draw.items():
_watermarks = create_watermarks_and_draw(template_stream, page, "image", images)
_watermarks = create_watermarks_and_draw(
template_stream, page, "image", images
)
for i, watermark in enumerate(_watermarks):
if watermark:
image_watermarks[i] = watermark
Expand Down
8 changes: 4 additions & 4 deletions PyPDFForm/core/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from ..middleware.checkbox import Checkbox
from ..middleware.dropdown import Dropdown
from ..middleware.radio import Radio
from ..middleware.text import Text
from ..middleware.signature import Signature
from ..middleware.text import Text
from .constants import (ANNOTATION_FIELD_KEY, BUTTON_IDENTIFIER,
BUTTON_STYLE_IDENTIFIER, CHOICE_FIELD_IDENTIFIER,
CHOICES_IDENTIFIER, FIELD_FLAG_KEY, PARENT_KEY,
SELECTABLE_IDENTIFIER, SUBTYPE_KEY,
TEXT_FIELD_ALIGNMENT_IDENTIFIER,
SELECTABLE_IDENTIFIER, SIGNATURE_FIELD_IDENTIFIER,
SUBTYPE_KEY, TEXT_FIELD_ALIGNMENT_IDENTIFIER,
TEXT_FIELD_APPEARANCE_IDENTIFIER,
TEXT_FIELD_IDENTIFIER, WIDGET_SUBTYPE_KEY,
WIDGET_TYPE_KEY, SIGNATURE_FIELD_IDENTIFIER)
WIDGET_TYPE_KEY)

WIDGET_TYPE_PATTERNS = [
(
Expand Down
2 changes: 1 addition & 1 deletion PyPDFForm/middleware/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from .checkbox import Checkbox
from .dropdown import Dropdown
from .radio import Radio
from .text import Text
from .signature import Signature
from .text import Text

VERSION_IDENTIFIERS = [
b"%PDF-1.0",
Expand Down
10 changes: 5 additions & 5 deletions PyPDFForm/middleware/signature.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""Contains signature middleware."""

from typing import BinaryIO, Union
from os.path import expanduser
from typing import BinaryIO, Union

from .adapter import fp_or_f_obj_or_stream_to_stream
from .widget import Widget
Expand Down Expand Up @@ -37,7 +37,7 @@ def stream(self) -> Union[bytes, None]:
"""Converts the value of the signature field image to a stream."""

return (
fp_or_f_obj_or_stream_to_stream(self.value)
if self.value is not None
else None
)
fp_or_f_obj_or_stream_to_stream(self.value)
if self.value is not None
else None
)
33 changes: 17 additions & 16 deletions tests/test_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@


def test_fill_signature(pdf_samples, image_samples, request):
expected_path = os.path.join(
pdf_samples, "signature", "test_fill_signature.pdf"
)
expected_path = os.path.join(pdf_samples, "signature", "test_fill_signature.pdf")
with open(expected_path, "rb+") as f:
obj = PdfWrapper(
os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf")
).fill(
{"signature": os.path.join(image_samples, "sample_signature.png")}
)
os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf")
).fill({"signature": os.path.join(image_samples, "sample_signature.png")})

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
Expand All @@ -27,28 +23,33 @@ def test_fill_signature(pdf_samples, image_samples, request):


def test_signature_schema(pdf_samples):
obj = PdfWrapper(os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf"))
obj = PdfWrapper(
os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf")
)

assert obj.widgets["signature"].schema_definition == {"type": "string"}


def test_signature_sample_value(pdf_samples):
obj = PdfWrapper(os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf"))
obj = PdfWrapper(
os.path.join(pdf_samples, "signature", "sample_template_with_signature.pdf")
)

assert obj.widgets["signature"].sample_value == os.path.expanduser(
"~/Downloads/sample_image.jpg")
"~/Downloads/sample_image.jpg"
)


def test_fill_signature_overlap(pdf_samples, image_samples, request):
expected_path = os.path.join(
pdf_samples, "signature", "test_fill_signature_overlap.pdf"
)
pdf_samples, "signature", "test_fill_signature_overlap.pdf"
)
with open(expected_path, "rb+") as f:
obj = PdfWrapper(
os.path.join(pdf_samples, "signature", "sample_template_with_signature_overlap.pdf")
).fill(
{"signature": os.path.join(image_samples, "sample_signature.png")}
)
os.path.join(
pdf_samples, "signature", "sample_template_with_signature_overlap.pdf"
)
).fill({"signature": os.path.join(image_samples, "sample_signature.png")})

request.config.results["expected_path"] = expected_path
request.config.results["stream"] = obj.read()
Expand Down

0 comments on commit 89d46f8

Please sign in to comment.