upload new sources (v0.6.1)
This commit is contained in:
parent
1fbf42ae6b
commit
117a1debbb
6 changed files with 90 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
/pdfkit-0.4.1.tar.gz
|
||||
/pdfkit-0.5.0.zip
|
||||
/pdfkit-0.6.1.tar.gz
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import sys
|
|||
import codecs
|
||||
import unittest
|
||||
|
||||
|
||||
if sys.version_info[0] == 2 and sys.version_info[1] == 7:
|
||||
unittest.TestCase.assertRegex = unittest.TestCase.assertRegexpMatches
|
||||
|
||||
|
||||
#Prepend ../ to PYTHONPATH so that we can import PDFKIT form there.
|
||||
TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(TESTS_ROOT, '..')))
|
||||
|
|
@ -41,11 +46,66 @@ class TestPDFKitInitialization(unittest.TestCase):
|
|||
|
||||
def test_options_parsing(self):
|
||||
r = pdfkit.PDFKit('html', 'string', options={'page-size': 'Letter'})
|
||||
self.assertTrue(r.options['--page-size'])
|
||||
test_command = r.command('test')
|
||||
idx = test_command.index('--page-size') # Raise exception in case of not found
|
||||
self.assertTrue(test_command[idx+1] == 'Letter')
|
||||
|
||||
def test_options_parsing_with_dashes(self):
|
||||
r = pdfkit.PDFKit('html', 'string', options={'--page-size': 'Letter'})
|
||||
self.assertTrue(r.options['--page-size'])
|
||||
|
||||
test_command = r.command('test')
|
||||
idx = test_command.index('--page-size') # Raise exception in case of not found
|
||||
self.assertTrue(test_command[idx+1] == 'Letter')
|
||||
|
||||
def test_options_parsing_with_tuple(self):
|
||||
options = {
|
||||
'--custom-header': [
|
||||
('Accept-Encoding','gzip')
|
||||
]
|
||||
}
|
||||
r = pdfkit.PDFKit('html', 'string', options=options)
|
||||
command = r.command()
|
||||
idx1 = command.index('--custom-header') # Raise exception in case of not found
|
||||
self.assertTrue(command[idx1 + 1] == 'Accept-Encoding')
|
||||
self.assertTrue(command[idx1 + 2] == 'gzip')
|
||||
|
||||
def test_options_parsing_with_tuple_no_dashes(self):
|
||||
options = {
|
||||
'custom-header': [
|
||||
('Accept-Encoding','gzip')
|
||||
]
|
||||
}
|
||||
r = pdfkit.PDFKit('html', 'string', options=options)
|
||||
command = r.command()
|
||||
idx1 = command.index('--custom-header') # Raise exception in case of not found
|
||||
self.assertTrue(command[idx1 + 1] == 'Accept-Encoding')
|
||||
self.assertTrue(command[idx1 + 2] == 'gzip')
|
||||
|
||||
def test_repeatable_options(self):
|
||||
roptions = {
|
||||
'--page-size': 'Letter',
|
||||
'cookies': [
|
||||
('test_cookie1','cookie_value1'),
|
||||
('test_cookie2','cookie_value2'),
|
||||
]
|
||||
}
|
||||
|
||||
r = pdfkit.PDFKit('html', 'string', options=roptions)
|
||||
|
||||
test_command = r.command('test')
|
||||
|
||||
idx1 = test_command.index('--page-size') # Raise exception in case of not found
|
||||
self.assertTrue(test_command[idx1 + 1] == 'Letter')
|
||||
|
||||
self.assertTrue(test_command.count('--cookies') == 2)
|
||||
|
||||
idx2 = test_command.index('--cookies')
|
||||
self.assertTrue(test_command[idx2 + 1] == 'test_cookie1')
|
||||
self.assertTrue(test_command[idx2 + 2] == 'cookie_value1')
|
||||
|
||||
idx3 = test_command.index('--cookies', idx2 + 2)
|
||||
self.assertTrue(test_command[idx3 + 1] == 'test_cookie2')
|
||||
self.assertTrue(test_command[idx3 + 2] == 'cookie_value2')
|
||||
|
||||
def test_custom_configuration(self):
|
||||
conf = pdfkit.configuration()
|
||||
|
|
@ -155,14 +215,18 @@ class TestPDFKitCommandGeneration(unittest.TestCase):
|
|||
}
|
||||
r = pdfkit.PDFKit('html', 'string', options=options, toc={'xsl-style-sheet': 'test.xsl'})
|
||||
|
||||
self.assertEqual(r.command()[1 + len(options) * 2], 'toc')
|
||||
self.assertEqual(r.command()[1 + len(options) * 2 + 1], '--xsl-style-sheet')
|
||||
command = r.command()
|
||||
|
||||
self.assertEqual(command[1 + len(options) * 2], 'toc')
|
||||
self.assertEqual(command[1 + len(options) * 2 + 1], '--xsl-style-sheet')
|
||||
|
||||
def test_cover_without_options(self):
|
||||
r = pdfkit.PDFKit('html', 'string', cover='test.html')
|
||||
|
||||
self.assertEqual(r.command()[1], 'cover')
|
||||
self.assertEqual(r.command()[2], 'test.html')
|
||||
command = r.command()
|
||||
|
||||
self.assertEqual(command[1], 'cover')
|
||||
self.assertEqual(command[2], 'test.html')
|
||||
|
||||
def test_cover_with_options(self):
|
||||
options = {
|
||||
|
|
@ -175,8 +239,10 @@ class TestPDFKitCommandGeneration(unittest.TestCase):
|
|||
}
|
||||
r = pdfkit.PDFKit('html', 'string', options=options, cover='test.html')
|
||||
|
||||
self.assertEqual(r.command()[1 + len(options) * 2], 'cover')
|
||||
self.assertEqual(r.command()[1 + len(options) * 2 + 1], 'test.html')
|
||||
command = r.command()
|
||||
|
||||
self.assertEqual(command[1 + len(options) * 2], 'cover')
|
||||
self.assertEqual(command[1 + len(options) * 2 + 1], 'test.html')
|
||||
|
||||
def test_cover_and_toc(self):
|
||||
options = {
|
||||
|
|
@ -191,6 +257,19 @@ class TestPDFKitCommandGeneration(unittest.TestCase):
|
|||
command = r.command()
|
||||
self.assertEqual(command[-7:], ['toc', '--xsl-style-sheet', 'test.xsl', 'cover', 'test.html', '-', '-'])
|
||||
|
||||
def test_cover_and_toc_cover_first(self):
|
||||
options = {
|
||||
'page-size': 'Letter',
|
||||
'margin-top': '0.75in',
|
||||
'margin-right': '0.75in',
|
||||
'margin-bottom': '0.75in',
|
||||
'margin-left': '0.75in',
|
||||
'encoding': "UTF-8"
|
||||
}
|
||||
r = pdfkit.PDFKit('html', 'string', options=options, toc={'xsl-style-sheet': 'test.xsl'}, cover='test.html', cover_first=True)
|
||||
command = r.command()
|
||||
self.assertEqual(command[-7:], ['cover', 'test.html', 'toc', '--xsl-style-sheet', 'test.xsl', '-', '-'])
|
||||
|
||||
def test_outline_options(self):
|
||||
options = {
|
||||
'outline': None,
|
||||
|
|
@ -327,7 +406,7 @@ class TestPDFKitGeneration(unittest.TestCase):
|
|||
r.to_pdf()
|
||||
|
||||
raised_exception = cm.exception
|
||||
self.assertRegexpMatches(str(raised_exception), '^wkhtmltopdf exited with non-zero code 1. error:\nUnknown long argument --bad-option\r?\n')
|
||||
self.assertRegex(str(raised_exception), '^wkhtmltopdf exited with non-zero code 1. error:\nUnknown long argument --bad-option\r?\n')
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
2
sources
2
sources
|
|
@ -1 +1 @@
|
|||
SHA512 (pdfkit-0.5.0.zip) = 7d310d36503305bf71065b9b96bb313cb21f40ad7c347554b6f7a82e3d7ee8a7e3122ce54a522fbbacb5c50f0ddb72c9827bc0b38aa1ebea891e5c91b2668841
|
||||
SHA512 (pdfkit-0.6.1.tar.gz) = b3ac1016d1c01a2a196f567b9b672caca10f564cc6a62122691d34c3cbbf143f6a846bfba26c3474e9c0296977f0d30c0b5af13b3321ab207b787df3cba12e5d
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue