diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-03-29 18:35:54 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-04-03 08:23:44 +0200 |
commit | d76281864b0e83812c0edf7490b1e8271e89fff5 (patch) | |
tree | a84c6503db43cb3ec5c14bfc1849e11aa338fdd1 /unotest | |
parent | 20c680092fa2598feb4541b1c69a8389779dbae4 (diff) |
Create temp copies of test docs in Python/UITests
...where necessary, so the tests will succeed if SRCDIR is a read-only tree.
Change-Id: Iea4c52d5982d3eba079088ef1670ff557ce30c3f
Reviewed-on: https://gerrit.libreoffice.org/52122
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'unotest')
-rw-r--r-- | unotest/source/python/org/libreoffice/unotest.py | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/unotest/source/python/org/libreoffice/unotest.py b/unotest/source/python/org/libreoffice/unotest.py index a6a927ca881c..1d0beb737ccb 100644 --- a/unotest/source/python/org/libreoffice/unotest.py +++ b/unotest/source/python/org/libreoffice/unotest.py @@ -14,6 +14,9 @@ import time import uuid import argparse import os +import shutil +import urllib.parse +import urllib.request try: import pyuno @@ -210,20 +213,15 @@ class UnoInProcess: return self.openDocFromTDOC(file, True) def openDocFromTDOC(self, file, asTemplate = False): - path = os.getenv("TDOC") - if os.name == "nt": - # do not quote drive letter - it must be "X:" - url = "file:///" + path + "/" + quote(file) - else: - url = "file://" + quote(path) + "/" + quote(file) - return self.openDocFromURL(url, asTemplate) + path = makeCopyFromTDOC(file) + return self.openDocFromAbsolutePath(path, asTemplate) - def openDocFromAbsolutePath(self, file): + def openDocFromAbsolutePath(self, file, asTemplate = False): if os.name == "nt": url = "file:///" + file else: url = "file://" + file - return self.openDocFromURL(url) + return self.openDocFromURL(url, asTemplate) def openDocFromURL(self, url, asTemplate = False): props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", asTemplate)] @@ -285,6 +283,28 @@ def runConnectionTests(connection, invoker, tests): finally: connection.tearDown() +def makeCopyFromTDOC(file): + src = os.getenv("TDOC") + assert(src is not None) + src = os.path.join(src, file) + dst = os.getenv("TestUserDir") + assert(dst is not None) + uri = urllib.parse.urlparse(dst) + assert(uri.scheme.casefold() == "file") + assert(uri.netloc == "" or uri.netloc.casefold() == "localhost") + assert(uri.params == "") + assert(uri.query == "") + assert(uri.fragment == "") + dst = urllib.request.url2pathname(uri.path) + dst = os.path.join(dst, "tmp", file) + os.makedirs(os.path.dirname(dst), exist_ok=True) + try: + os.remove(dst) + except FileNotFoundError: + pass + shutil.copyfile(src, dst) + return dst + ### tests ### if __name__ == "__main__": |