mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
working on unittest
use fontforge PPA in travis exluding test/ in the archive .. rewrite test_naming.py migrate old test_nameing.py to new unittest
This commit is contained in:
parent
2ca5ea6031
commit
22d19329c0
14
.gitignore
vendored
14
.gitignore
vendored
@ -3,20 +3,18 @@ CMakeFiles/*
|
|||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
gmon.out
|
gmon.out
|
||||||
Makefile
|
|
||||||
install_manifest.txt
|
install_manifest.txt
|
||||||
|
Makefile
|
||||||
pdf2htmlEX
|
pdf2htmlEX
|
||||||
pdf2htmlEX.1
|
pdf2htmlEX.1
|
||||||
|
*.pyc
|
||||||
share/base.css
|
share/base.css
|
||||||
|
share/base.min.css
|
||||||
share/fancy.css
|
share/fancy.css
|
||||||
share/js_src/css_class_names.js
|
share/fancy.min.css
|
||||||
share/pdf2htmlEX.js
|
share/pdf2htmlEX.js
|
||||||
|
share/pdf2htmlEX.min.js
|
||||||
src/pdf2htmlEX-config.h
|
src/pdf2htmlEX-config.h
|
||||||
src/util/css_const.h
|
src/util/css_const.h
|
||||||
test/*
|
test export-ignore
|
||||||
Testing/*
|
Testing/*
|
||||||
wiki/*
|
|
||||||
doc/*
|
|
||||||
/"\\"
|
|
||||||
/share/base.min.css
|
|
||||||
/share/fancy.min.css
|
|
||||||
|
10
.travis.yml
10
.travis.yml
@ -1,16 +1,10 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
before_install:
|
before_install:
|
||||||
|
- sudo add-apt-repository ppa:fontforge/fontforge --yes
|
||||||
- sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes
|
- sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -qq libpoppler-dev libspiro-dev libcairo-dev libfreetype6-dev libltdl-dev
|
- sudo apt-get install -qq libpoppler-dev libspiro-dev libcairo-dev libfreetype6-dev libltdl-dev libfontforge-dev libpango1.0-dev
|
||||||
install:
|
|
||||||
- export LIBRARY_PATH=/usr/local/lib
|
|
||||||
- export LD_LIBRARY_PATH=/usr/local/lib
|
|
||||||
- pushd ..
|
|
||||||
- wget 'https://github.com/coolwanglu/fontforge/archive/pdf2htmlEX.tar.gz' -O - | tar -zxf -
|
|
||||||
- pushd fontforge-pdf2htmlEX && ./autogen.sh && ./configure && make && sudo make install && popd
|
|
||||||
- popd
|
|
||||||
before_script:
|
before_script:
|
||||||
- cmake -DENABLE_SVG=ON .
|
- cmake -DENABLE_SVG=ON .
|
||||||
script:
|
script:
|
||||||
|
@ -203,5 +203,4 @@ install (FILES ${PDF2HTMLEX_RESOURCE} DESTINATION share/pdf2htmlEX)
|
|||||||
install (FILES pdf2htmlEX.1 DESTINATION share/man/man1)
|
install (FILES pdf2htmlEX.1 DESTINATION share/man/man1)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_test(test_naming
|
add_test(test python ${CMAKE_SOURCE_DIR}/test/test.py)
|
||||||
python ${CMAKE_SOURCE_DIR}/test/test_naming.py)
|
|
||||||
|
1
CTestCustom.cmake
Normal file
1
CTestCustom.cmake
Normal file
@ -0,0 +1 @@
|
|||||||
|
SET(CTEST_CUSTOM_POST_TEST "cat Testing/Temporary/LastTest.log")
|
@ -11,6 +11,7 @@
|
|||||||
#
|
#
|
||||||
# Special
|
# Special
|
||||||
# If a line contains """ only, all text until next """ will be included
|
# If a line contains """ only, all text until next """ will be included
|
||||||
|
# #TEST_IGNORE_BEGIN & #TEST_IGNORE_END are used for unittest
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# Declaration - Do not modify
|
# Declaration - Do not modify
|
||||||
@ -28,8 +29,12 @@
|
|||||||
# Styles
|
# Styles
|
||||||
# base CSS styles - Do not modify
|
# base CSS styles - Do not modify
|
||||||
@base.min.css
|
@base.min.css
|
||||||
|
|
||||||
# fancy CSS styles - Optional
|
# fancy CSS styles - Optional
|
||||||
|
#TEST_IGNORE_BEGIN
|
||||||
@fancy.min.css
|
@fancy.min.css
|
||||||
|
#TEST_IGNORE_END
|
||||||
|
|
||||||
# PDF specific CSS styles - Do not modify
|
# PDF specific CSS styles - Do not modify
|
||||||
$css
|
$css
|
||||||
|
|
||||||
@ -39,7 +44,9 @@ $css
|
|||||||
|
|
||||||
# compatibility.min.js, extracted from PDF.js
|
# compatibility.min.js, extracted from PDF.js
|
||||||
# To support old browsers like IE9
|
# To support old browsers like IE9
|
||||||
|
#TEST_IGNORE_BEGIN
|
||||||
@compatibility.min.js
|
@compatibility.min.js
|
||||||
|
#TEST_IGNORE_END
|
||||||
|
|
||||||
# entry point of pdf2htmlEX.Viewer
|
# entry point of pdf2htmlEX.Viewer
|
||||||
# You can override default configuration by passing an object to the constructor of Viewer
|
# You can override default configuration by passing an object to the constructor of Viewer
|
||||||
@ -48,6 +55,7 @@ $css
|
|||||||
# pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({
|
# pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({
|
||||||
# 'key_handler' : false
|
# 'key_handler' : false
|
||||||
# });
|
# });
|
||||||
|
#TEST_IGNORE_BEGIN
|
||||||
@pdf2htmlEX.min.js
|
@pdf2htmlEX.min.js
|
||||||
"""
|
"""
|
||||||
<script>
|
<script>
|
||||||
@ -56,6 +64,8 @@ try{
|
|||||||
}catch(e){}
|
}catch(e){}
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
|
#TEST_IGNORE_END
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# Do not modify
|
# Do not modify
|
||||||
@ -71,6 +81,8 @@ try{
|
|||||||
# You can add a class 'opened' here if you want it always opened or you don't use pdf2htmlEX.js
|
# You can add a class 'opened' here if you want it always opened or you don't use pdf2htmlEX.js
|
||||||
# e.g.
|
# e.g.
|
||||||
# <div id="sidebar" class="opened">
|
# <div id="sidebar" class="opened">
|
||||||
|
|
||||||
|
#TEST_IGNORE_BEGIN
|
||||||
"""
|
"""
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
"""
|
"""
|
||||||
@ -83,6 +95,7 @@ $outline
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
#TEST_IGNORE_END
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# The container of PDF pages
|
# The container of PDF pages
|
||||||
@ -100,6 +113,8 @@ $pages
|
|||||||
# shown when loading a page via ajax
|
# shown when loading a page via ajax
|
||||||
# The default appearance should be invisible
|
# The default appearance should be invisible
|
||||||
# The 'active' class will be added when it is used
|
# The 'active' class will be added when it is used
|
||||||
|
|
||||||
|
#TEST_IGNORE_BEGIN
|
||||||
"""
|
"""
|
||||||
<div class="loading-indicator">
|
<div class="loading-indicator">
|
||||||
"""
|
"""
|
||||||
@ -107,6 +122,7 @@ $pages
|
|||||||
"""
|
"""
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
#TEST_IGNORE_END
|
||||||
|
|
||||||
#############
|
#############
|
||||||
# Do not modify
|
# Do not modify
|
||||||
|
3
test/old/convert_to_woff.fontforge
Normal file
3
test/old/convert_to_woff.fontforge
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Open($1);
|
||||||
|
Generate($1:r+".woff");
|
||||||
|
Quit(0);
|
24
test/old/test.py
Executable file
24
test/old/test.py
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
DIR = 'pdf'
|
||||||
|
#DIR = '../../pdf.js/test/pdfs'
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
with open('out.html','w') as outf:
|
||||||
|
outf.write('<!DOCTYPE html>\n<html><head><meta charset=\"utf-8\"></head><body><div style="position:absolute;top:0;left:0;width:80%;height:100%;"><iframe width="100%" height="100%" name="pdf"></iframe></div><div style="position:absolute;top:0;right:0;width:20%;height:100%;overflow:auto;text-align:right;">')
|
||||||
|
|
||||||
|
for f in os.listdir(DIR):
|
||||||
|
if not f.lower().endswith('.pdf'):
|
||||||
|
continue
|
||||||
|
print f
|
||||||
|
if os.system('pdf2htmlEX -l 10 --no-drm 1 --fit-width 1024 --dest-dir html --external-hint-tool="ttfautohint" "%s/%s"' % (DIR,f)) != 0:
|
||||||
|
print "error on ", f
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
|
ff = f[:-3]
|
||||||
|
outf.write('<a href="html/%shtml" target="pdf">%s</a><br/>' % (ff,ff))
|
||||||
|
outf.flush();
|
||||||
|
|
||||||
|
outf.write('</div></body></html>')
|
96
test/test.py
96
test/test.py
@ -1,24 +1,88 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
DIR = 'pdf'
|
import unittest
|
||||||
#DIR = '../../pdf.js/test/pdfs'
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
with open('out.html','w') as outf:
|
class Common(object):
|
||||||
outf.write('<!DOCTYPE html>\n<html><head><meta charset=\"utf-8\"></head><body><div style="position:absolute;top:0;left:0;width:80%;height:100%;"><iframe width="100%" height="100%" name="pdf"></iframe></div><div style="position:absolute;top:0;right:0;width:20%;height:100%;overflow:auto;text-align:right;">')
|
SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
TEST_DIR = os.path.join(SRC_DIR, 'test')
|
||||||
|
DATA_DIR = os.path.join(SRC_DIR, 'share')
|
||||||
|
PDF2HTMLEX_PATH = os.path.join(SRC_DIR, 'pdf2htmlEX')
|
||||||
|
|
||||||
for f in os.listdir(DIR):
|
def setUp(self):
|
||||||
if not f.lower().endswith('.pdf'):
|
self.cur_temp_dir = tempfile.mkdtemp(prefix='pdf2htmlEX_test')
|
||||||
continue
|
self.cur_data_dir = os.path.join(self.cur_temp_dir, 'share')
|
||||||
print f
|
self.cur_output_dir = os.path.join(self.cur_temp_dir, 'out')
|
||||||
if os.system('pdf2htmlEX -l 10 --no-drm 1 --fit-width 1024 --dest-dir html --external-hint-tool="ttfautohint" "%s/%s"' % (DIR,f)) != 0:
|
os.mkdir(self.cur_data_dir)
|
||||||
print "error on ", f
|
os.mkdir(self.cur_output_dir)
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
ff = f[:-3]
|
# filter manifest
|
||||||
outf.write('<a href="html/%shtml" target="pdf">%s</a><br/>' % (ff,ff))
|
with open(os.path.join(self.DATA_DIR, 'manifest')) as inf:
|
||||||
outf.flush();
|
with open(os.path.join(self.cur_data_dir, 'manifest'), 'w') as outf:
|
||||||
|
ignore = False
|
||||||
|
for line in inf:
|
||||||
|
if ignore:
|
||||||
|
if line.startswith('#TEST_IGNORE_END'):
|
||||||
|
ignore = False
|
||||||
|
elif line.startswith('#TEST_IGNORE_BEGIN'):
|
||||||
|
ignore = True
|
||||||
|
else:
|
||||||
|
outf.write(line)
|
||||||
|
|
||||||
outf.write('</div></body></html>')
|
# copy files
|
||||||
|
shutil.copy(os.path.join(self.DATA_DIR, 'base.min.css'),
|
||||||
|
os.path.join(self.cur_data_dir, 'base.min.css'))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.cur_temp_dir, True)
|
||||||
|
|
||||||
|
def run_pdf2htmlEX(self, args):
|
||||||
|
"""
|
||||||
|
Execute the pdf2htmlEX with the specified arguments.
|
||||||
|
|
||||||
|
:type args: list of values
|
||||||
|
:param args: list of arguments to pass to executable.
|
||||||
|
:return: an object of relevant info
|
||||||
|
"""
|
||||||
|
|
||||||
|
cmd = [self.PDF2HTMLEX_PATH,
|
||||||
|
'--data-dir', self.cur_data_dir,
|
||||||
|
'--dest-dir', self.cur_output_dir
|
||||||
|
]
|
||||||
|
|
||||||
|
for val in args:
|
||||||
|
cmd.append(str(val))
|
||||||
|
|
||||||
|
return_code = subprocess.call(cmd)
|
||||||
|
self.assertEquals(return_code, 0)
|
||||||
|
|
||||||
|
files = os.listdir(self.cur_output_dir)
|
||||||
|
files.sort()
|
||||||
|
|
||||||
|
return {
|
||||||
|
'return_code' : return_code,
|
||||||
|
'output_files' : files
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if not os.path.isfile(Common.PDF2HTMLEX_PATH) or not os.access(Common.PDF2HTMLEX_PATH, os.X_OK):
|
||||||
|
print >> sys.stderr, "Cannot locate pdf2htmlEX executable. Make sure source was built before running this test."
|
||||||
|
exit(1)
|
||||||
|
suites = []
|
||||||
|
loader = unittest.TestLoader()
|
||||||
|
for module_name in ['test_naming']:
|
||||||
|
__import__(module_name)
|
||||||
|
suites.append(loader.loadTestsFromModule(sys.modules[module_name]))
|
||||||
|
|
||||||
|
failure_count = 0
|
||||||
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
|
for suite in suites:
|
||||||
|
result = runner.run(suite)
|
||||||
|
failure_count += len(result.errors) + len(result.failures)
|
||||||
|
|
||||||
|
exit(failure_count)
|
||||||
|
@ -1,264 +1,85 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Test --split-page and --page-filename
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import tempfile
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
# We assume that this file is put inside SRC_DIR/test
|
from test import Common
|
||||||
TEST_DIR = os.path.dirname(__file__)
|
|
||||||
# The location where our test PDFs are stored
|
|
||||||
TEST_DATA_DIR = os.path.join(TEST_DIR, 'test_data')
|
|
||||||
# The location where the base css file, etc is stored in the build folder
|
|
||||||
DATA_DIR = os.path.join(TEST_DIR, '../share')
|
|
||||||
|
|
||||||
# The script should be run in the directory containing the binary
|
class OutputNamingTests(Common, unittest.TestCase):
|
||||||
# The location where the executable is generated by the build
|
def run_test_case(self, input_file, expected_output_files, args=[]):
|
||||||
PDF2HTMLEX_PATH = './pdf2htmlEX'
|
args = list(args)
|
||||||
|
args.insert(0, os.path.join(self.TEST_DIR, 'test_naming', input_file))
|
||||||
|
self.assertEquals(self.run_pdf2htmlEX(args)['output_files'], sorted(expected_output_files))
|
||||||
|
|
||||||
|
|
||||||
def execute_pdf2htmlex_with_args(args):
|
|
||||||
"""
|
|
||||||
Execute the pdf2htmlEX with the specified arguments.
|
|
||||||
|
|
||||||
:type args: list of values
|
|
||||||
:param args: list of arguments to pass to executable. First part of each tuple is the argument, second part is the value.
|
|
||||||
|
|
||||||
:rtype: int
|
|
||||||
:return: The exit code of the command
|
|
||||||
"""
|
|
||||||
executable = os.path.abspath(PDF2HTMLEX_PATH)
|
|
||||||
|
|
||||||
cmd = [executable, '--data-dir', os.path.abspath(DATA_DIR)]
|
|
||||||
|
|
||||||
for val in args:
|
|
||||||
cmd.append(str(val))
|
|
||||||
|
|
||||||
return_code = subprocess.call(cmd)
|
|
||||||
|
|
||||||
if return_code != 0:
|
|
||||||
print >> sys.stderr, "Command return code %d: %s" % (return_code, ' '.join(cmd))
|
|
||||||
|
|
||||||
return return_code
|
|
||||||
|
|
||||||
def execute_pdf2htmlex_and_get_files(args):
|
|
||||||
"""
|
|
||||||
Execute the pdf2htmlEX with the specified arguments, and get the names of the output files. Will automatically create
|
|
||||||
a temporary directory for the output, pass that as the output dir to pdf2htmlEX, determine the files generated, and
|
|
||||||
clean up the temporary directory afterwards.
|
|
||||||
|
|
||||||
:type args: list of values
|
|
||||||
:param args: list of arguments to pass to executable. First part of each tuple is the argument, second part is the value.
|
|
||||||
|
|
||||||
:rtype: list of str
|
|
||||||
:return: List of the file names that were generated as output in alphabetical order. None if the command does not execute successfully.
|
|
||||||
"""
|
|
||||||
temp_dir = tempfile.mkdtemp()
|
|
||||||
|
|
||||||
try:
|
|
||||||
if execute_pdf2htmlex_with_args(['--dest-dir', temp_dir] + args) != 0:
|
|
||||||
return None
|
|
||||||
|
|
||||||
files = os.listdir(temp_dir)
|
|
||||||
files.sort()
|
|
||||||
return files
|
|
||||||
finally:
|
|
||||||
shutil.rmtree(path=temp_dir, ignore_errors=True)
|
|
||||||
|
|
||||||
def path_to_test_file(filename):
|
|
||||||
"""
|
|
||||||
Retrieve an absolute path to the specified test file.
|
|
||||||
|
|
||||||
:type filename:
|
|
||||||
:param filename: the name of the test file to get the path to
|
|
||||||
|
|
||||||
:rtype: str
|
|
||||||
:returns: the full path to the test file
|
|
||||||
"""
|
|
||||||
return os.path.abspath(os.path.join(TEST_DATA_DIR, filename))
|
|
||||||
|
|
||||||
class OutputNamingTests(unittest.TestCase):
|
|
||||||
def test_generate_single_html_default_name_single_page_pdf(self):
|
def test_generate_single_html_default_name_single_page_pdf(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('1-page.pdf', ['1-page.html'])
|
||||||
path_to_test_file('1-page.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['1-page.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_default_name_multiple_page_pdf(self):
|
def test_generate_single_html_default_name_multiple_page_pdf(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['2-pages.html'])
|
||||||
path_to_test_file('2-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['2-pages.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_specify_name_single_page_pdf(self):
|
def test_generate_single_html_specify_name_single_page_pdf(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('1-page.pdf', ['foo.html'], ['foo.html'])
|
||||||
path_to_test_file('1-page.pdf'),
|
|
||||||
'foo.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_specify_name_multiple_page_pdf(self):
|
def test_generate_single_html_specify_name_multiple_page_pdf(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['foo.html'], ['foo.html'])
|
||||||
path_to_test_file('2-pages.pdf'),
|
|
||||||
'foo.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo.html'])
|
|
||||||
|
|
||||||
def test_generate_split_pages_default_name_single_page(self):
|
def test_generate_split_pages_default_name_single_page(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('1-page.pdf', ['1-page.html', '1-page1.page'], ['--split-pages', 1])
|
||||||
'--split-pages', 1,
|
|
||||||
path_to_test_file('1-page.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['1-page.html', '1-page1.page']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_default_name_multiple_pages(self):
|
def test_generate_split_pages_default_name_multiple_pages(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', '3-pages1.page', '3-pages2.page', '3-pages3.page'], ['--split-pages', 1])
|
||||||
'--split-pages', 1,
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', '3-pages1.page', '3-pages2.page', '3-pages3.page']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_single_page(self):
|
def test_generate_split_pages_specify_name_single_page(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('1-page.pdf', ['1-page.html', 'foo1.xyz'], ['--split-pages', 1, '--page-filename', 'foo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'foo.xyz',
|
|
||||||
path_to_test_file('1-page.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['1-page.html', 'foo1.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_multiple_pages(self):
|
def test_generate_split_pages_specify_name_multiple_pages(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'foo1.xyz', 'foo2.xyz', 'foo3.xyz'], ['--split-pages', 1, '--page-filename', 'foo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'foo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'foo1.xyz', 'foo2.xyz', 'foo3.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_formatter_multiple_pages(self):
|
def test_generate_split_pages_specify_name_formatter_multiple_pages(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'fo1o.xyz', 'fo2o.xyz', 'fo3o.xyz'], ['--split-pages', 1, '--page-filename', 'fo%do.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'fo%do.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'fo1o.xyz', 'fo2o.xyz', 'fo3o.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_formatter_with_padded_zeros_multiple_pages(self):
|
def test_generate_split_pages_specify_name_formatter_with_padded_zeros_multiple_pages(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'fo001o.xyz', 'fo002o.xyz', 'fo003o.xyz'], ['--split-pages', 1, '--page-filename', 'fo%03do.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'fo%03do.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'fo001o.xyz', 'fo002o.xyz', 'fo003o.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_first_formatter_gets_taken(self):
|
def test_generate_split_pages_specify_name_only_first_formatter_gets_taken(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f1o%do.xyz', 'f2o%do.xyz', 'f3o%do.xyz'], ['--split-pages', 1, '--page-filename', 'f%do%do.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%do%do.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f1o%do.xyz', 'f2o%do.xyz', 'f3o%do.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_s(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_s(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%soo1.xyz', 'f%soo2.xyz', 'f%soo3.xyz'], ['--split-pages', 1, '--page-filename', 'f%soo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%soo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%soo1.xyz', 'f%soo2.xyz', 'f%soo3.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_p(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_p(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%poo1.xyz', 'f%poo2.xyz', 'f%poo3.xyz'], ['--split-pages', 1, '--page-filename', 'f%poo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%poo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%poo1.xyz', 'f%poo2.xyz', 'f%poo3.xyz']))
|
|
||||||
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_n(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_n(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%noo1.xyz', 'f%noo2.xyz', 'f%noo3.xyz'], ['--split-pages', 1, '--page-filename', 'f%noo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%noo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%noo1.xyz', 'f%noo2.xyz', 'f%noo3.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%%oo1.xyz', 'f%%oo2.xyz', 'f%%oo3.xyz'], ['--split-pages', 1, '--page-filename', 'f%%oo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%%oo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%%oo1.xyz', 'f%%oo2.xyz', 'f%%oo3.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent_with_actual_placeholder(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent_with_actual_placeholder(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%%o1o.xyz', 'f%%o2o.xyz', 'f%%o3o.xyz'], ['--split-pages', 1, '--page-filename', 'f%%o%do.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%%o%do.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%%o1o.xyz', 'f%%o2o.xyz', 'f%%o3o.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent_with_actual_placeholder(self):
|
def test_generate_split_pages_specify_name_only_percent_d_is_used_percent_percent_with_actual_placeholder(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'fo1o%%.xyz', 'fo2o%%.xyz', 'fo3o%%.xyz'], ['--split-pages', 1, '--page-filename', 'fo%do%%.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'fo%do%%.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf')
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'fo1o%%.xyz', 'fo2o%%.xyz', 'fo3o%%.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_name_only_formatter_starts_part_way_through_invalid_formatter(self):
|
def test_generate_split_pages_specify_name_only_formatter_starts_part_way_through_invalid_formatter(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('3-pages.pdf', ['3-pages.html', 'f%021oo.xyz', 'f%022oo.xyz', 'f%023oo.xyz'], ['--split-pages', 1, '--page-filename', 'f%02%doo.xyz'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'f%02%doo.xyz',
|
|
||||||
path_to_test_file('3-pages.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['3-pages.html', 'f%021oo.xyz', 'f%022oo.xyz', 'f%023oo.xyz']))
|
|
||||||
|
|
||||||
def test_generate_split_pages_specify_output_filename_no_formatter_no_extension(self):
|
def test_generate_split_pages_specify_output_filename_no_formatter_no_extension(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('1-page.pdf', ['1-page.html', 'foo1'], ['--split-pages', 1, '--page-filename', 'foo'])
|
||||||
'--split-pages', 1,
|
|
||||||
'--page-filename', 'foo',
|
|
||||||
path_to_test_file('1-page.pdf'),
|
|
||||||
])
|
|
||||||
self.assertEquals(files, sorted(['1-page.html', 'foo1']))
|
|
||||||
|
|
||||||
def test_generate_single_html_name_specified_format_characters_percent_d(self):
|
def test_generate_single_html_name_specified_format_characters_percent_d(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['foo%d.html'], ['foo%d.html'])
|
||||||
path_to_test_file('2-pages.pdf'),
|
|
||||||
'foo%d.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo%d.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_name_specified_format_characters_percent_p(self):
|
def test_generate_single_html_name_specified_format_characters_percent_p(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['foo%p.html'], ['foo%p.html'])
|
||||||
path_to_test_file('2-pages.pdf'),
|
|
||||||
'foo%p.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo%p.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_name_specified_format_characters_percent_n(self):
|
def test_generate_single_html_name_specified_format_characters_percent_n(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['foo%n.html'], ['foo%n.html'])
|
||||||
path_to_test_file('2-pages.pdf'),
|
|
||||||
'foo%n.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo%n.html'])
|
|
||||||
|
|
||||||
def test_generate_single_html_name_specified_format_characters_percent_percent(self):
|
def test_generate_single_html_name_specified_format_characters_percent_percent(self):
|
||||||
files = execute_pdf2htmlex_and_get_files([
|
self.run_test_case('2-pages.pdf', ['foo%%.html'], ['foo%%.html'])
|
||||||
path_to_test_file('2-pages.pdf'),
|
|
||||||
'foo%%.html'
|
|
||||||
])
|
|
||||||
self.assertEquals(files, ['foo%%.html'])
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
executable = os.path.abspath(PDF2HTMLEX_PATH)
|
|
||||||
if not os.path.isfile(executable) or not os.access(executable, os.X_OK):
|
|
||||||
print >> sys.stderr, "Cannot locate pdf2htmlEX executable. Make sure source was built before running this test."
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# we want to run pdf2htmlEX without installing it
|
|
||||||
shutil.copy(os.path.join(TEST_DIR, '../3rdparty/PDF.js/compatibility.min.js'), DATA_DIR)
|
|
||||||
unittest.main()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user