From f4a1dfe2ea2750467f2cc8cc50a14c656beda6ec Mon Sep 17 00:00:00 2001 From: Hamish McIntyre-Bhatty Date: Fri, 11 Jan 2019 20:16:35 +0000 Subject: 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 --- sw/qa/python/xscriptprovider.py | 60 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'sw/qa/python') 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() -- cgit