diff --git a/.travis.yml b/.travis.yml index cc1a79e..f382248 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,15 +4,20 @@ before_install: - sudo add-apt-repository ppa:fontforge/fontforge --yes - sudo add-apt-repository ppa:coolwanglu/pdf2htmlex --yes - sudo apt-get update -qq - - sudo apt-get install -qq libpoppler-dev libpoppler-private-dev libspiro-dev libcairo-dev libpango1.0-dev libfreetype6-dev libltdl-dev libfontforge-dev python-imaging wkhtmltopdf + - sudo apt-get install -qq libpoppler-dev libpoppler-private-dev libspiro-dev libcairo-dev libpango1.0-dev libfreetype6-dev libltdl-dev libfontforge-dev python-imaging python-pip ttfautohint firefox xvfb + - sudo pip install selenium + - export DISPLAY=:99.0 + - test/start_xvfb.sh + - sleep 5 before_script: - cmake -DENABLE_SVG=ON . script: - make - - make test + - ctest --output-on-failure - sudo make install - /usr/local/bin/pdf2htmlEX -v branches: only: - master - incoming + - travis diff --git a/CMakeLists.txt b/CMakeLists.txt index f17578b..b1f5413 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,20 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif() -include(CheckCXXCompilerFlag) -check_cxx_compiler_flag("${CMAKE_CXX_FLAGS}" CXX0X_SUPPORT) +# check the C++11 features we need +include(CheckCXXSourceCompiles) +check_cxx_source_compiles(" +#include +int main() +{ + char * ptr = nullptr; + std::vector v; + auto f = [&](){ for(auto & i : v) ++i; }; + f(); +} +" CXX0X_SUPPORT) if(NOT CXX0X_SUPPORT) - message(FATAL_ERROR "Error: your compiler does not support C++0x, please update it.") + message(FATAL_ERROR "Error: your compiler does not support C++0x/C++11, please update it.") endif() diff --git a/CTestCustom.cmake b/CTestCustom.cmake deleted file mode 100644 index f8c87fb..0000000 --- a/CTestCustom.cmake +++ /dev/null @@ -1 +0,0 @@ -SET(CTEST_CUSTOM_POST_TEST "cat Testing/Temporary/LastTest.log") diff --git a/README.md b/README.md index f48e7bb..3b49cb7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ->一图胜千言
A beautiful demo is worth a thousand words: +>一图胜千言
A beautiful demo is worth a thousand words - **Bible de Genève, 1564** (fonts and typography): [HTML](http://coolwanglu.github.com/pdf2htmlEX/demo/geneve.html) / [PDF](https://github.com/raphink/geneve_1564/raw/master/geneve_1564.pdf) - **Cheat Sheet** (math formulas): [HTML](http://coolwanglu.github.com/pdf2htmlEX/demo/cheat.html) / [PDF](http://www.tug.org/texshowcase/cheat.pdf) diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 0000000..d72fd52 --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1 @@ +*.pdf binary diff --git a/test/README.md b/test/README.md index 9b7bc7b..c8c2dde 100644 --- a/test/README.md +++ b/test/README.md @@ -1,14 +1,18 @@ ### Dependencies -- wkhtmltoimage -- python2 -- Python Imaging Library +- python2 and packages + - Python Imaging Library + - Selenium + - unittest +- Firefox ### Usage - Run all tests: - `./test.py` -- Run selected tests: - - `./test.py test_A test_B ...` +- Run selected test suites: + - `./test.py test_local_browser` +- Run selected test case: + - `./test.py test_basic_text - Environment variables: - set `P2H_TEST_SAVE_TMP=1` to keep the temporary files - set `P2H_TEST_GEN=1` to generate new reference images instead of comparing with old ones @@ -21,6 +25,5 @@ - One page only, unless the test case is about multiple pages. - Grayscale only, unless the test case is about colors. - Remove unnecessary elements. - - Set proper parameters for cropping in `wkhtml2image_args`. - [Optional] Include the source files that the PDF file is generated from. diff --git a/test/browser_tests.py b/test/browser_tests.py new file mode 100644 index 0000000..ea2ded6 --- /dev/null +++ b/test/browser_tests.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +import unittest +import os +import subprocess +import shutil + +from PIL import Image, ImageChops +from test import Common + +class BrowserTests(Common): + TTFAUTOHINT = 'ttfautohint' + TEST_DATA_DIR = os.path.join(Common.TEST_DIR, 'browser_tests') + + DEFAULT_PDF2HTMLEX_ARGS = [ + '--external-hint-tool', 'ttfautohint', + '--fit-width', 800, + '--last-page', 1, + '--correct-text-visibility', 1, + '--embed', 'fi', # avoid base64 to make it faster + ] + + BROWSER_WIDTH=800 + BROWSER_HEIGHT=1200 + + @classmethod + def setUpClass(cls): + exit_code = subprocess.call([cls.TTFAUTOHINT, '--version']) + assert (exit_code == 0), 'Cannot execute ' + cls.TTFAUTOHINT + + @classmethod + def tearDownClass(cls): + pass + + def run_test_case(self, filename, pdf2htmlEX_args=[]): + 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 + ] + + 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) + return + + png_out_dir = os.path.join(self.cur_temp_dir, 'png_out') + os.mkdir(png_out_dir) + + 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) + ref_img = Image.open(pngfilename_ref_fullpath) + + diff_img = ImageChops.difference(ref_img, out_img); + + if diff_img.getbbox() is not None: + 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') + + def test_basic_text(self): + self.run_test_case('basic_text.pdf') + + def test_geneve_1564(self): + self.run_test_case('geneve_1564.pdf') + + def test_text_visibility(self): + self.run_test_case('text_visibility.pdf') + diff --git a/test/test_conversion/basic_text.pdf b/test/browser_tests/basic_text.pdf similarity index 100% rename from test/test_conversion/basic_text.pdf rename to test/browser_tests/basic_text.pdf diff --git a/test/test_conversion/basic_text.tex b/test/browser_tests/basic_text.tex similarity index 100% rename from test/test_conversion/basic_text.tex rename to test/browser_tests/basic_text.tex diff --git a/test/browser_tests/basic_text/basic_text.html b/test/browser_tests/basic_text/basic_text.html new file mode 100644 index 0000000..6376103 --- /dev/null +++ b/test/browser_tests/basic_text/basic_text.html @@ -0,0 +1,107 @@ + + + + + + + + + + + + + +
+
Normal tiny Text
Rise
CharSpace
Horizontal Scale
Rotated
Rise
CharSpace
Horizontal Scale
1
+
+ + diff --git a/test/browser_tests/basic_text/f1.woff b/test/browser_tests/basic_text/f1.woff new file mode 100644 index 0000000..e021d44 Binary files /dev/null and b/test/browser_tests/basic_text/f1.woff differ diff --git a/test/browser_tests/basic_text/f2.woff b/test/browser_tests/basic_text/f2.woff new file mode 100644 index 0000000..749ebec Binary files /dev/null and b/test/browser_tests/basic_text/f2.woff differ diff --git a/test/test_conversion/geneve_1564.pdf b/test/browser_tests/geneve_1564.pdf similarity index 100% rename from test/test_conversion/geneve_1564.pdf rename to test/browser_tests/geneve_1564.pdf diff --git a/test/browser_tests/geneve_1564/bg1.png b/test/browser_tests/geneve_1564/bg1.png new file mode 100644 index 0000000..78d4782 Binary files /dev/null and b/test/browser_tests/geneve_1564/bg1.png differ diff --git a/test/browser_tests/geneve_1564/f1.woff b/test/browser_tests/geneve_1564/f1.woff new file mode 100644 index 0000000..0d5ac60 Binary files /dev/null and b/test/browser_tests/geneve_1564/f1.woff differ diff --git a/test/browser_tests/geneve_1564/f2.woff b/test/browser_tests/geneve_1564/f2.woff new file mode 100644 index 0000000..1df880c Binary files /dev/null and b/test/browser_tests/geneve_1564/f2.woff differ diff --git a/test/browser_tests/geneve_1564/geneve_1564.html b/test/browser_tests/geneve_1564/geneve_1564.html new file mode 100644 index 0000000..df19e00 --- /dev/null +++ b/test/browser_tests/geneve_1564/geneve_1564.html @@ -0,0 +1,738 @@ + + + + + + + + + + + + + +
+
1
Le premier lire de Moyſe,
Di Geneſe.
.
Ce premier lire comprend l’origine caſes de totes choſes, principalement la creation de l’homme, q’il a eſté d
commencement, ſa chete releement : comment d’n tos ont eſté procreés, por lers enormes pechés Die
les a conſmés, par le delge, reſeré hi, dont la ſemence a rempli tote la terre. Pis il deſcrit les ies, fais, reli-
gion, lignees des ſaints Patriarches, qi ont eſc deant la Loy : Les benediions, promees, alliances d Sei-
gner faies aecicex : Comment de le la terre de Chanaan ſont deſcends en Epte. Acns ont appelé ce lire, le
lire des Iſtes. Totefois ceci a obten entre nos predeceers nos, q’il eſt appelé Geneſe, qi eſt n mot Grec,
gnifiant generation origine : d’atant q’en iceli eſt deſcrite l’origine procreation de totes choſes : nom-
mément des Peres anciens, qi ont eſté tant deant q’apres le delge, e eſgard à deſcen-
d d’icex ſelon la chair.
.
I
Creation d ciel de la terre, II, 10. de tot ce qi y eſt
comprins. 3.14. De la lmiere a, 26 de l’homme, 18
qel tot eſt abietti. 2.2. 18 Die benit totes ſes œ-
res, 31 q’il a accomplies en x iors.
1
Ie
a
crea
b
a com
mence -
ment
c
le
ciel & la
terre.
2 Or la
terre eſ-
toit ſans
forme, &
vide, & les tenebres eſtoyent ſr les
abyſmes : & l’Eſprit de Die
d
eſtoit
eſpand par des les eax.
3 Adonc Die dît,
2
’il y ait lmie-
re.
e
Et la lmiere ft.
4 Et Die vid q
̃
la lmiere eſtoit bon-
ne : & ſepara la lmiere des tenebres.
5 Et Die appela la lmiere ior,& les
tenebres ni. Lors ft fai le
f
ſoir &
le matin d premier ior.
6 Pis Die dît,
3
’il y ait ne
g
eſ-
tende entre les eax, & qelle ſepare
les
h
eax daec les eax.
7 Die donc fit leſtende, & diiſa
I
Ce premier cha-
pitre eſt fort diffi-
cile : & por cette
caſe, il eſtoit de-
fend entre les He
briex de le lire &
interpreter deant
laage de trente
ans.
a
Fit de rien, &
ſans acne ma-
tiere.
1
Iob 38.4, Pſea.
33.6, 89.12.,
135.5, Eccleſtiaſti.
13.1, A. 14-15,
17.14
b
Tot premiere-
ment, & aãt q’il
y et acne crea-
tre, Iean 1.10.
2
Hebr. 11.3.
c
Le ciel & la
terre, les eax, les
abyſmes, ſe pren-
nent ici por vne
meſme choſe : aſç.
por ne matiere
cõfſe & ſans for-
me, q
̃
Die forma
& agença apres
par ſa Parole.
d
O, ſe mo-
voit. Ceſt, ſoſte-
noit et conſeroit
en ſon eſtre cette
matiere confſe.
Car il eſt impo-
ble, q
̃
acne cho-
ſe apres aoir eſté
faies,pie ſb-
ſter n ſel mo-
ment, Die ne la
ſoſtient & cõſer-
ve par ſa vert,
Pſea. 130.
e
Cette lmiere
neſtoit point en-
core a ſoleil, car
il naoit pas eſté
creé, mais eſtoit en
la main de Die,
ayãt ſon ordre ſc-
cef aec les tene-
bres, por faire le
ior & la ni &
ce iſqes a qa-
trieme ior, qe
Die fit le ſoleil
por eſtre miniſtre
& diſpenſater de
cette lmiere, aec
la lne & eſtoilles.
3
Pſea. 33.6,
136.5.
Ierem. 10.11
51.15.
f
Ici eſt la caſe
les eax, qi eſtoyent ſos leſtende,
daec celles, qi eſtoyent ſr leſten-
de. Et ft ain fai.
8 EtDie appela leſtende, Ciel. Lors
ft fai le ſoir & le matin d ſecond
ior.
9 Pis Die dît,
4 i
e les eax, qi
ſont ſos le ciel, ſoyent aemblees en
n lie, & qe le ſec apparoie. Et ft
ain fai.
10 EtDie appeꝉale ſec,Terre,& laem
blee des eax, mers. Et Die vid qe
celà eſtoit bon.
11 Et Die dît, e la terre prodiſe
verdre, herbe prodiſant ſemence, &
arbre friier, faiſant fri ſelon ſon
eſpece, leqel ait ſa ſemẽce en ſoy-meſ-
me ſr la terre. Et ft ain fai.
12 La terre dõc prodit verdre, her-
be prodiſant ſemẽce ſelon ſon eſpece,
& arbre ſans fri, leqel aoit ſa
ſemence en ſoymeſme ſelon ſon eſpe-
ce. Et Die vid qe celà eſtoit bon.
13 Lors ft fai le ſoir & le matin d
troieme ior.
14 Apres Die dît,
5 k
’il y ait lmi
naires en leſtende d ciel, por ſepa-
rer la ni d ior : & ſoyẽt en
l
gnes,
a en
porqoy les He-
briex cõmencent
le ior natrel le
ſoir apres le ſoleil
cochant.
g
Ce mot d’Eſtẽ
de, comprẽd tot
ce qi ſe voit par
des nos, tãt en
la region celeſte,
qelementaire.
4
Pſea. 33.7.
h
Il eſt ici parlé
de dex manieres
deax : asçaoir,
celles q ſont ſos
leſtende, comme
la mer, les flees,
& atres qi ſont
ſr la terre & cel-
les, qi ſont ſr
leſtende, comme
ſont les nees plei-
nes dea ça hat
en lair par des
nos. Die a mis
entre ces dex for
ces deax ne grã
de eſtende, qon
appelle le ciel : de
nos appelons
les oiſeax d ciel.
i
Ceci appartiẽt a
ſecõd ior, aqel
Die ſepara, & fit
apparoir la terre d
milie des eax.
k
Il inſtite n
noel ordre en
natre, qand il
fat & ordonne le
ſoleil diſtribter
de cette lmiere
q’il aoit creée
aant li, & aant
la lne & les eſ-
toilles.
5
Pſea. 136.7
l
Ceſt por -
gnifier dierſes di-
ſpotions qe les
corps ĩferiers ſe-
lon lordre de na-
tre ont des corps
celeſtes, cõme ca
ſes ſecõdes ordon
nees de Die à ce-
là. En qoy to-
teſfois fat fir c-
rioté & ſperſti-
tion q
̃
les hõmes
ont cõtroee ſr
celà.
+
+ + diff --git a/test/test_conversion/text_visibility.pdf b/test/browser_tests/text_visibility.pdf similarity index 100% rename from test/test_conversion/text_visibility.pdf rename to test/browser_tests/text_visibility.pdf diff --git a/test/browser_tests/text_visibility/bg1.png b/test/browser_tests/text_visibility/bg1.png new file mode 100644 index 0000000..63d8b89 Binary files /dev/null and b/test/browser_tests/text_visibility/bg1.png differ diff --git a/test/browser_tests/text_visibility/f1.woff b/test/browser_tests/text_visibility/f1.woff new file mode 100644 index 0000000..ae656c4 Binary files /dev/null and b/test/browser_tests/text_visibility/f1.woff differ diff --git a/test/browser_tests/text_visibility/f2.woff b/test/browser_tests/text_visibility/f2.woff new file mode 100644 index 0000000..6ec5264 Binary files /dev/null and b/test/browser_tests/text_visibility/f2.woff differ diff --git a/test/browser_tests/text_visibility/text_visibility.html b/test/browser_tests/text_visibility/text_visibility.html new file mode 100644 index 0000000..25f457e --- /dev/null +++ b/test/browser_tests/text_visibility/text_visibility.html @@ -0,0 +1,153 @@ + + + + + + + + + + + + + +
+
ecient ecient
ecient ecient
e cient
e cient
ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient wordspace ecient
cient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
cient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
ecient ecient ecient
+
+ + diff --git a/test/start_xvfb.sh b/test/start_xvfb.sh new file mode 100755 index 0000000..9664154 --- /dev/null +++ b/test/start_xvfb.sh @@ -0,0 +1,2 @@ +#!/bin/sh +/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1920x16 diff --git a/test/test.py b/test/test.py index 85db25e..dc60464 100755 --- a/test/test.py +++ b/test/test.py @@ -14,6 +14,8 @@ class Common(object): PDF2HTMLEX_PATH = os.path.join(SRC_DIR, 'pdf2htmlEX') SAVE_TMP = os.environ.get('P2H_TEST_SAVE_TMP') + GENERATING_MODE = os.environ.get('P2H_TEST_GEN') + CANONICAL_TEMPDIR = '/tmp/pdf2htmlEX_test' def setUp(self): @@ -83,14 +85,23 @@ if __name__ == '__main__': exit(1) suites = [] loader = unittest.TestLoader() - test_names = list(map(lambda x: 'T.'+x, sys.argv[1:])) - for module_name in ['test_naming', 'test_conversion']: + all_modules = ['test_output', 'test_local_browser'] + test_names = [] + for name in sys.argv[1:]: + if name in all_modules or name.find('.') != -1: + test_names.append(name) + else: + for m in all_modules: + test_names.append(m + '.' + name) + + for module_name in all_modules: __import__(module_name) if len(test_names) > 0: - try: - suites.append(loader.loadTestsFromNames(test_names, sys.modules[module_name])) - except: - pass + for n in test_names: + try: + suites.append(loader.loadTestsFromName(n, sys.modules[module_name])) + except: + pass else: suites.append(loader.loadTestsFromModule(sys.modules[module_name])) diff --git a/test/test_conversion.py b/test/test_conversion.py deleted file mode 100755 index ab2b70c..0000000 --- a/test/test_conversion.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python - -import unittest -import os -import subprocess - -from PIL import Image, ImageChops -from test import Common - -class T(Common, unittest.TestCase): - GENERATING_MODE = os.environ.get('P2H_TEST_GEN') - - WKHTML2IMAGE = 'wkhtmltoimage' - TTFAUTOHINT = 'ttfautohint' - TEST_DATA_DIR = os.path.join(Common.TEST_DIR, 'test_conversion') - - DEFAULT_PDF2HTMLEX_ARGS = [ - '--external-hint-tool', 'ttfautohint', - '--fit-width', 800, - '--last-page', 1, - '--correct-text-visibility', 1, - ] - - DEFAULT_WKHTML2IMAGE_ARGS = [ - '-f', 'png', - '--height', 600, - '--width', 800, - '--quality', 0, - '--quiet' - ] - - @classmethod - def setUpClass(cls): - subprocess.check_call([cls.WKHTML2IMAGE, '--version']) - subprocess.check_call([cls.TTFAUTOHINT, '--version']) - - def run_test_case(self, filename, pdf2htmlEX_args=[], wkhtml2image_args=[]): - basefilename, extension = os.path.splitext(filename) - htmlfilename = basefilename + '.html' - pngfilename = basefilename + '.png' - - 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 - ] - - result = self.run_pdf2htmlEX(pdf2htmlEX_args) - self.assertIn(htmlfilename, result['output_files'], 'HTML file is not generated') - - png_out_dir = os.path.join(self.cur_temp_dir, 'png_out') - os.mkdir(png_out_dir) - - pngfilename_out_fullpath = os.path.join(png_out_dir, pngfilename) - pngfilename_raw_fullpath = os.path.join(self.TEST_DATA_DIR, pngfilename) - - wkhtml2image_args = [self.WKHTML2IMAGE] \ - + self.DEFAULT_WKHTML2IMAGE_ARGS \ - + list(wkhtml2image_args) + [ - os.path.join(self.cur_output_dir, htmlfilename), - pngfilename_out_fullpath - ] - - return_code = subprocess.call(list(map(str, wkhtml2image_args))) - self.assertEquals(return_code, 0, 'cannot execute ' + self.WKHTML2IMAGE) - - if self.GENERATING_MODE: - shutil.copy(pngfilename_out_fullpath, pngfilename_raw_fullpath) - else: - original_img = Image.open(pngfilename_raw_fullpath) - new_img = Image.open(pngfilename_out_fullpath) - - diff_img = ImageChops.difference(original_img, new_img); - - if diff_img.getbbox() is not None: - 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') - - def test_basic_text(self): - self.run_test_case('basic_text.pdf', - wkhtml2image_args=[ - '--crop-x', 180, - '--crop-y', 150, - '--crop-w', 220, - '--crop-h', 260 - ]) - - def test_geneve_1564(self): - self.run_test_case('geneve_1564.pdf', wkhtml2image_args=['--height', 1100]) - - def test_text_visibility(self): - self.run_test_case('text_visibility.pdf', wkhtml2image_args=['--height', 1200]) - diff --git a/test/test_conversion/basic_text.png b/test/test_conversion/basic_text.png deleted file mode 100644 index 9451e11..0000000 Binary files a/test/test_conversion/basic_text.png and /dev/null differ diff --git a/test/test_conversion/geneve_1564.png b/test/test_conversion/geneve_1564.png deleted file mode 100644 index c768327..0000000 Binary files a/test/test_conversion/geneve_1564.png and /dev/null differ diff --git a/test/test_conversion/text_visibility.png b/test/test_conversion/text_visibility.png deleted file mode 100644 index 1456678..0000000 Binary files a/test/test_conversion/text_visibility.png and /dev/null differ diff --git a/test/test_local_browser.py b/test/test_local_browser.py new file mode 100755 index 0000000..2545463 --- /dev/null +++ b/test/test_local_browser.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import unittest +import os +import subprocess +import shutil + +from PIL import Image, ImageChops +from selenium import webdriver +from browser_tests import BrowserTests + +class test_local_browser(BrowserTests, unittest.TestCase): + @classmethod + def setUpClass(cls): + super(test_local_browser, cls).setUpClass() + if not cls.GENERATING_MODE: + cls.browser = webdriver.Firefox() + cls.browser.maximize_window() + size = cls.browser.get_window_size() + assert ((size['width'] >= cls.BROWSER_WIDTH) and (size['height'] >= cls.BROWSER_HEIGHT)), 'Screen is not large enough' + cls.browser.set_window_size(cls.BROWSER_WIDTH, cls.BROWSER_HEIGHT) + + @classmethod + def tearDownClass(cls): + if not cls.GENERATING_MODE: + cls.browser.quit() + super(test_local_browser, cls).tearDownClass() + + def generate_image(self, html_file, png_file): + assert not self.GENERATING_MODE + self.browser.get('file://' + html_file) + self.browser.save_screenshot(png_file) + diff --git a/test/test_naming.py b/test/test_output.py similarity index 95% rename from test/test_naming.py rename to test/test_output.py index add17f8..741cd82 100644 --- a/test/test_naming.py +++ b/test/test_output.py @@ -1,16 +1,18 @@ #!/usr/bin/env python -# Test --split-page and --page-filename +# Test output files import unittest import os from test import Common -class T(Common, unittest.TestCase): +class test_output(Common, unittest.TestCase): 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.insert(0, os.path.join(self.TEST_DIR, 'test_naming', 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) def test_generate_single_html_default_name_single_page_pdf(self): diff --git a/test/test_naming/1-page.pdf b/test/test_output/1-page.pdf similarity index 100% rename from test/test_naming/1-page.pdf rename to test/test_output/1-page.pdf diff --git a/test/test_naming/2-pages.pdf b/test/test_output/2-pages.pdf similarity index 100% rename from test/test_naming/2-pages.pdf rename to test/test_output/2-pages.pdf diff --git a/test/test_naming/3-pages.pdf b/test/test_output/3-pages.pdf similarity index 100% rename from test/test_naming/3-pages.pdf rename to test/test_output/3-pages.pdf