diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3fdabb0..4cad847 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -215,5 +215,19 @@ set(PDF2HTMLEX_RESOURCE
install (FILES ${PDF2HTMLEX_RESOURCE} DESTINATION share/pdf2htmlEX)
install (FILES pdf2htmlEX.1 DESTINATION share/man/man1)
-enable_testing()
-add_test(test python ${CMAKE_SOURCE_DIR}/test/test.py)
+## tests:
+
+set(PDF2HTMLEX_PATH ${CMAKE_BINARY_DIR}/pdf2htmlEX)
+set(PDF2HTMLEX_TMPDIR /tmp/pdf2htmlEX/tmp)
+set(PDF2HTMLEX_DATDIR /tmp/pdf2htmlEX/dat)
+set(PDF2HTMLEX_PNGDIR /tmp/pdf2htmlEX/png)
+set(PDF2HTMLEX_OUTDIR /tmp/pdf2htmlEX/out)
+file(MAKE_DIRECTORY ${PDF2HTMLEX_TMPDIR})
+file(MAKE_DIRECTORY ${PDF2HTMLEX_DATDIR})
+file(MAKE_DIRECTORY ${PDF2HTMLEX_PNGDIR})
+file(MAKE_DIRECTORY ${PDF2HTMLEX_OUTDIR})
+configure_file(${CMAKE_SOURCE_DIR}/test/test.py.in ${CMAKE_SOURCE_DIR}/test/test.py)
+
+include(CTest)
+add_test(test_basic python ${CMAKE_SOURCE_DIR}/test/test_output.py)
+add_test(test_browser python ${CMAKE_SOURCE_DIR}/test/test_local_browser.py)
diff --git a/test/README.md b/test/README.md
index e6b1225..9370d8f 100644
--- a/test/README.md
+++ b/test/README.md
@@ -5,24 +5,21 @@
- Selenium
- unittest
- Firefox
+ - firefoxdriver
### Usage
- Run all tests:
- - `./test.py`
-- Run selected test suites:
- - `./test.py test_local_browser`
-- Run selected test case:
- - `./test.py test_local_browser.test_basic_text`
- - Or `./test.py test_basic_text`
+ - python test_output.py
+ - python test_local_browser.py
- Environment variables:
- - Set `P2H_TEST_SAVE_TMP=1` to keep the temporary files in `/tmp/pdf2htmlEX_test`
- - Set `P2H_TEST_GEN=1` to generate new reference files
- - Set `P2H_TEST_REMOTE=1` to test different browsers using Sauce Labs
+ - `export P2H_TEST_GEN=1` to generate new reference files (when done, `unset P2H_TEST_GEN`)
+ - `export P2H_TEST_REMOTE=1` to test different browsers using Sauce Labs
- Install `sauceclient` for Python
- Set correct values for `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY`
- Setup a HTTP server at `/` on port 8000
- Enable Sauce Connect
- See `.travis.yml` as an example
+ - python test_remote_browser.py
### Add new test cases
@@ -35,4 +32,3 @@
- [Optional] Include the source files that the PDF file is generated from.
- Add the new PDF file to the correct folder in `test/`, and add a new function in the corresponding Python file
- Run `P2H_TEST_GEN=1 test/test.py test_issueXXX` to generate the reference, assuming that the new function is called `test_issueXXX`
-
diff --git a/test/browser_tests.py b/test/browser_tests.py
index 08931c5..c1880a9 100644
--- a/test/browser_tests.py
+++ b/test/browser_tests.py
@@ -14,7 +14,7 @@ class BrowserTests(Common):
DEFAULT_PDF2HTMLEX_ARGS = [
'--fit-width', 800,
'--last-page', 1,
- '--embed', 'fi', # avoid base64 to make it faster
+ # avoid base64 to make it faster
]
BROWSER_WIDTH=800
@@ -28,42 +28,35 @@ class BrowserTests(Common):
def tearDownClass(cls):
pass
- def run_test_case(self, filename, pdf2htmlEX_args=[], page_must_load=True):
+ def run_test_case(self, filename, args=[], page_must_load=True):
basefilename, extension = os.path.splitext(filename)
- htmlfilename = basefilename + '.html'
-
- ref_htmlfolder = os.path.join(self.TEST_DATA_DIR, basefilename)
- ref_htmlfilename = os.path.join(ref_htmlfolder, htmlfilename)
-
- out_htmlfilename = os.path.join(self.cur_output_dir, htmlfilename)
-
self.assertEquals(extension.lower(), '.pdf', 'Input file is not PDF')
- pdf2htmlEX_args = self.DEFAULT_PDF2HTMLEX_ARGS \
- + list(pdf2htmlEX_args) + [
- os.path.join(self.TEST_DATA_DIR, filename),
- htmlfilename
- ]
+ htmlfilename = basefilename + '.html'
+ ref_htmlfolder = os.path.join(self.TEST_DATA_DIR, basefilename)
+ ref_htmlfilename = os.path.join(ref_htmlfolder, htmlfilename)
+ out_htmlfilename = os.path.join(self.OUTDIR, htmlfilename)
+ pdf2htmlEX_args = self.DEFAULT_PDF2HTMLEX_ARGS + args + [
+ os.path.join(self.TEST_DATA_DIR, filename),
+ htmlfilename ]
result = self.run_pdf2htmlEX(pdf2htmlEX_args)
+
self.assertIn(htmlfilename, result['output_files'], 'HTML file is not generated')
if self.GENERATING_MODE:
# copy generated html files
shutil.rmtree(ref_htmlfolder, True)
- shutil.copytree(self.cur_output_dir, ref_htmlfolder)
+ shutil.copytree(self.OUTDIR, ref_htmlfolder)
return
- png_out_dir = os.path.join(self.cur_temp_dir, 'png_out')
- os.mkdir(png_out_dir)
+ pngfilename_out = os.path.join(self.PNGDIR, basefilename + '.out.png')
+ self.generate_image(out_htmlfilename, pngfilename_out)
+ out_img = Image.open(pngfilename_out)
- pngfilename_out_fullpath = os.path.join(png_out_dir, basefilename + '.out.png')
- self.generate_image(out_htmlfilename, pngfilename_out_fullpath)
- out_img = Image.open(pngfilename_out_fullpath)
-
- pngfilename_ref_fullpath = os.path.join(png_out_dir, basefilename + '.ref.png')
- self.generate_image(ref_htmlfilename, pngfilename_ref_fullpath, page_must_load=page_must_load)
- ref_img = Image.open(pngfilename_ref_fullpath)
+ pngfilename_ref = os.path.join(self.PNGDIR, basefilename + '.ref.png')
+ self.generate_image(ref_htmlfilename, pngfilename_ref, page_must_load=page_must_load)
+ ref_img = Image.open(pngfilename_ref)
diff_img = ImageChops.difference(ref_img, out_img);
@@ -71,11 +64,13 @@ class BrowserTests(Common):
if diff_bbox is not None:
diff_size = (diff_bbox[2] - diff_bbox[0]) * (diff_bbox[3] - diff_bbox[1])
img_size = ref_img.size[0] * ref_img.size[1]
- if self.SAVE_TMP:
- # save the diff image
- # http://stackoverflow.com/questions/15721484/saving-in-png-using-pil-library-after-taking-imagechops-difference-of-two-png
- diff_img.convert('RGB').save(os.path.join(png_out_dir, basefilename + '.diff.png'))
- self.fail('PNG files differ by <= %d pixels, (%f%% of %d pixels in total)' % (diff_size, 1.0*diff_size/img_size, img_size))
+ # save the diff image (http://stackoverflow.com/questions/15721484):
+ diff_file_name = os.path.join(self.PNGDIR, basefilename + '.diff.png')
+ diff_img.convert('RGB').save(diff_file_name)
+ self.fail(('PNG files %s and %s differ by at most %d pixels, '+
+ '(%f%% of %d pixels in total), difference: %s') %
+ (pngfilename_out, pngfilename_ref,
+ diff_size, 100.0*diff_size/img_size, img_size, diff_file_name))
@unittest.skipIf(Common.GENERATING_MODE, 'Do not auto generate reference for test_fail')
def test_fail(self):
diff --git a/test/browser_tests/basic_text/basic_text.html b/test/browser_tests/basic_text/basic_text.html
index 171d451..39bf871 100644
--- a/test/browser_tests/basic_text/basic_text.html
+++ b/test/browser_tests/basic_text/basic_text.html
@@ -19,8 +19,8 @@