mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
reactivated test_output.py, now directly called from 'ctest'
This commit is contained in:
parent
d3e29acd66
commit
e88f079e48
@ -218,5 +218,5 @@ install (FILES pdf2htmlEX.1 DESTINATION share/man/man1)
|
|||||||
include(CTest)
|
include(CTest)
|
||||||
set(PDF2HTMLEX_PATH ${CMAKE_BINARY_DIR}/pdf2htmlEX)
|
set(PDF2HTMLEX_PATH ${CMAKE_BINARY_DIR}/pdf2htmlEX)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/test/test.py.in ${CMAKE_SOURCE_DIR}/test/test.py)
|
configure_file(${CMAKE_SOURCE_DIR}/test/test.py.in ${CMAKE_SOURCE_DIR}/test/test.py)
|
||||||
add_test(test_basic python ${CMAKE_SOURCE_DIR}/test/test.py test_basic_text)
|
add_test(test_basic python ${CMAKE_SOURCE_DIR}/test/test_output.py)
|
||||||
add_test(test_browser python ${CMAKE_SOURCE_DIR}/test/test.py test_local_browser)
|
add_test(test_browser python ${CMAKE_SOURCE_DIR}/test/test.py test_local_browser)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
- Selenium
|
- Selenium
|
||||||
- unittest
|
- unittest
|
||||||
- Firefox
|
- Firefox
|
||||||
|
- firefoxdriver
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
- Run all tests:
|
- Run all tests:
|
||||||
|
132
test/test.py.in
Executable file
132
test/test.py.in
Executable file
@ -0,0 +1,132 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
class Common(object):
|
||||||
|
PDF2HTMLEX_PATH = "@PDF2HTMLEX_PATH@"
|
||||||
|
if not os.path.isfile(PDF2HTMLEX_PATH) or not os.access(PDF2HTMLEX_PATH, os.X_OK):
|
||||||
|
print >> sys.stderr, "Cannot locate pdf2htmlEX executable, expected at ", PDF2HTMLEX_PATH,
|
||||||
|
". Make sure source was built before running this test."
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
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')
|
||||||
|
|
||||||
|
SAVE_TMP = bool(os.environ.get('P2H_TEST_SAVE_TMP'))
|
||||||
|
GENERATING_MODE = bool(os.environ.get('P2H_TEST_GEN'))
|
||||||
|
|
||||||
|
CANONICAL_TEMPDIR = '/tmp/pdf2htmlEX_test'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
if not self.SAVE_TMP:
|
||||||
|
self.cur_temp_dir = tempfile.mkdtemp(prefix='pdf2htmlEX_test')
|
||||||
|
else:
|
||||||
|
shutil.rmtree(self.CANONICAL_TEMPDIR, True)
|
||||||
|
os.mkdir(self.CANONICAL_TEMPDIR)
|
||||||
|
self.cur_temp_dir = self.CANONICAL_TEMPDIR
|
||||||
|
|
||||||
|
self.cur_data_dir = os.path.join(self.cur_temp_dir, 'share')
|
||||||
|
self.cur_output_dir = os.path.join(self.cur_temp_dir, 'out')
|
||||||
|
os.mkdir(self.cur_data_dir)
|
||||||
|
os.mkdir(self.cur_output_dir)
|
||||||
|
|
||||||
|
# filter manifest
|
||||||
|
with open(os.path.join(self.DATA_DIR, 'manifest')) as inf:
|
||||||
|
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)
|
||||||
|
|
||||||
|
# copy files
|
||||||
|
shutil.copy(os.path.join(self.DATA_DIR, 'base.min.css'),
|
||||||
|
os.path.join(self.cur_data_dir, 'base.min.css'))
|
||||||
|
shutil.copy(os.path.join(self.TEST_DIR, 'fancy.min.css'),
|
||||||
|
os.path.join(self.cur_data_dir, 'fancy.min.css'))
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
if not self.SAVE_TMP:
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
args = [Common.PDF2HTMLEX_PATH,
|
||||||
|
'--data-dir', self.cur_data_dir,
|
||||||
|
'--dest-dir', self.cur_output_dir
|
||||||
|
] + args
|
||||||
|
|
||||||
|
with open(os.devnull, 'w') as fnull:
|
||||||
|
return_code = subprocess.call(list(map(str, args)), stderr=fnull)
|
||||||
|
|
||||||
|
self.assertEquals(return_code, 0, 'cannot execute pdf2htmlEX')
|
||||||
|
|
||||||
|
files = os.listdir(self.cur_output_dir)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'return_code' : return_code,
|
||||||
|
'output_files' : files
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
suites = []
|
||||||
|
loader = unittest.TestLoader()
|
||||||
|
|
||||||
|
all_classes = ['test_output', 'test_local_browser']
|
||||||
|
if bool(os.environ.get('P2H_TEST_REMOTE')):
|
||||||
|
all_classes += 'test_remote_browser'
|
||||||
|
|
||||||
|
all_modules = [ __import__(m) for m in all_classes ]
|
||||||
|
|
||||||
|
test_names = []
|
||||||
|
for name in sys.argv[1:]:
|
||||||
|
test_names.append(name)
|
||||||
|
if name.find('.') == -1:
|
||||||
|
for m in all_classes:
|
||||||
|
test_names.append(m + '.' + name)
|
||||||
|
|
||||||
|
print( 'TEST_NAMES -> ', test_names )
|
||||||
|
|
||||||
|
for module in all_modules:
|
||||||
|
if len(test_names) > 0 and module.__name__ not in test_names:
|
||||||
|
for n in test_names:
|
||||||
|
try:
|
||||||
|
suites.append(loader.loadTestsFromName(n, module))
|
||||||
|
print( "DEB2 ", n, module, ' ==> ', loader.loadTestsFromName(n, module))
|
||||||
|
except:
|
||||||
|
print "Catched error:", sys.exc_info()
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
suites.append(loader.loadTestsFromModule(module))
|
||||||
|
print( "DEB1 ", module, ' ==> ', loader.loadTestsFromModule(module))
|
||||||
|
|
||||||
|
if len(suites) == 0:
|
||||||
|
print >>sys.stderr, 'No test found'
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
failure_count = 0
|
||||||
|
runner = unittest.TextTestRunner(verbosity=2)
|
||||||
|
for suite in suites:
|
||||||
|
result = runner.run(suite)
|
||||||
|
print( 'SUITE ', suite, ' ---> ', result )
|
||||||
|
failure_count += len(result.errors) + len(result.failures)
|
||||||
|
|
||||||
|
exit(failure_count)
|
@ -16,6 +16,9 @@ class test_output(Common, unittest.TestCase):
|
|||||||
result = self.run_pdf2htmlEX(args)
|
result = self.run_pdf2htmlEX(args)
|
||||||
if expected_output_files:
|
if expected_output_files:
|
||||||
self.assertItemsEqual(result['output_files'], expected_output_files)
|
self.assertItemsEqual(result['output_files'], expected_output_files)
|
||||||
|
print("test_output ", input_file, ": matched ", expected_output_files)
|
||||||
|
else:
|
||||||
|
print("test_output ", input_file, ": passed")
|
||||||
|
|
||||||
def test_generate_single_html_default_name_single_page_pdf(self):
|
def test_generate_single_html_default_name_single_page_pdf(self):
|
||||||
self.run_test_case('1-page.pdf', expected_output_files = ['1-page.html'])
|
self.run_test_case('1-page.pdf', expected_output_files = ['1-page.html'])
|
||||||
@ -88,3 +91,6 @@ class test_output(Common, unittest.TestCase):
|
|||||||
|
|
||||||
def test_issue501(self):
|
def test_issue501(self):
|
||||||
self.run_test_case('issue501', ['--split-pages', 1, '--embed-css', 0]);
|
self.run_test_case('issue501', ['--split-pages', 1, '--embed-css', 0]);
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main() # runs all methods that have names starting with 'test'
|
||||||
|
Loading…
Reference in New Issue
Block a user