Skip to content

Commit

Permalink
PPF-433: also change deprecating attribute docstrings to todos
Browse files Browse the repository at this point in the history
  • Loading branch information
chinapandaman committed Dec 30, 2023
1 parent 908eab4 commit 5b905ed
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
21 changes: 18 additions & 3 deletions PyPDFForm/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def read(self) -> bytes:

@property
def elements(self) -> dict:
"""About to be deprecated."""
"""ToDo: deprecate this."""

warn(
DEPRECATION_NOTICE.format(
Expand Down Expand Up @@ -197,7 +197,8 @@ def draw_image(

return self

def generate_schema(self) -> dict:
@property
def schema(self) -> dict:
"""Generates a json schema for the PDF form template."""

result = {
Expand All @@ -209,6 +210,20 @@ def generate_schema(self) -> dict:

return result

def generate_schema(self) -> dict:
"""ToDo: deprecate this."""

warn(
DEPRECATION_NOTICE.format(
f"{self.__class__.__name__}.generate_schema()",
f"{self.__class__.__name__}.schema",
),
DeprecationWarning,
stacklevel=2,
)

return self.schema

@classmethod
def register_font(
cls, font_name: str, ttf_file: Union[bytes, str, BinaryIO]
Expand All @@ -221,7 +236,7 @@ def register_font(


class PyPDFForm(PdfWrapper):
"""About to be deprecated."""
"""ToDo: deprecate this."""

def __init__(
self,
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ with open(PATH_TO_OUTPUT_PDF_FORM, "wb+") as output:
output.write(filled_pdf.read())
```

## Generate JSON schema
## Retrieve JSON schema

This example demos how to generate a JSON schema for a PDF form.
This example demos how to retrieve a JSON schema for the data used to fill a PDF form.

```python
import json
Expand All @@ -377,7 +377,7 @@ PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM = os.path.join(
print(
json.dumps(PdfWrapper(
PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM
).generate_schema(), indent=4, sort_keys=True)
).schema, indent=4, sort_keys=True)
)
```

Expand Down Expand Up @@ -452,7 +452,7 @@ PATH_TO_FILLED_PDF_FORM = os.path.join(
) # Change this to where you wish to put your filled PDF form

obj = PdfWrapper(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM)
print(obj.pages[0].generate_schema())
print(obj.pages[0].schema)

with open(PATH_TO_FILLED_PDF_FORM, "wb+") as output:
output.write(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from PyPDFForm import PdfWrapper


def test_generate_schema(sample_template_with_dropdown):
schema = PdfWrapper(sample_template_with_dropdown).generate_schema()
def test_schema(sample_template_with_dropdown):
schema = PdfWrapper(sample_template_with_dropdown).schema

for key, value in schema["properties"].items():
if key == "dropdown_1":
Expand Down
14 changes: 11 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def test_elements_deprecation_notice(template_stream):
assert r


def test_generate_schema_deprecation_notice(template_stream):
with pytest.warns(DeprecationWarning) as r:
obj = PdfWrapper(template_stream)
assert not r
assert obj.generate_schema() == obj.schema
assert r


def test_pypdfform_deprecation_notice(template_stream):
with pytest.warns(DeprecationWarning) as r:
assert PyPDFForm(template_stream)
Expand Down Expand Up @@ -322,15 +330,15 @@ def test_addition_operator_3_times_sejda(
assert result.read() == expected


def test_generate_schema(sample_template_with_comb_text_field):
def test_schema(sample_template_with_comb_text_field):
data = {
"FirstName": "John",
"MiddleName": "Joe",
"LastName": "XXXXXXX",
"Awesomeness": True,
"Gender": 0,
}
schema = PdfWrapper(sample_template_with_comb_text_field).generate_schema()
schema = PdfWrapper(sample_template_with_comb_text_field).schema

assert schema["type"] == "object"
properties = schema["properties"]
Expand Down Expand Up @@ -369,7 +377,7 @@ def test_generate_schema(sample_template_with_comb_text_field):
def test_sample_data(sejda_template_complex):
obj = PdfWrapper(sejda_template_complex)
try:
validate(instance=obj.sample_data, schema=obj.generate_schema())
validate(instance=obj.sample_data, schema=obj.schema)
except ValidationError:
assert False

Expand Down

0 comments on commit 5b905ed

Please sign in to comment.