]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/test/runtests.py
Reduce caption hardcoding
[lyx.git] / src / tex2lyx / test / runtests.py
index 2ff7adf2e75a234b3e33fa31cd7eff1ecc000960..8d053acd1f6f28a79ff344bf88e5e0372d0c2087 100755 (executable)
@@ -20,6 +20,17 @@ import os, string, sys, time, difflib, filecmp, subprocess, re
 def usage(prog_name):
   return "Usage: %s [uselyx2lyx] [<tex2lyx binary> [[<script dir>] [[<output dir>] [testfile]]]]" % prog_name
 
+pat_fl1 = re.compile(r'^#LyX file created by tex2lyx .*$')
+pat_fl2 = re.compile(r'^#LyX \d+\.\d+ created this file.*$')
+
+def compareLyx(lines1, lines2):
+    if lines1[1:] != lines2[1:]:
+        return False
+    if not pat_fl1.match(lines1[0]) and not pat_fl2.match(lines1[0]):
+        return False
+    if not pat_fl1.match(lines2[0]) and not pat_fl2.match(lines2[0]):
+        return False
+    return True
 
 def main(argv):
     # Parse and manipulate the command line arguments.
@@ -30,9 +41,9 @@ def main(argv):
             uselyx2lyx = True
             skipcount = 1
     if len(argv) >= 3+skipcount:
-       sys.path.append(os.path.join(sys.argv[2+skipcount]))
+        sys.path.append(os.path.join(sys.argv[2+skipcount]))
     else:
-       sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../lib/scripts'))
+        sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../../../lib/scripts'))
 
     from lyxpreview_tools import error
 
@@ -45,9 +56,9 @@ def main(argv):
 
     suffixre = re.search(r'\d+\.\d+$', tex2lyx)
     if suffixre:
-       suffix = suffixre.group()
+        suffix = suffixre.group()
     else:
-       suffix = ""
+        suffix = ""
     lyx = os.path.join(os.path.dirname(tex2lyx), "lyx" + suffix)
     inputdir = os.path.dirname(argv[0])
     if len(argv) >= 4+skipcount:
@@ -66,9 +77,11 @@ def main(argv):
                  'test-insets.tex', \
                  'test-modules.tex', \
                  'test-refstyle-theorems.tex', \
+                 'test-scr.tex', \
                  'test-structure.tex', \
                  'verbatim.tex', \
-                 'XeTeX-polyglossia.tex']
+                 'XeTeX-polyglossia.tex', \
+                 'algo2e.tex']
 
     errors = []
     overwrite = (outputdir == inputdir)
@@ -82,6 +95,7 @@ def main(argv):
         else:
             lyxfile = os.path.join(outputdir, base + ".lyx")
             cmd = '%s -roundtrip -copyfiles -f %s %s' % (tex2lyx, texfile, lyxfile)
+        print 'Executing: ' + cmd + "\n"
         proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         proc.wait()
         err = proc.returncode
@@ -102,18 +116,21 @@ def main(argv):
                           os.path.join(outputdir, base + ".lyx2.lyx"), uselyx2lyx)
                 if lyxfile2 is None:
                     errors.append(f)
-                elif not filecmp.cmp(lyxfile1, lyxfile2, False):
+                else:
                     t1 = time.ctime(os.path.getmtime(lyxfile1))
                     t2 = time.ctime(os.path.getmtime(lyxfile2))
                     f1 = open(lyxfile1, 'r')
                     f2 = open(lyxfile2, 'r')
                     lines1 = f1.readlines()
                     lines2 = f2.readlines()
-                    diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
                     f1.close()
                     f2.close()
-                    sys.stdout.writelines(diff)
-                    errors.append(f)
+                    # ignore the first line e.g. the version of lyx
+                    if not compareLyx(lines1, lines2):
+                        diff = difflib.unified_diff(lines1, lines2, lyxfile1, lyxfile2, t1, t2)
+                        sys.stdout.writelines(diff)
+                        errors.append(f)
+
 
     if len(errors) > 0:
         error('Converting the following files failed: %s' % ', '.join(errors))