summaryrefslogtreecommitdiff
path: root/sw/qa/python
diff options
context:
space:
mode:
authorHamish McIntyre-Bhatty <hamishmb@live.co.uk>2019-01-11 20:16:35 +0000
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2019-03-18 09:39:37 +0100
commitf4a1dfe2ea2750467f2cc8cc50a14c656beda6ec (patch)
treebbd71bae23be581b99f143177cd67f4d69002200 /sw/qa/python
parentd4c620ba7e9abccd8a82e2c64bd0d8cdf9538380 (diff)
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@cib.de>
Diffstat (limited to 'sw/qa/python')
-rw-r--r--sw/qa/python/xscriptprovider.py60
1 files changed, 33 insertions, 27 deletions
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()