[Libreoffice-commits] core.git: dbaccess/qa sw/qa unotest/source

Michael Stahl mstahl at redhat.com
Thu Sep 7 19:46:46 UTC 2017


 dbaccess/qa/python/fdo84315.py                   |    2 
 sw/qa/python/check_cross_references.py           |    2 
 sw/qa/python/check_fields.py                     |    2 
 sw/qa/python/check_flies.py                      |    2 
 sw/qa/python/text_portion_enumeration_test.py    |    6 +-
 unotest/source/python/org/libreoffice/unotest.py |   63 ++++++-----------------
 6 files changed, 25 insertions(+), 52 deletions(-)

New commits:
commit 01b0d6da7ffdbd0eeea601020329c82fa1b37c11
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Sep 7 21:26:02 2017 +0200

    unotest.py: refactor confusing mess of openDoc functions
    
    Change-Id: I148332c639510c55dea2d09bc7aa695708fbf34c

diff --git a/dbaccess/qa/python/fdo84315.py b/dbaccess/qa/python/fdo84315.py
index 03acc0a92e2f..f58b16f51309 100644
--- a/dbaccess/qa/python/fdo84315.py
+++ b/dbaccess/qa/python/fdo84315.py
@@ -20,7 +20,7 @@ class Fdo84315(unittest.TestCase):
         cls._uno = UnoInProcess()
         cls._uno.setUp()
         workdir = os.environ[ "WORKDIR_FOR_BUILD" ]
-        cls._xDoc = cls._uno.openDoc(workdir + "/CppunitTest/fdo84315.odb")
+        cls._xDoc = cls._uno.openDocFromAbsolutePath(workdir + "/CppunitTest/fdo84315.odb")
 
     @classmethod
     def tearDownClass(cls):
diff --git a/sw/qa/python/check_cross_references.py b/sw/qa/python/check_cross_references.py
index 2246118bed31..9eaabf0b0105 100644
--- a/sw/qa/python/check_cross_references.py
+++ b/sw/qa/python/check_cross_references.py
@@ -38,7 +38,7 @@ class CheckCrossReferences(unittest.TestCase):
     def setUpClass(cls):
         cls._uno = UnoInProcess()
         cls._uno.setUp()
-        cls.document = cls._uno.openWriterTemplateDoc("CheckCrossReferences.odt")
+        cls.document = cls._uno.openDocFromTDOC("CheckCrossReferences.odt")
         cls.xParaEnum = None
         cls.xPortionEnum = None
         cls.xFieldsRefresh = None
diff --git a/sw/qa/python/check_fields.py b/sw/qa/python/check_fields.py
index ff02ec0eb9d5..2fdbdf93cc2c 100644
--- a/sw/qa/python/check_fields.py
+++ b/sw/qa/python/check_fields.py
@@ -17,7 +17,7 @@ class CheckFields(unittest.TestCase):
     def setUpClass(cls):
         cls._uno = UnoInProcess()
         cls._uno.setUp()
-        cls._xDoc = cls._uno.openWriterTemplateDoc("fdo39694.ott")
+        cls._xDoc = cls._uno.openTemplateFromTDOC("fdo39694.ott")
         cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
 
     @classmethod
diff --git a/sw/qa/python/check_flies.py b/sw/qa/python/check_flies.py
index 55c04fec0783..d9407731e609 100644
--- a/sw/qa/python/check_flies.py
+++ b/sw/qa/python/check_flies.py
@@ -26,7 +26,7 @@ class CheckFlies(unittest.TestCase):
     def setUpClass(cls):
         cls._uno = UnoInProcess()
         cls._uno.setUp()
-        cls.document = cls._uno.openWriterTemplateDoc("CheckFlies.odt")
+        cls.document = cls._uno.openDocFromTDOC("CheckFlies.odt")
 
     @classmethod
     def tearDownClass(cls):
diff --git a/sw/qa/python/text_portion_enumeration_test.py b/sw/qa/python/text_portion_enumeration_test.py
index b767368d850b..d6774629f96a 100644
--- a/sw/qa/python/text_portion_enumeration_test.py
+++ b/sw/qa/python/text_portion_enumeration_test.py
@@ -3250,7 +3250,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
     def doload(self, file):
         xComp = None
         print("Loading test document...")
-        xComp = self.__class__._uno.openDoc(file)
+        xComp = self.__class__._uno.openDocFromAbsolutePath(file)
         self.assertIsNotNone(xComp, "cannot load: {}".format(file))
         print("...done")
         return xComp
@@ -3266,7 +3266,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
         xComp = None
         filename = "TESTMETA.odt"
         try:
-            xComp = self.__class__._uno.openBaseDoc(filename)
+            xComp = self.__class__._uno.openDocFromTDOC(filename)
             if xComp:
                 self.checkloadmeta(xComp)
                 with TemporaryDirectory() as tempdir:
@@ -3338,7 +3338,7 @@ class TextPortionEnumerationTest(unittest.TestCase):
         xComp = None
         filename = "TESTXMLID.odt"
         try:
-            xComp = self.__class__._uno.openBaseDoc(filename)
+            xComp = self.__class__._uno.openDocFromTDOC(filename)
             if xComp:
                 self.checkloadxmlid(xComp)
                 with TemporaryDirectory() as tempdir:
diff --git a/unotest/source/python/org/libreoffice/unotest.py b/unotest/source/python/org/libreoffice/unotest.py
index 0bb5212c9d4a..a6a927ca881c 100644
--- a/unotest/source/python/org/libreoffice/unotest.py
+++ b/unotest/source/python/org/libreoffice/unotest.py
@@ -195,72 +195,45 @@ class UnoInProcess:
         if not(havePonies):
             pyuno.private_initTestEnvironment()
             havePonies = True
+
     def openEmptyWriterDoc(self):
-        assert(self.xContext)
-        smgr = self.getContext().ServiceManager
-        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
-        props = [("Hidden", True), ("ReadOnly", False)]
-        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
-        self.xDoc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, loadProps)
-        assert(self.xDoc)
-        return self.xDoc
+        return self.openEmptyDoc("private:factory/swriter")
 
     def openEmptyCalcDoc(self):
-        self.xDoc = self.openEmptyDoc("private:factory/scalc")
-        return self.xDoc
+        return self.openEmptyDoc("private:factory/scalc")
 
     def openEmptyDoc(self, url, bHidden = True, bReadOnly = False):
-        assert(self.xContext)
-        smgr = self.getContext().ServiceManager
-        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
         props = [("Hidden", bHidden), ("ReadOnly", bReadOnly)]
-        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
-        self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
-        assert(self.xDoc)
-        return self.xDoc
+        return self.__openDocFromURL(url, props)
 
-    def openWriterTemplateDoc(self, file):
-        assert(self.xContext)
-        smgr = self.getContext().ServiceManager
-        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
-        props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", True)]
-        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
+    def openTemplateFromTDOC(self, file):
+        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)
-        self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
-        assert(self.xDoc)
-        return self.xDoc
+        return self.openDocFromURL(url, asTemplate)
 
-    def openBaseDoc(self, file):
-        assert(self.xContext)
-        smgr = self.getContext().ServiceManager
-        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
-        props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", False)]
-        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
-        path = os.getenv("TDOC")
+    def openDocFromAbsolutePath(self, file):
         if os.name == "nt":
-            #do not quote drive letter - it must be "X:"
-            url = "file:///" + path + "/" + quote(file)
+            url = "file:///" + file
         else:
-            url = "file://" + quote(path) + "/" + quote(file)
-        self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
-        assert(self.xDoc)
-        return self.xDoc
+            url = "file://" + file
+        return self.openDocFromURL(url)
 
-    def openDoc(self, file):
+    def openDocFromURL(self, url, asTemplate = False):
+        props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", asTemplate)]
+        return self.__openDocFromURL(url, props)
+
+    def __openDocFromURL(self, url, props):
         assert(self.xContext)
         smgr = self.getContext().ServiceManager
         desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
-        props = [("Hidden", True), ("ReadOnly", False), ("AsTemplate", False)]
         loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
-        if os.name == "nt":
-            url = "file:///" + file
-        else:
-            url = "file://" + file
         self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
         assert(self.xDoc)
         return self.xDoc


More information about the Libreoffice-commits mailing list