[poppler] 2 commits - regtest/commands regtest/main.py regtest/TestReferences.py regtest/TestRun.py regtest/Utils.py

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Tue Sep 13 11:13:44 PDT 2011


 regtest/TestReferences.py       |    9 +++++++--
 regtest/TestRun.py              |    9 +++++++--
 regtest/Utils.py                |   20 ++++++++++++++++++++
 regtest/commands/create-refs.py |   24 ++++++++++++------------
 regtest/commands/run-tests.py   |   26 +++++++++++++-------------
 regtest/main.py                 |    8 ++++++--
 6 files changed, 65 insertions(+), 31 deletions(-)

New commits:
commit da1b5437148e1e6317246b16f7235c8bc280be97
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Sep 13 20:09:56 2011 +0200

    regtest: Add a way to skip files
    
    A new command line option --skip has been added to give a file with the
    list of test to skip. When --skip is not used, it look for a file named
    Skipped in the tests dir. Lines starting with '#' are considered
    comments and are ignored.

diff --git a/regtest/TestReferences.py b/regtest/TestReferences.py
index 5d95e6f..042b0d4 100644
--- a/regtest/TestReferences.py
+++ b/regtest/TestReferences.py
@@ -20,13 +20,14 @@ import os
 import errno
 from backends import get_backend, get_all_backends
 from Config import Config
-from Utils import get_document_paths_from_dir
+from Utils import get_document_paths_from_dir, get_skipped_tests
 
 class TestReferences:
 
     def __init__(self, docsdir, refsdir):
         self._docsdir = docsdir
         self._refsdir = refsdir
+        self._skipped = get_skipped_tests(docsdir)
         self.config = Config()
 
         try:
@@ -38,6 +39,10 @@ class TestReferences:
             raise
 
     def create_refs_for_file(self, filename, n_doc = 1, total_docs = 1):
+        if filename in self._skipped:
+            print("Skipping test '%s' (%d/%d)" % (os.path.join(self._docsdir, filename), n_doc, total_docs))
+            return
+
         refs_path = os.path.join(self._refsdir, filename)
         try:
             os.makedirs(refs_path)
@@ -55,7 +60,7 @@ class TestReferences:
 
         for backend in backends:
             if not self.config.force and backend.has_md5(refs_path):
-                print "Checksum file found, skipping '%s' for %s backend" % (doc_path, backend.get_name())
+                print "Checksum file found, skipping '%s' for %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs)
                 continue
             print "Creating refs for '%s' using %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs)
             if backend.create_refs(doc_path, refs_path):
diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index 25e8fb7..ba74b1a 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -18,7 +18,7 @@
 
 from backends import get_backend, get_all_backends
 from Config import Config
-from Utils import get_document_paths_from_dir
+from Utils import get_document_paths_from_dir, get_skipped_tests
 import sys
 import os
 import errno
@@ -29,6 +29,7 @@ class TestRun:
         self._docsdir = docsdir
         self._refsdir = refsdir
         self._outdir = outdir
+        self._skipped = get_skipped_tests(docsdir)
         self.config = Config()
 
         # Results
@@ -105,6 +106,10 @@ class TestRun:
             return
 
     def run_test(self, filename, n_doc = 1, total_docs = 1):
+        if filename in self._skipped:
+            print("Skipping test '%s' (%d/%d)" % (os.path.join(self._docsdir, filename), n_doc, total_docs))
+            return
+
         out_path = os.path.join(self._outdir, filename)
         try:
             os.makedirs(out_path)
@@ -117,7 +122,7 @@ class TestRun:
         refs_path = os.path.join(self._refsdir, filename)
 
         if not os.path.isdir(refs_path):
-            print "Reference dir not found for %s, skipping" % (doc_path)
+            print "Reference dir not found for %s, skipping (%d/%d)" % (doc_path, n_doc, total_docs)
             return
 
         if self.config.backends:
diff --git a/regtest/Utils.py b/regtest/Utils.py
index 6656fac..90a6eea 100644
--- a/regtest/Utils.py
+++ b/regtest/Utils.py
@@ -32,4 +32,24 @@ def get_document_paths_from_dir(docsdir):
     paths.sort()
     return paths, n_paths
 
+def get_skipped_tests(docsdir):
+    from Config import Config
+    config = Config()
+    if config.skipped_file:
+        skipped_file = config.skipped_file
+    elif os.path.exists(os.path.join(docsdir, 'Skipped')):
+        skipped_file = os.path.join(docsdir, 'Skipped')
+    else:
+        return []
+
+    skipped = []
+    f = open(skipped_file, 'r')
+    for line in f.readlines():
+        line = line.rstrip('\n \t\b\r')
+        if not line or line[0] == '#':
+            continue
+        skipped.append(line)
+    f.close()
+    return skipped
+
 
diff --git a/regtest/main.py b/regtest/main.py
index 1254cae..4c8a390 100644
--- a/regtest/main.py
+++ b/regtest/main.py
@@ -49,11 +49,15 @@ def main(args):
     parser.add_argument('--help-command', metavar = 'COMMAND',
                         action = HelpAction,
                         help = 'Show help for a given command')
-    parser.add_argument('--utils-dir', action = 'store', dest = 'utils_dir', default = os.path.abspath("../utils"),
+    parser.add_argument('--utils-dir',
+                        action = 'store', dest = 'utils_dir', default = os.path.abspath("../utils"),
                         help = 'Directory of poppler utils used for the tests')
     parser.add_argument('-b', '--backends',
                         action = ListAction, dest = 'backends',
                         help = 'List of backends that will be used (separated by comma)')
+    parser.add_argument('--skip', metavar = 'FILE',
+                        action = 'store', dest = 'skipped_file',
+                        help = 'File containing tests to skip')
 
     ns, args = parser.parse_known_args(args)
     if not args:
commit b730b2c1d9666f62f940762663c8318e64049d61
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Tue Sep 13 19:04:04 2011 +0200

    regtest: Limit the number of arguments to 1
    
    It's easier to run poppler-regtest more than once if you need to run
    different tests.

diff --git a/regtest/commands/create-refs.py b/regtest/commands/create-refs.py
index 4c5034b..081a7e8 100644
--- a/regtest/commands/create-refs.py
+++ b/regtest/commands/create-refs.py
@@ -26,7 +26,7 @@ import tempfile
 class CreateRefs(Command):
 
     name = 'create-refs'
-    usage_args = '[ options ... ] documents ... '
+    usage_args = '[ options ... ] tests '
     description = 'Create references for tests'
 
     def __init__(self):
@@ -41,7 +41,7 @@ class CreateRefs(Command):
         parser.add_argument('-c', '--checksums-only',
                             action = 'store_true', dest = 'checksums_only', default = False,
                             help = 'Leave only checksum files in references dir, other files will be deleted')
-        parser.add_argument('documents', nargs='*')
+        parser.add_argument('tests')
 
     def run(self, options):
         config = Config()
@@ -49,17 +49,17 @@ class CreateRefs(Command):
         config.checksums_only = options['checksums_only']
 
         t = Timer()
-        for doc in options['documents']:
-            if os.path.isdir(doc):
-                docs_dir = doc
-            else:
-                docs_dir = os.path.dirname(doc)
+        doc = options['tests']
+        if os.path.isdir(doc):
+            docs_dir = doc
+        else:
+            docs_dir = os.path.dirname(doc)
 
-            refs = TestReferences(docs_dir, options['refs_dir'])
-            if doc == docs_dir:
-                refs.create_refs()
-            else:
-                refs.create_refs_for_file(os.path.basename(doc))
+        refs = TestReferences(docs_dir, options['refs_dir'])
+        if doc == docs_dir:
+            refs.create_refs()
+        else:
+            refs.create_refs_for_file(os.path.basename(doc))
         print "Refs created in %s" % (t.elapsed_str())
 
 register_command('create-refs', CreateRefs)
diff --git a/regtest/commands/run-tests.py b/regtest/commands/run-tests.py
index b97b34b..2c564c7 100644
--- a/regtest/commands/run-tests.py
+++ b/regtest/commands/run-tests.py
@@ -26,7 +26,7 @@ import tempfile
 class RunTests(Command):
 
     name = 'run-tests'
-    usage_args = '[ options ... ] documents ... '
+    usage_args = '[ options ... ] tests '
     description = 'Run tests for documents'
 
     def __init__(self):
@@ -44,7 +44,7 @@ class RunTests(Command):
         parser.add_argument('--create-diffs',
                             action = 'store_true', dest = 'create_diffs', default = False,
                             help = 'Create diff files for failed tests')
-        parser.add_argument('documents', nargs='*')
+        parser.add_argument('tests')
 
     def run(self, options):
         config = Config()
@@ -52,18 +52,18 @@ class RunTests(Command):
         config.create_diffs = options['create_diffs']
 
         t = Timer()
-        for doc in options['documents']:
-            if os.path.isdir(doc):
-                docs_dir = doc
-            else:
-                docs_dir = os.path.dirname(doc)
+        doc = options['tests']
+        if os.path.isdir(doc):
+            docs_dir = doc
+        else:
+            docs_dir = os.path.dirname(doc)
 
-            tests = TestRun(docs_dir, options['refs_dir'], options['out_dir'])
-            if doc == docs_dir:
-                tests.run_tests()
-            else:
-                tests.run_test(os.path.basename(doc))
-            tests.summary()
+        tests = TestRun(docs_dir, options['refs_dir'], options['out_dir'])
+        if doc == docs_dir:
+            tests.run_tests()
+        else:
+            tests.run_test(os.path.basename(doc))
+        tests.summary()
         print "Tests run in %s" % (t.elapsed_str())
 
 register_command('run-tests', RunTests)
diff --git a/regtest/main.py b/regtest/main.py
index 5784f5a..1254cae 100644
--- a/regtest/main.py
+++ b/regtest/main.py
@@ -42,7 +42,7 @@ def main(args):
     parser = argparse.ArgumentParser(
         description = 'Poppler regression tests',
         prog = 'poppler-regtest',
-        usage = '%(prog)s [options ...] command [command-options ...] tests ...',
+        usage = '%(prog)s [options ...] command [command-options ...] tests',
         add_help = False)
     parser.add_argument('-h', '--help',
                         action = HelpAction, nargs = 0)


More information about the poppler mailing list