1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 01:28:39 +00:00

imporving tests[ci skip]

This commit is contained in:
Lu Wang 2014-11-20 12:19:45 +08:00
parent 52807ca27e
commit 3df6a8a893
8 changed files with 33 additions and 9 deletions

View File

@ -15,10 +15,15 @@
- `./test.py test_local_browser.test_basic_text` - `./test.py test_local_browser.test_basic_text`
- Or `./test.py test_basic_text - Or `./test.py test_basic_text
- Environment variables: - Environment variables:
- set `P2H_TEST_SAVE_TMP=1` to keep the temporary files in `/tmp/pdf2htmlEX_test` - 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_GEN=1` to generate new reference files
- Set `P2H_TEST_REMOTE=1` to test different browsers using Sauce Labs
- 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
### Guidelines for test cases ### Add new test cases
- Make sure you have the proper copyrights. - Make sure you have the proper copyrights.
- Using meaningful file names, a description of the file, or issueXXX.pdf. - Using meaningful file names, a description of the file, or issueXXX.pdf.
@ -27,4 +32,6 @@
- Grayscale only, unless the test case is about colors. - Grayscale only, unless the test case is about colors.
- Remove unnecessary elements. - Remove unnecessary elements.
- [Optional] Include the source files that the PDF file is generated from. - [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`

View File

@ -3,6 +3,7 @@
import os import os
import subprocess import subprocess
import shutil import shutil
import unittest
from PIL import Image, ImageChops from PIL import Image, ImageChops
from test import Common from test import Common
@ -73,6 +74,14 @@ class BrowserTests(Common):
diff_img.crop(diff_img.getbbox()).convert('RGB').save(os.path.join(png_out_dir, basefilename + '.diff.png')) diff_img.crop(diff_img.getbbox()).convert('RGB').save(os.path.join(png_out_dir, basefilename + '.diff.png'))
self.fail('PNG files differ') self.fail('PNG files differ')
@unittest.skipIf(Common.GENERATING_MODE, 'Do not auto generate reference for test_fail')
def test_fail(self):
# The HTML reference is generated manually, which mismatches the PDF
# To test if the environment can detect any errors
# E.g. when network is down, 404 message is shown for any HTML message
with self.assertRaises(AssertionError):
self.run_test_case('test_fail.pdf')
def test_basic_text(self): def test_basic_text(self):
self.run_test_case('basic_text.pdf') self.run_test_case('basic_text.pdf')

Binary file not shown.

View File

@ -0,0 +1,9 @@
\documentclass{article}
\begin{document}
\Huge
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
The quick brown fox jumps over the lazy dog
\end{document}

View File

@ -13,8 +13,8 @@ class Common(object):
DATA_DIR = os.path.join(SRC_DIR, 'share') DATA_DIR = os.path.join(SRC_DIR, 'share')
PDF2HTMLEX_PATH = os.path.join(SRC_DIR, 'pdf2htmlEX') PDF2HTMLEX_PATH = os.path.join(SRC_DIR, 'pdf2htmlEX')
SAVE_TMP = os.environ.get('P2H_TEST_SAVE_TMP') SAVE_TMP = bool(os.environ.get('P2H_TEST_SAVE_TMP'))
GENERATING_MODE = os.environ.get('P2H_TEST_GEN') GENERATING_MODE = bool(os.environ.get('P2H_TEST_GEN'))
CANONICAL_TEMPDIR = '/tmp/pdf2htmlEX_test' CANONICAL_TEMPDIR = '/tmp/pdf2htmlEX_test'
@ -91,7 +91,7 @@ if __name__ == '__main__':
all_modules.append(__import__('test_local_browser')) all_modules.append(__import__('test_local_browser'))
all_classes = ['test_output', 'test_local_browser'] all_classes = ['test_output', 'test_local_browser']
if os.environ.get('P2H_TEST_REMOTE'): if bool(os.environ.get('P2H_TEST_REMOTE')):
m = __import__('test_remote_browser') m = __import__('test_remote_browser')
all_modules.append(m) all_modules.append(m)
all_classes += m.test_classnames all_classes += m.test_classnames

View File

@ -7,10 +7,9 @@ import os
from test import Common from test import Common
@unittest.skipIf(Common.GENERATING_MODE, 'Skipping test_output in generating mode')
class test_output(Common, unittest.TestCase): class test_output(Common, unittest.TestCase):
def run_test_case(self, input_file, expected_output_files, args=[]): def run_test_case(self, input_file, expected_output_files, args=[]):
if self.GENERATING_MODE:
self.skipTest("Skipping test_output test cases in generating mode")
args = list(args) args = list(args)
args.insert(0, os.path.join(self.TEST_DIR, 'test_output', input_file)) args.insert(0, os.path.join(self.TEST_DIR, 'test_output', input_file))
self.assertItemsEqual(self.run_pdf2htmlEX(args)['output_files'], expected_output_files) self.assertItemsEqual(self.run_pdf2htmlEX(args)['output_files'], expected_output_files)

View File

@ -99,7 +99,7 @@ class test_remote_browser_base(BrowserTests):
branch = os.environ.get('TRAVIS_BRANCH', 'manual') branch = os.environ.get('TRAVIS_BRANCH', 'manual')
pull_request = os.environ.get('TRAVIS_PULL_REQUEST') pull_request = os.environ.get('TRAVIS_PULL_REQUEST')
self.sauce.jobs.update_job(self.browser.session_id, self.sauce.jobs.update_job(self.browser.session_id,
build_num=os.environ.get('TRAVIS_BUILD_NUMBER', 0), build_num=os.environ.get('TRAVIS_BUILD_NUMBER', '0'),
name='pdf2htmlEX', name='pdf2htmlEX',
passed=passed, passed=passed,
public='public restricted', public='public restricted',