summaryrefslogtreecommitdiff
path: root/regtest
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2015-12-03 15:46:58 +0100
committerCarlos Garcia Campos <carlosgc@gnome.org>2015-12-03 15:46:58 +0100
commit3e22c678e749eda4402a7440b91b33d627705fdb (patch)
tree34685a69a2da6c9b42e060bf8e6601ae69cfc48a /regtest
parent50ba37c7b1aff14c73f158ff7f33d31953af512b (diff)
regtest: Add support for testing password protected documents
Similar to how skipped file works, you can pass a passwords file from the command line or add a Passwords file to your docs directory. This file should be a python file containing a "passwords" dictionary where the key is the test document and the value is the password required to open that document.
Diffstat (limited to 'regtest')
-rw-r--r--regtest/TestReferences.py7
-rw-r--r--regtest/TestRun.py11
-rw-r--r--regtest/Utils.py13
-rw-r--r--regtest/backends/__init__.py2
-rw-r--r--regtest/backends/cairo.py7
-rw-r--r--regtest/backends/postscript.py7
-rw-r--r--regtest/backends/splash.py7
-rw-r--r--regtest/backends/text.py7
-rw-r--r--regtest/main.py3
9 files changed, 49 insertions, 15 deletions
diff --git a/regtest/TestReferences.py b/regtest/TestReferences.py
index 4572ef69..05b08e24 100644
--- a/regtest/TestReferences.py
+++ b/regtest/TestReferences.py
@@ -21,7 +21,7 @@ import errno
from backends import get_backend, get_all_backends
from Config import Config
from Printer import get_printer
-from Utils import get_document_paths_from_dir, get_skipped_tests
+from Utils import get_document_paths_from_dir, get_skipped_tests, get_passwords
from Queue import Queue
from threading import Thread, RLock
@@ -32,6 +32,7 @@ class TestReferences:
self._docsdir = docsdir
self._refsdir = refsdir
self._skipped = get_skipped_tests(docsdir)
+ self._passwords = get_passwords(docsdir)
self.config = Config()
self.printer = get_printer()
self._total_tests = 1
@@ -73,6 +74,8 @@ class TestReferences:
raise
doc_path = os.path.join(self._docsdir, filename)
+ password = self._passwords.get(filename)
+
for backend in backends:
if not self.config.force and backend.has_results(refs_path):
with self._lock:
@@ -80,7 +83,7 @@ class TestReferences:
self.printer.print_default("Results found, skipping '%s' for %s backend" % (doc_path, backend.get_name()))
continue
- if backend.create_refs(doc_path, refs_path):
+ if backend.create_refs(doc_path, refs_path, password):
backend.create_checksums(refs_path, self.config.checksums_only)
with self._lock:
self._n_tests += 1
diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index 99b23ead..fc3f6a70 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, get_skipped_tests
+from Utils import get_document_paths_from_dir, get_skipped_tests, get_passwords
from Printer import get_printer
import sys
import os
@@ -34,6 +34,7 @@ class TestRun:
self._refsdir = refsdir
self._outdir = outdir
self._skip = get_skipped_tests(docsdir)
+ self._passwords = get_passwords(docsdir)
self.config = Config()
self.printer = get_printer()
self._total_tests = 1
@@ -68,7 +69,7 @@ class TestRun:
return get_all_backends()
- def test(self, refs_path, doc_path, test_path, backend):
+ def test(self, refs_path, doc_path, test_path, backend, password):
# First check whether there are test results for the backend
ref_has_md5 = backend.has_md5(refs_path)
ref_is_crashed = backend.is_crashed(refs_path)
@@ -80,7 +81,7 @@ class TestRun:
self.printer.print_default("Reference files not found, skipping '%s' for %s backend" % (doc_path, backend.get_name()))
return
- test_has_md5 = backend.create_refs(doc_path, test_path)
+ test_has_md5 = backend.create_refs(doc_path, test_path, password)
test_passed = False
if ref_has_md5 and test_has_md5:
test_passed = backend.compare_checksums(refs_path, test_path, not self.config.keep_results, self.config.create_diffs, self.config.update_refs)
@@ -165,8 +166,10 @@ class TestRun:
self.printer.print_default("Reference dir not found for %s, skipping" % (doc_path))
return
+ password = self._passwords.get(filename)
+
for backend in backends:
- self.test(refs_path, doc_path, out_path, backend)
+ self.test(refs_path, doc_path, out_path, backend, password)
def _worker_thread(self):
while True:
diff --git a/regtest/Utils.py b/regtest/Utils.py
index f491a6dd..cd1a572f 100644
--- a/regtest/Utils.py
+++ b/regtest/Utils.py
@@ -55,4 +55,17 @@ def get_skipped_tests(docsdir):
f.close()
return skipped
+def get_passwords(docsdir):
+ from Config import Config
+ config = Config()
+ if config.passwords_file:
+ passwords_file = config.passwords_file
+ elif os.path.exists(os.path.join(docsdir, 'Passwords')):
+ passwords_file = os.path.join(docsdir, 'Passwords')
+ else:
+ return {}
+
+ passwords = {}
+ execfile(passwords_file, passwords)
+ return passwords['passwords']
diff --git a/regtest/backends/__init__.py b/regtest/backends/__init__.py
index 95de1436..1287110f 100644
--- a/regtest/backends/__init__.py
+++ b/regtest/backends/__init__.py
@@ -287,7 +287,7 @@ class Backend:
def _create_diff(self, ref_path, result_path):
raise NotImplementedError
- def create_refs(self, doc_path, refs_path):
+ def create_refs(self, doc_path, refs_path, password = None):
raise NotImplementedError
_backends = {}
diff --git a/regtest/backends/cairo.py b/regtest/backends/cairo.py
index 3593342e..818ac3bc 100644
--- a/regtest/backends/cairo.py
+++ b/regtest/backends/cairo.py
@@ -26,9 +26,12 @@ class Cairo(Backend):
Backend.__init__(self, name, '.diff.png')
self._pdftocairo = os.path.join(self._utilsdir, 'pdftocairo');
- def create_refs(self, doc_path, refs_path):
+ def create_refs(self, doc_path, refs_path, password = None):
out_path = os.path.join(refs_path, 'cairo')
- p = subprocess.Popen([self._pdftocairo, '-cropbox', '-r', '72', '-png', doc_path, out_path], stderr = subprocess.PIPE)
+ cmd = [self._pdftocairo, '-cropbox', '-r', '72', '-png', doc_path, out_path]
+ if password is not None:
+ cmd.extend(['-opw', password])
+ p = subprocess.Popen(cmd, stderr = subprocess.PIPE)
return self._check_exit_status(p, out_path)
def _create_diff(self, ref_path, result_path):
diff --git a/regtest/backends/postscript.py b/regtest/backends/postscript.py
index 62360029..f9547cdf 100644
--- a/regtest/backends/postscript.py
+++ b/regtest/backends/postscript.py
@@ -26,9 +26,12 @@ class PostScript(Backend):
Backend.__init__(self, name)
self._pdftops = os.path.join(self._utilsdir, 'pdftops');
- def create_refs(self, doc_path, refs_path):
+ def create_refs(self, doc_path, refs_path, password = None):
out_path = os.path.join(refs_path, 'postscript')
- p = subprocess.Popen([self._pdftops, doc_path, out_path + '.ps'], stderr = subprocess.PIPE)
+ cmd = [self._pdftops, doc_path, out_path + '.ps']
+ if password is not None:
+ cmd.extend(['-opw', password])
+ p = subprocess.Popen(cmd, stderr = subprocess.PIPE)
return self._check_exit_status(p, out_path)
register_backend('postscript', PostScript)
diff --git a/regtest/backends/splash.py b/regtest/backends/splash.py
index aadbdec9..f107198a 100644
--- a/regtest/backends/splash.py
+++ b/regtest/backends/splash.py
@@ -26,9 +26,12 @@ class Splash(Backend):
Backend.__init__(self, name, '.diff.png')
self._pdftoppm = os.path.join(self._utilsdir, 'pdftoppm');
- def create_refs(self, doc_path, refs_path):
+ def create_refs(self, doc_path, refs_path, password = None):
out_path = os.path.join(refs_path, 'splash')
- p = subprocess.Popen([self._pdftoppm, '-cropbox', '-r', '72', '-png', doc_path, out_path], stderr = subprocess.PIPE)
+ cmd = [self._pdftoppm, '-cropbox', '-r', '72', '-png', doc_path, out_path]
+ if password is not None:
+ cmd.extend(['-opw', password])
+ p = subprocess.Popen(cmd, stderr = subprocess.PIPE)
return self._check_exit_status(p, out_path)
def _create_diff(self, ref_path, result_path):
diff --git a/regtest/backends/text.py b/regtest/backends/text.py
index 10b660a3..598aab8e 100644
--- a/regtest/backends/text.py
+++ b/regtest/backends/text.py
@@ -26,9 +26,12 @@ class Text(Backend):
Backend.__init__(self, name, '.diff')
self._pdftotext = os.path.join(self._utilsdir, 'pdftotext');
- def create_refs(self, doc_path, refs_path):
+ def create_refs(self, doc_path, refs_path, password = None):
out_path = os.path.join(refs_path, 'text')
- p = subprocess.Popen([self._pdftotext, doc_path, out_path + '.txt'], stderr = subprocess.PIPE)
+ cmd = [self._pdftotext, doc_path, out_path + '.txt']
+ if password is not None:
+ cmd.extend(['-opw', password])
+ p = subprocess.Popen([cmd, stderr = subprocess.PIPE)
return self._check_exit_status(p, out_path)
def _create_diff(self, ref_path, result_path):
diff --git a/regtest/main.py b/regtest/main.py
index 59b178b9..0febb79f 100644
--- a/regtest/main.py
+++ b/regtest/main.py
@@ -65,6 +65,9 @@ def main(args):
parser.add_argument('--skip', metavar = 'FILE',
action = 'store', dest = 'skipped_file',
help = 'File containing tests to skip')
+ parser.add_argument('-p', '--passwords', metavar = 'FILE',
+ action = 'store', dest = 'passwords_file',
+ help = 'File containing the documents passwords')
parser.add_argument('-t', '--threads',
action = 'store', dest = 'threads', type = int, default = n_cpus,
help = 'Number of worker threads (Default: %d)' % n_cpus)