-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: Rewrite JS tests from unittest to pytest (#746)
Signed-off-by: Matthew Peveler <[email protected]>
- Loading branch information
1 parent
7771fad
commit 0ea2301
Showing
5 changed files
with
47 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import pytest | ||
|
||
from PyPDF2 import PdfFileReader, PdfFileWriter | ||
|
||
# Configure path environment | ||
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__)) | ||
PROJECT_ROOT = os.path.dirname(TESTS_ROOT) | ||
RESOURCE_ROOT = os.path.join(PROJECT_ROOT, "Resources") | ||
|
||
@pytest.fixture | ||
def pdf_file_writer(): | ||
ipdf = PdfFileReader(os.path.join(RESOURCE_ROOT, "crazyones.pdf")) | ||
pdf_file_writer = PdfFileWriter() | ||
pdf_file_writer.appendPagesFromReader(ipdf) | ||
yield pdf_file_writer | ||
|
||
def test_add_js(pdf_file_writer): | ||
pdf_file_writer.addJS( | ||
"this.print({bUI:true,bSilent:false,bShrinkToFit:true});" | ||
) | ||
|
||
assert "/Names" in pdf_file_writer._root_object, "addJS should add a name catalog in the root object." | ||
assert "/JavaScript" in pdf_file_writer._root_object["/Names"], "addJS should add a JavaScript name tree under the name catalog." | ||
assert "/OpenAction" in pdf_file_writer._root_object, "addJS should add an OpenAction to the catalog." | ||
|
||
def test_overwrite_js(pdf_file_writer): | ||
def get_javascript_name(): | ||
assert "/Names" in pdf_file_writer._root_object | ||
assert "/JavaScript" in pdf_file_writer._root_object["/Names"] | ||
assert "/Names" in pdf_file_writer._root_object["/Names"]["/JavaScript"] | ||
return pdf_file_writer._root_object["/Names"]["/JavaScript"]["/Names"][0] | ||
|
||
pdf_file_writer.addJS( | ||
"this.print({bUI:true,bSilent:false,bShrinkToFit:true});" | ||
) | ||
first_js = get_javascript_name() | ||
|
||
pdf_file_writer.addJS( | ||
"this.print({bUI:true,bSilent:false,bShrinkToFit:true});" | ||
) | ||
second_js = get_javascript_name() | ||
|
||
assert first_js != second_js, "addJS should overwrite the previous script in the catalog." |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters