2 # -*- coding: utf-8 -*-
4 # file src/tex2lyx/test/runtests.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
10 # Full author contact details are available in file CREDITS
12 # This script is a very basic test suite runner for tex2lyx
13 # The defaults for optional command line arguments are tailored to the
14 # standard use case of testing without special build settings like a version
15 # suffix, since I don't know how to transport command line arguments through
16 # the autotools "make check" mechanism.
18 import os, string, sys, time, difflib, filecmp, subprocess, re
21 return "Usage: %s [<tex2lyx binary> [[<script dir>] [[<output dir>] [testfile]]]]" % prog_name
25 # Parse and manipulate the command line arguments.
27 sys.path.append(os.path.join(sys.argv[2]))
29 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../lib/scripts'))
31 from lyxpreview_tools import error
40 lyx = os.path.join(os.path.dirname(tex2lyx), "lyx")
41 inputdir = os.path.dirname(argv[0])
43 outputdir = sys.argv[3]
45 # outputdir = inputdir
46 outputdir = os.path.join(os.path.dirname(tex2lyx), "test")
51 files = ['test.ltx', 'test-structure.tex', 'test-insets.tex', \
52 'test-modules.tex', 'box-color-size-space-align.tex', \
53 'CJK.tex', 'XeTeX-polyglossia.tex']
56 overwrite = (outputdir == inputdir)
58 (base, ext) = os.path.splitext(f)
59 texfile = os.path.join(inputdir, f)
61 cmd = '%s -roundtrip -f %s' % (tex2lyx, texfile)
63 lyxfile = os.path.join(outputdir, base + ".lyx")
64 cmd = '%s -roundtrip -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
65 proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
68 errorstring = proc.stderr.read()
69 if not errorstring is None:
74 lyxfile1 = os.path.join(inputdir, base + ".lyx.lyx")
75 lyxfile2 = os.path.join(outputdir, base + ".lyx")
76 if not filecmp.cmp(lyxfile1, lyxfile2, False):
77 t1 = time.ctime(os.path.getmtime(lyxfile1))
78 t2 = time.ctime(os.path.getmtime(lyxfile2))
79 f1 = open(lyxfile1, 'r')
80 f2 = open(lyxfile2, 'r')
81 lines1 = f1.readlines()
82 lines2 = f2.readlines()
83 diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
86 sys.stdout.writelines(diff)
90 error('Converting the following files failed: %s' % ', '.join(errors))
92 if __name__ == "__main__":