1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

Merge remote-tracking branch 'origin/incoming' into wl

This commit is contained in:
Lu Wang 2014-11-20 16:29:46 +08:00
commit 899eeef3a4
9 changed files with 36 additions and 12 deletions

View File

@ -10,7 +10,7 @@ before_install:
- sudo pip install selenium sauceclient - sudo pip install selenium sauceclient
- export DISPLAY=:99.0 - export DISPLAY=:99.0
- test/start_xvfb.sh - test/start_xvfb.sh
- pushd test/browser_tests - pushd /
- python -m SimpleHTTPServer 8000 & - python -m SimpleHTTPServer 8000 &
- popd - popd
- sleep 5 - sleep 5

View File

@ -15,10 +15,16 @@
- `./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
- 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
### 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 +33,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

@ -21,9 +21,8 @@ BASEURL='http://localhost:8000/'
SAUCE_OPTIONS = { SAUCE_OPTIONS = {
'record-video': False, 'record-video': False,
'record-screenshots': False, 'record-screenshots': True,
'record-logs': False, 'record-logs': False,
'sauce-advisor': False,
} }
# we want to test the latest stable version # we want to test the latest stable version
@ -99,7 +98,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',