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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Mar 18 08:39:58 UTC 2019


 sw/qa/python/xscriptprovider.py |   60 ++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

New commits:
commit f4a1dfe2ea2750467f2cc8cc50a14c656beda6ec
Author:     Hamish McIntyre-Bhatty <hamishmb at live.co.uk>
AuthorDate: Fri Jan 11 20:16:35 2019 +0000
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Mon Mar 18 09:39:37 2019 +0100

    tdf#97361 make xscriptprovider.py more pythonic
    
    Use pylint to identify style and convention errors in
    xscriptprovider.py. Also make use of setUp and tearDown
    methods to streamline the class and reduce code
    duplication.
    
    Change-Id: Iee4addb6577c304c5ced4e2d246c4bb557d2b6f4
    Reviewed-on: https://gerrit.libreoffice.org/66197
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/sw/qa/python/xscriptprovider.py b/sw/qa/python/xscriptprovider.py
index b79b379ad16d..b63812a590d3 100644
--- a/sw/qa/python/xscriptprovider.py
+++ b/sw/qa/python/xscriptprovider.py
@@ -7,12 +7,12 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 #
+
 import unittest
-import unohelper
-from org.libreoffice.unotest import UnoInProcess
-from com.sun.star.script.provider import ScriptFrameworkErrorException
 import uno
 
+from org.libreoffice.unotest import UnoInProcess
+from com.sun.star.script.provider import ScriptFrameworkErrorException
 
 class TestXScriptProvider(unittest.TestCase):
 
@@ -25,48 +25,54 @@ class TestXScriptProvider(unittest.TestCase):
     def tearDownClass(cls):
         cls._uno.tearDown()
 
-    def test_getScriptApplication(self):
-        # getScript for built-in StarBasic function
-        xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
-        xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
-        xScript = xScriptProvider.getScript(
+    def setUp(self):
+        xMasterScriptProviderFactory = create_master_script_provider_factory()
+        self.xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
+
+    def tearDown(self):
+        del self.xScriptProvider
+
+    def test_get_script_application(self):
+        #getScript for built-in StarBasic function
+        xScript = self.xScriptProvider.getScript(
             "vnd.sun.star.script:Tools.Misc.CreateNewDocument?language=Basic&"
             "location=application")
+
         self.assertIsNotNone(xScript, "xScript was not loaded")
 
-    def test_getScriptDocument(self):
-        # getScript for StarBasic function in loaded document
-        xDoc = self.__class__._uno.openTemplateFromTDOC("xscriptprovider.odt")
-        xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
-        xScriptProvider = xMasterScriptProviderFactory.createScriptProvider(xDoc)
+    def test_get_script_document(self):
+        #getScript for StarBasic function in loaded document
+        x_doc = self.__class__._uno.openTemplateFromTDOC("xscriptprovider.odt")
+
+        xMasterScriptProviderFactory = create_master_script_provider_factory()
+        xScriptProvider = xMasterScriptProviderFactory.createScriptProvider(x_doc)
+
         xScript = xScriptProvider.getScript(
             "vnd.sun.star.script:Standard.Module1.Main?language=Basic&"
             "location=document")
+
         self.assertIsNotNone(xScript, "xScript was not loaded")
-        xDoc.close(True)
 
-    def test_getScriptInvalidURI(self):
+        x_doc.close(True)
+
+    def test_get_script_invalid_uri(self):
         # getScript fails with invalid URI
-        xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
-        xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
         with self.assertRaises(ScriptFrameworkErrorException):
-            xScript = xScriptProvider.getScript("invalid URI, isn't it?")
+            self.xScriptProvider.getScript("invalid URI, isn't it?")
 
-    def test_getScriptNotFound(self):
+    def test_get_script_not_found(self):
         # getScript fails when script not found
-        xMasterScriptProviderFactory = self.createMasterScriptProviderFactory()
-        xScriptProvider = xMasterScriptProviderFactory.createScriptProvider("")
         with self.assertRaises(ScriptFrameworkErrorException):
-            xScript = xScriptProvider.getScript(
+            self.xScriptProvider.getScript(
                 "vnd.sun.star.script:NotExisting.NotExisting.NotExisting?"
                 "language=Basic&location=document")
 
-    def createMasterScriptProviderFactory(self):
-        xServiceManager = uno.getComponentContext().ServiceManager
-        return xServiceManager.createInstanceWithContext(
-            "com.sun.star.script.provider.MasterScriptProviderFactory",
-            uno.getComponentContext())
+def create_master_script_provider_factory():
+    xServiceManager = uno.getComponentContext().ServiceManager
 
+    return xServiceManager.createInstanceWithContext(
+        "com.sun.star.script.provider.MasterScriptProviderFactory",
+        uno.getComponentContext())
 
 if __name__ == '__main__':
     unittest.main()


More information about the Libreoffice-commits mailing list