| 1 |
#!/usr/bin/python |
|---|
| 2 |
# (C) Copyright 2003-2006 Nuxeo SAS <http://nuxeo.com> |
|---|
| 3 |
# |
|---|
| 4 |
# Authors: |
|---|
| 5 |
# Laurent Godard (lgodard@indesko.com) |
|---|
| 6 |
# |
|---|
| 7 |
# This program is free software; you can redistribute it and/or modify |
|---|
| 8 |
# it under the terms of the GNU General Public License version 2 as published |
|---|
| 9 |
# by the Free Software Foundation. |
|---|
| 10 |
# |
|---|
| 11 |
# This program is distributed in the hope that it will be useful, |
|---|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
# GNU General Public License for more details. |
|---|
| 15 |
# |
|---|
| 16 |
# You should have received a copy of the GNU General Public License |
|---|
| 17 |
# along with this program; if not, write to the Free Software |
|---|
| 18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|---|
| 19 |
# 02111-1307, USA. |
|---|
| 20 |
# |
|---|
| 21 |
# See ``COPYING`` for more information |
|---|
| 22 |
# |
|---|
| 23 |
# $Id$ |
|---|
| 24 |
|
|---|
| 25 |
import zipfile |
|---|
| 26 |
import os, os.path |
|---|
| 27 |
import tempfile |
|---|
| 28 |
|
|---|
| 29 |
test_cases= [{'input_file': 'input/test.sxw', |
|---|
| 30 |
'expected_dir': 'output/sxw.out'}, |
|---|
| 31 |
|
|---|
| 32 |
{'input_file': 'input/test.odt', |
|---|
| 33 |
'expected_dir': 'output/odt.out'}, |
|---|
| 34 |
] |
|---|
| 35 |
|
|---|
| 36 |
def ooo2dbk_tester(input_file, expected_dir): |
|---|
| 37 |
|
|---|
| 38 |
target_dir = tempfile.mkdtemp(prefix='ooo2dbk-test-') |
|---|
| 39 |
|
|---|
| 40 |
command = '../ooo2dbk -d %s %s' % (os.path.join(target_dir,'test.docb.xml'), |
|---|
| 41 |
input_file) |
|---|
| 42 |
print command |
|---|
| 43 |
os.system(command) |
|---|
| 44 |
|
|---|
| 45 |
status = True |
|---|
| 46 |
|
|---|
| 47 |
# are all the images processed ? |
|---|
| 48 |
expected_images_dir = os.path.join(expected_dir, 'images') |
|---|
| 49 |
for image in os.listdir(expected_images_dir): |
|---|
| 50 |
image_to_find = os.path.join(expected_images_dir, image) |
|---|
| 51 |
if os.path.isfile(image_to_find): #to avoid .svn dir |
|---|
| 52 |
expect = os.path.join(target_dir, 'images', image) |
|---|
| 53 |
if not os.path.isfile(expect): |
|---|
| 54 |
status = status and False |
|---|
| 55 |
print 'image %s not found' % image |
|---|
| 56 |
|
|---|
| 57 |
# compare docbook files ? |
|---|
| 58 |
f = open(os.path.join(expected_dir, 'test.docb.xml')) |
|---|
| 59 |
model = '\n'.join(f.readlines()) |
|---|
| 60 |
f.close() |
|---|
| 61 |
g = open(os.path.join(target_dir, 'test.docb.xml')) |
|---|
| 62 |
computed = '\n'.join(g.readlines()) |
|---|
| 63 |
g.close() |
|---|
| 64 |
|
|---|
| 65 |
if computed != model: |
|---|
| 66 |
status = False |
|---|
| 67 |
print "docbook files are different !" |
|---|
| 68 |
command = ("diff -u %s %s" % |
|---|
| 69 |
(os.path.join(expected_dir, 'test.docb.xml'), |
|---|
| 70 |
os.path.join(target_dir, 'test.docb.xml') |
|---|
| 71 |
) |
|---|
| 72 |
) |
|---|
| 73 |
os.system(command) |
|---|
| 74 |
|
|---|
| 75 |
# clean temp file |
|---|
| 76 |
os.system('rmdir --ignore-fail-on-non-empty %s' % target_dir) |
|---|
| 77 |
|
|---|
| 78 |
return status |
|---|
| 79 |
|
|---|
| 80 |
if __name__ == '__main__': |
|---|
| 81 |
|
|---|
| 82 |
for test in test_cases: |
|---|
| 83 |
print '--------------------' |
|---|
| 84 |
status = ooo2dbk_tester(test['input_file'], test['expected_dir']) |
|---|
| 85 |
if status: |
|---|
| 86 |
result = 'PASS' |
|---|
| 87 |
else: |
|---|
| 88 |
result = 'FAIL' |
|---|
| 89 |
print "\n%s on %s" %(result, test['input_file']) |
|---|