Skip to content

Commit 2bdd073

Browse files
Add comprehensive test suite and rules documentation
- Add .rules directory with detailed guidelines for code style, testing, samples, file review, docs, and commit strategy - Update test READMEs with improved documentation - Add new integration tests for editpdf, pagenumbers, pdftojpg, and validate_pdfa tasks - Add new unit tests for editpdf, pagenumbers, pdftojpg, and validate_pdfa tasks - Update existing unit tests with enhancements - Add test sample files (PDFs and images) for comprehensive testing - Improve test structure and organization Update test_task.py Update test_task_methods.py Update README.md
1 parent 71f8c0a commit 2bdd073

56 files changed

Lines changed: 1250 additions & 92 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ This directory contains all test code for the **iLovePDF Python** library. Tests
44

55
## Structure
66

7-
- `unit/`
8-
Contains unit tests for individual modules and classes.
7+
- `unit/`
8+
Contains unit tests for individual modules and classes.
99
See [`unit/README.md`](unit/README.md) for details.
1010

11-
- `integration/`
12-
Contains integration tests that interact with the iLovePDF API and test complete workflows.
11+
- `integration/`
12+
Contains integration tests that interact with the iLovePDF API and test complete workflows.
1313
See [`integration/README.md`](integration/README.md) for details.
1414

1515
## Running Tests

tests/integration/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@ pytest tests/integration
3333
| test_integration_merge_task.py | Integration tests for MergeTask, merging multiple PDF files. |
3434
| test_integration_office_pdf_task.py | Integration tests for OfficePdfTask, converting Office files to PDF. |
3535
| test_integration_pdfocr_task.py | Integration tests for PdfOcrTask, performing OCR on scanned PDFs. |
36-
| test_integration_pdftopdfa_task.py | Integration tests for PdfToPdfATask, converting PDFs to PDF/A format. |
37-
| test_integration_protect_task.py | Integration tests for ProtectTask, adding password protection to PDFs. |
36+
| test_integration_pdftojpg_task.py | Integration tests for PdfToJpgTask, converting PDF files to JPG images in 'pages' and 'extract' modes. |
37+
| test_integration_pdftopdfa_task.py | Integration tests for PdfToPdfATask, converting PDFs to PDF/A format. |
38+
| test_integration_validate_pdfa_task.py | Integration tests for ValidatePdfATask, validating PDF/A compliance of PDF files. |
39+
| test_integration_protect_task.py | Integration tests for ProtectTask, adding password protection to PDFs. |
3840
| test_integration_repair_task.py | Integration tests for RepairTask, repairing corrupted PDFs. |
3941
| test_integration_rotate_task.py | Integration tests for RotateTask, rotating PDF pages. |
4042
| test_integration_sign_basic_task.py | Integration tests for SignTask, digital signature workflows. |
4143
| test_integration_split_task.py | Integration tests for SplitTask, splitting PDFs by range, pages, or size. |
4244
| test_integration_unlock_task.py | Integration tests for UnlockTask, removing password protection from PDFs. |
4345
| test_integration_watermark_task.py | Integration tests for WatermarkTask, adding text or image watermarks to PDFs. |
44-
| test_integration_removebackground_task.py | Integration tests for RemoveBackgroundTask, verifying background removal in PDFs. |
45-
| test_integration_resize_task.py | Integration tests for ResizeTask, resizing images within PDFs. |
46-
| test_integration_upscale_task.py | Integration tests for UpscaleTask, AI-based upscaling of images in PDFs. |
46+
| test_integration_pagenumbers_task.py | Integration tests for PageNumbersTask, adding page numbers to PDFs with customizable appearance and format. |
47+
| test_integration_editpdf_task.py | Integration tests for EditPdfTask, covering text, image, and SVG elements plus execute/download workflows. |
4748

4849
Update this table as new integration tests are added.
4950

tests/integration/base_task_integration_test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ class MyTaskTest(BaseIlovePdfTaskIntegrationTest):
1010

1111
import os
1212
import shutil
13+
import tempfile
1314
from pathlib import Path
1415
from typing import Generic, TypeVar
1516

1617
import pytest
1718

1819
from ilovepdf.task import Task
1920

20-
_OUTPUT_COUNTER_FILE = Path("/tmp/ilovepdf_output_counter.txt")
21+
_OUTPUT_COUNTER_FILE = Path(
22+
os.path.join(tempfile.gettempdir(), "ilovepdf_output_counter.txt")
23+
)
2124

2225

2326
def get_and_increment_global_counter() -> int:
@@ -45,7 +48,6 @@ def get_and_increment_global_counter() -> int:
4548
T = TypeVar("T", bound=Task)
4649

4750

48-
# pylint: disable=protected-access
4951
class BaseTaskIntegrationTest(Generic[T]):
5052
"""
5153
Base class for iLovePDF Task integration tests.
@@ -245,9 +247,9 @@ def download_result(self, output_filename: str) -> None:
245247
self.task.download()
246248
self.downloaded_file = output_filename
247249

248-
assert os.path.exists(
249-
self.downloaded_file
250-
), f"Downloaded file '{self.downloaded_file}' does not exist."
251-
assert (
252-
os.path.getsize(self.downloaded_file) > 0
253-
), f"Downloaded file '{self.downloaded_file}' is empty."
250+
assert os.path.exists(self.downloaded_file), (
251+
f"Downloaded file '{self.downloaded_file}' does not exist."
252+
)
253+
assert os.path.getsize(self.downloaded_file) > 0, (
254+
f"Downloaded file '{self.downloaded_file}' is empty."
255+
)
14.5 KB
Loading
Lines changed: 9 additions & 0 deletions
Loading
-11.4 KB
Binary file not shown.
826 KB
Binary file not shown.
-978 KB
Binary file not shown.

tests/integration/test_integration_00_auth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ def start(self):
1616
"""Start the authentication test."""
1717

1818

19-
# pylint: disable=bad-option-value
20-
# pylint: disable=broad-exception-raised
2119
class TestAuthAPI(BaseTaskIntegrationTest):
2220
"""Test the authentication API."""
2321

tests/integration/test_integration_01_upload_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def test_full_upload_flow(self):
1515

1616
# 1. Upload a IMG file and associate it with the task
1717
uploaded_file = self.add_sample_file()
18-
assert (
19-
getattr(uploaded_file, "server_filename", None) is not None
20-
), "Uploaded file should have a server_filename."
18+
assert getattr(uploaded_file, "server_filename", None) is not None, (
19+
"Uploaded file should have a server_filename."
20+
)
2121

2222
# 2. Execute the task and download the result
2323
self.execute_task()

0 commit comments

Comments
 (0)