Skip to content

Commit

Permalink
Renamed classes and fixed tests
Browse files Browse the repository at this point in the history
- Fixed failing tests
- Renamed classes to align with design strategy
  • Loading branch information
Ayush-Kaushik committed Jun 13, 2024
1 parent 00a6ed6 commit cea91bd
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PDF Merger
name: PDF Merger [main]

on:
push:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PDF Merger
name: PDF Merger [release]

on:
pull_request:
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pyinstaller PyPDF2 PyQt5 img2pdf
python -m pip install -r requirements.txt
- name: Check contents of workspace
run: |
Expand Down Expand Up @@ -54,7 +54,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
# Pulls from the CREATE RELEASE step above,
# referencing its ID to get its outputs object,
# which include a `upload_url`.
# See this blog post for more info:
# https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release.zip
asset_name: release.zip
asset_content_type: application/zip
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ The tool currently supports following formats:
- PyPDF2
- PyQt5

## 👏 Acknowledgements <a name = "acknowledgement"></a>
- The free landing page has been acquired from here https://cruip.com/demos/solid/. All credit goes to their respective owners.
## 👏 Acknowledgements <a name = "acknowledgement"></a>
- Free PDF's for testing found here: https://freetestdata.com/document-files/pdf/
- Sample image files found here: https://file-examples.com/

Expand Down
6 changes: 3 additions & 3 deletions pdf_merger/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyPDF2 import PdfFileMerger
from PyQt5.QtWidgets import QHBoxLayout, QWidget, QMainWindow, QTabWidget, QApplication

from pdf_merger.src.services import ImageService, PDFService
from pdf_merger.src.services import ImageMergerService, PdfMergerService
from pdf_merger.src.views import AppLayoutConfig, ViewAggregator
from pdf_merger.src.views.labels import Labels

Expand All @@ -20,8 +20,8 @@ def configure(self, binder: Binder) -> None:

class ViewAggregatorContainerModule(Module):
def configure(self, binder: Binder) -> None:
binder.bind(PDFService, to=PDFService(PdfFileMerger(), [], ""), scope=injector.singleton)
binder.bind(ImageService, to=ImageService(img2pdf, [], ""), scope=injector.singleton)
binder.bind(PdfMergerService, to=PdfMergerService(PdfFileMerger(), [], ""), scope=injector.singleton)
binder.bind(ImageMergerService, to=ImageMergerService(img2pdf, [], ""), scope=injector.singleton)
binder.bind(Labels, to=Labels())
binder.bind(ViewAggregator, to=ViewAggregator, scope=injector.singleton)

Expand Down
6 changes: 3 additions & 3 deletions pdf_merger/src/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# __init__.py

from .image_service import ImageService
from .pdf_service import PDFService
from .image_merger_service import ImageMergerService
from .pdf_merger_service import PdfMergerService

__all__ = ['ImageService', 'PDFService']
__all__ = ['ImageMergerService', 'PdfMergerService']

VERSION = '1.0.0'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pathlib


class FileMergerServiceInterface(ABC):
class AbstractFileMergerService(ABC):
def __init__(self, allowed_extensions, target_file_path: pathlib.Path):
self.allowed_file_extensions = allowed_extensions
self.target_file_path = target_file_path
Expand All @@ -29,4 +29,3 @@ def set_output_target(self, file_path):
@abstractmethod
def get_output_target(self):
pass

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from PyQt5.QtCore import QUrl
import pathlib
import img2pdf
from pdf_merger.src.services.merger_service_interface import FileMergerServiceInterface
from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService

'''
Operations related to merging Images to PDF
'''


class ImageService(FileMergerServiceInterface):
class ImageMergerService(AbstractFileMergerService):
def __init__(self, merger: img2pdf, file_list, target_path: pathlib.Path):
super().__init__({
".jpg": ".jpg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import pathlib
from PyPDF2 import PdfFileMerger
from pdf_merger.src.services.merger_service_interface import FileMergerServiceInterface
from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService

'''
Deals with operations related to PDF merging and creation
'''


class PDFService(FileMergerServiceInterface):
class PdfMergerService(AbstractFileMergerService):
def __init__(self, merger: PdfFileMerger, path_list, target_path: pathlib.Path):
super().__init__({".pdf": ".pdf"}, target_path) # passing valid extensions
self.merger = merger
Expand Down
6 changes: 3 additions & 3 deletions pdf_merger/src/views/drag_drop_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from PyQt5.QtWidgets import QAbstractItemView, QListWidget
from pdf_merger.src.exceptions import InvalidExtensionError
from pdf_merger.src.views.popup_factory import PopupFactory
from pdf_merger.src.services.merger_service_interface import FileMergerServiceInterface
from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService

'''
List Widget Box which accepts multiple PDF files
List Widget Box which accepts multiple files
Using polymorphism here to be able to pass any services
PDFService, ImageService etc.
'''


class DragAndDropArea(QListWidget):
def __init__(self, service: FileMergerServiceInterface, parent=None):
def __init__(self, service: AbstractFileMergerService, parent=None):
super().__init__(parent)

self.setAcceptDrops(True)
Expand Down
4 changes: 2 additions & 2 deletions pdf_merger/src/views/file_collection_merge_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pdf_merger.src.views.labels import Labels
from pdf_merger.src.views.popup_factory import PopupFactory

from pdf_merger.src.services.merger_service_interface import FileMergerServiceInterface
from pdf_merger.src.services.abstract_merger_service import AbstractFileMergerService

'''
Includes the complete view for Merging files into single PDF
Expand All @@ -18,7 +18,7 @@
class FileCollectionMergeView(QWidget):
def __init__(
self,
service: FileMergerServiceInterface,
service: AbstractFileMergerService,
config: AppLayoutConfig,
labels: Labels
):
Expand Down
8 changes: 4 additions & 4 deletions pdf_merger/src/views/view_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pdf_merger.src.views import AppLayoutConfig, Labels
from pdf_merger.src.views.file_collection_merge_view import FileCollectionMergeView
from pdf_merger.src.services.image_service import ImageService
from pdf_merger.src.services.pdf_service import PDFService
from pdf_merger.src.services.image_merger_service import ImageMergerService
from pdf_merger.src.services.pdf_merger_service import PdfMergerService
from injector import inject

'''
Expand All @@ -15,8 +15,8 @@ class ViewAggregator:
@inject
def __init__(
self,
pdf_service: PDFService,
image_service: ImageService,
pdf_service: PdfMergerService,
image_service: ImageMergerService,
widget_layout_config: AppLayoutConfig,
labels: Labels
):
Expand Down
24 changes: 16 additions & 8 deletions tests/test_image_to_pdf_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@
import pathlib
import img2pdf
from PyQt5.QtCore import QUrl
from pdf_merger.src.services import ImageService
from pdf_merger.src.services import ImageMergerService


class TestImagesToPdfService(unittest.TestCase):
def setUp(self):
self.merger = img2pdf
self.target_file_path = pathlib.Path("./pdf_merger/tests/output/test_output.pdf")
self.path_list = [
"./pdf_merger/tests/data/image/file_example_JPG_1MB.jpg",
"./pdf_merger/tests/data/image/file_example_JPG_1MB.jpg"]
self.service = ImageService(self.merger, self.path_list, self.target_file_path)
test_path = str(pathlib.Path(__file__).parent.resolve())
self.target_file_path = pathlib.Path(test_path + "/output/test_output.pdf")

self.service = ImageMergerService(
img2pdf,
[
test_path + "/tests/data/image/file_example_JPG_1MB.jpg",
test_path + "/tests/data/image/file_example_JPG_1MB.jpg"
],
self.target_file_path)

def test_merge_files(self):

print("Path of test file")
print()

self.service.merge_files()
self.assertTrue(self.service.target_file_path.exists())

def test_set_target_path(self):
new_target_path = pathlib.Path("./pdf_merger/tests/output/image.jpg")
new_target_path = pathlib.Path("./tests/output/image.pdf")
self.service.set_output_target(new_target_path)
self.assertEqual(self.service.get_output_target(), new_target_path)

Expand Down

0 comments on commit cea91bd

Please sign in to comment.