Skip to content

Adding attachFiles function and unit tests#29

Merged
claird merged 7 commits intoclaird:masterfrom
michd89:master
Jun 21, 2020
Merged

Adding attachFiles function and unit tests#29
claird merged 7 commits intoclaird:masterfrom
michd89:master

Conversation

@michd89
Copy link
Copy Markdown

@michd89 michd89 commented Feb 25, 2019

  • Added the attachFiles function for attaching multiple files onto a PDF created with a PdfFileWriter. Also added a respective unit test.

  • There was no unit test for the addAttachment function, so I wrote one.

Added a unit test for the addAttachment function because it was missing.
Added a unit test for the attachFiles function.
@acsor
Copy link
Copy Markdown
Collaborator

acsor commented Feb 27, 2019

Hey @michd89, some of the test data is missing from your (two?) tests. Nothing serious, you should just commit them as well (track them into the staging area → commit → push again).

Here are the error backlogs under my setup:

testAddAttachment()

Error
Traceback (most recent call last):
  File "/usr/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.5/unittest/case.py", line 601, in run
    testMethod()
  File "/home/acsor/software/PyPDF4/tests/test_pdf.py", line 443, in testAddAttachment
    'jpeg.pdf')) as writer:
  File "/home/acsor/software/PyPDF4/pypdf/pdf.py", line 82, in __init__
    self._stream = open(stream, "wb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/acsor/software/PyPDF4/tests/fixture_data/testAddAttachment/jpeg.pdf'

testAttachFiles()

Exception ignored in: <object repr() failed>
Traceback (most recent call last):

Error
Traceback (most recent call last):
  File "/usr/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/lib/python3.5/unittest/case.py", line 601, in run
    testMethod()
  File "/home/acsor/software/PyPDF4/tests/test_pdf.py", line 476, in testAttachFiles
    'jpeg.pdf')) as writer:
  File "/home/acsor/software/PyPDF4/pypdf/pdf.py", line 82, in __init__
    self._stream = open(stream, "wb")
FileNotFoundError: [Errno 2] No such file or directory: '/home/acsor/software/PyPDF4/tests/fixture_data/testAddAttachment/jpeg.pdf'

Replaced paths within fixture_data directory by temporary files.
@michd89
Copy link
Copy Markdown
Author

michd89 commented Feb 27, 2019

@Newnone Indeed, I left some paths within the tests, which existed only in my local repository. Now I replaced them by temporary files.

@acsor
Copy link
Copy Markdown
Collaborator

acsor commented Feb 28, 2019

All seems to be fine now. By the way, I suppose you have guessed the structure of the test suite. If need to be, you can place test files within dedicated directories (e.g. tests/fixture_data/testAddAttachment/).

Until I find time to carefully analyze how these changes interfere with the preexisting code, I leave it to @claird whether or not this PR can be merged.

@michd89
Copy link
Copy Markdown
Author

michd89 commented Feb 28, 2019

Yes, in the beginning I thought about using dedicated directories (I kept them in my early tests; that's why they failed before the fix). But actually the files which are already provided in tests/fixture_data/ are suitable.

Between the addAttachment and attachFiles there are some redundancies because my priority was to add the new functionality in the latter one. I'm sure that @claird wants to resolve some redundancies if possible.

Edit: Typo

@acsor acsor added enhancement New feature or request help wanted Extra attention is needed labels May 8, 2019
@claird claird merged commit e38a59b into claird:master Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants