testtools/source/bridgetest/pyuno/impl.py               |    4 -
 testtools/source/bridgetest/pyuno/importer.py           |    6 +-
 wizards/com/sun/star/wizards/common/Desktop.py          |    2 
 wizards/com/sun/star/wizards/ui/event/CommonListener.py |    2 
 wizards/source/access2base/access2base.py               |   43 ++++++++++------
 wizards/source/scriptforge/python/ScriptForgeHelper.py  |    3 -
 xmlsecurity/qa/uitest/gpg/encrypt.py                    |    4 -
 7 files changed, 38 insertions(+), 26 deletions(-)

New commits:
commit 129e69f005d4752bb5ec10a8c12d842037394822
Author:     Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
AuthorDate: Mon Jul 29 14:59:25 2024 +0300
Commit:     Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
CommitDate: Mon Jul 29 16:56:57 2024 +0200

    testtools, wizards, xmlsecurity: fix issues found by Ruff linter
    
    Change-Id: I03edbaa7c9a643ca7503fa0e93c2bf0de3ac4e51
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171211
    Tested-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>
    Tested-by: Jenkins
    Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>

diff --git a/testtools/source/bridgetest/pyuno/impl.py 
b/testtools/source/bridgetest/pyuno/impl.py
index c95622022548..e6062c9e5360 100644
--- a/testtools/source/bridgetest/pyuno/impl.py
+++ b/testtools/source/bridgetest/pyuno/impl.py
@@ -169,8 +169,8 @@ class TestHelperCase( unittest.TestCase ):
             try:
                   uno.setCurrentContext(
                         unohelper.CurrentContext( oldContext,{"My42":42}) )
-                  self.assertTrue( 42 == 
uno.getCurrentContext().getValueByName( "My42" ) )
-                  self.assertTrue( None == 
uno.getCurrentContext().getValueByName( "My43" ) )
+                  self.assertTrue( uno.getCurrentContext().getValueByName( 
"My42" ) == 42 )
+                  self.assertTrue( uno.getCurrentContext().getValueByName( 
"My43" ) is None )
             finally:
                   uno.setCurrentContext( oldContext )
           
diff --git a/testtools/source/bridgetest/pyuno/importer.py 
b/testtools/source/bridgetest/pyuno/importer.py
index c3fc20eed039..3ed02d76d9d0 100644
--- a/testtools/source/bridgetest/pyuno/importer.py
+++ b/testtools/source/bridgetest/pyuno/importer.py
@@ -32,7 +32,7 @@ class ImporterTestCase(unittest.TestCase):
                            "com.sun.star.test.bridge.CppTestObject",self.ctx)
 
       def testStandard( self ):
-          self.assertTrue( IllegalArgumentException != None, "none-test" )
+          self.assertTrue( IllegalArgumentException is not None, "none-test" )
           self.assertRaises( IllegalArgumentException, 
self.tobj.raiseException, 1,"foo",self.tobj)
                  
           self.assertTrue( TWO == uno.Enum( 
"test.testtools.bridgetest.TestEnum","TWO"), "enum" )
@@ -49,10 +49,10 @@ class ImporterTestCase(unittest.TestCase):
       def testDynamicComponentRegistration( self ):
           ctx = uno.getComponentContext()
           self.assertTrue(
-              not ("com.sun.star.connection.Acceptor" in 
ctx.ServiceManager.getAvailableServiceNames()),
+              "com.sun.star.connection.Acceptor" not in 
ctx.ServiceManager.getAvailableServiceNames(),
               "precondition for dynamic component registration test is not 
fulfilled" )
           self.assertTrue(
-              not ("com.sun.star.connection.Connector" in 
ctx.ServiceManager.getAvailableServiceNames()),
+              "com.sun.star.connection.Connector" not in 
ctx.ServiceManager.getAvailableServiceNames(),
               "precondition for dynamic component registration test is not 
fulfilled" )
           unohelper.addComponentsToContext(
               ctx , ctx, ("acceptor.uno","connector.uno"), 
"com.sun.star.loader.SharedLibrary" )
diff --git a/wizards/com/sun/star/wizards/common/Desktop.py 
b/wizards/com/sun/star/wizards/common/Desktop.py
index 9469f9f5f403..e1af6eaa3b53 100644
--- a/wizards/com/sun/star/wizards/common/Desktop.py
+++ b/wizards/com/sun/star/wizards/common/Desktop.py
@@ -68,7 +68,7 @@ class Desktop(object):
         while bElementexists:
             try:
                 bElementexists = xElementContainer.hasByName(sElementName)
-            except:
+            except Exception:
                 bElementexists = xElementContainer.hasByHierarchicalName(
                     sElementName)
             if bElementexists:
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.py 
b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
index c131195711ad..dad035ddf2c6 100644
--- a/wizards/com/sun/star/wizards/ui/event/CommonListener.py
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.py
@@ -39,7 +39,7 @@ class ItemListenerProcAdapter( unohelper.Base, XItemListener 
):
         if callable( self.oProcToCall ):
             try:
                 self.oProcToCall()
-            except:
+            except Exception:
                 self.oProcToCall(oItemEvent)
 
     def disposing(self, Event):
diff --git a/wizards/source/access2base/access2base.py 
b/wizards/source/access2base/access2base.py
index ee1e05f17324..e54dca0bbcf3 100644
--- a/wizards/source/access2base/access2base.py
+++ b/wizards/source/access2base/access2base.py
@@ -447,7 +447,8 @@ class acConstants(object, metaclass = _Singleton):
     vbLf = chr(10)
 
     def _NewLine():
-        if _opsys == 'Windows': return chr(13) + chr(10)
+        if _opsys == 'Windows':
+            return chr(13) + chr(10)
         return chr(10)
 
     vbNewLine = _NewLine()
@@ -607,7 +608,8 @@ class _A2B(object, metaclass = _Singleton):
         :param args: list of arguments to be passed to the script
         :return: the value returned by the script execution
         """
-        if COMPONENTCONTEXT is None: A2BConnect()     #   Connection from 
inside LibreOffice is done at first API invocation
+        if COMPONENTCONTEXT is None:
+            A2BConnect()     #   Connection from inside LibreOffice is done at 
first API invocation
         Script = cls.xScript(script, module)
         try:
             Returned = Script.invoke((args), (), ())[0]
@@ -615,7 +617,8 @@ class _A2B(object, metaclass = _Singleton):
             raise TypeError("Access2Base error: method '" + script + "' in 
Basic module '" + module + "' call error. Check its arguments.")
         else:
             if Returned is None:
-                if cls.VerifyNoError(): return None
+                if cls.VerifyNoError():
+                    return None
             return Returned
 
     @classmethod
@@ -632,7 +635,8 @@ class _A2B(object, metaclass = _Singleton):
         :param args: the arguments of the method, if any
         :return: the value returned by the execution of the Basic routine
         """
-        if COMPONENTCONTEXT is None: A2BConnect()     #   Connection from 
inside LibreOffice is done at first API invocation
+        if COMPONENTCONTEXT is None:
+            A2BConnect()     #   Connection from inside LibreOffice is done at 
first API invocation
         # Intercept special call to Application.Events()
         if basic == Application.basicmodule and script == 'Events':
             Script = cls.xScript('PythonEventsWrapper', _WRAPPERMODULE)
@@ -667,7 +671,8 @@ class _A2B(object, metaclass = _Singleton):
             else:                               # UNO object
                 return Returned[0]
         elif Returned[0] is None:
-            if cls.VerifyNoError(): return None
+            if cls.VerifyNoError():
+                return None
         else: # Should not happen
             return Returned[0]
 
@@ -756,7 +761,8 @@ class Application(object, metaclass = _Singleton):
     @classmethod
     def OpenConnection(cls, thisdatabasedocument = acConstants.Missing):
         global THISDATABASEDOCUMENT
-        if COMPONENTCONTEXT is None: A2BConnect()     #   Connection from 
inside LibreOffice is done at first API invocation
+        if COMPONENTCONTEXT is None:
+            A2BConnect()     #   Connection from inside LibreOffice is done at 
first API invocation
         if DESKTOP is not None:
             THISDATABASEDOCUMENT = DESKTOP.getCurrentComponent()
             return _A2B.invokeMethod('OpenConnection', 'Application', 
THISDATABASEDOCUMENT)
@@ -844,7 +850,8 @@ class DoCmd(object, metaclass = _Singleton):
     @classmethod
     def OutputTo(cls, objecttype, objectname = '', outputformat = '', 
outputfile = '', autostart = False, templatefile = ''
         , encoding = acConstants.acUTF8Encoding, quality = 
acConstants.acExportQualityPrint):
-        if objecttype == acConstants.acOutputForm: encoding = 0
+        if objecttype == acConstants.acOutputForm:
+            encoding = 0
         return cls.W(_vbMethod, cls.basicmodule, 'OutputTo', objecttype, 
objectname, outputformat
                            , outputfile, autostart, templatefile, encoding, 
quality)
     @classmethod
@@ -896,19 +903,23 @@ class Basic(object, metaclass = _Singleton):
 
     @classmethod
     def DateAdd(cls, add, count, datearg):
-        if isinstance(datearg, datetime.datetime): datearg = 
datearg.isoformat()
+        if isinstance(datearg, datetime.datetime):
+            datearg = datearg.isoformat()
         dateadd = cls.M('PyDateAdd', _WRAPPERMODULE, add, count, datearg)
         return datetime.datetime.strptime(dateadd, acConstants.FromIsoFormat)
 
     @classmethod
     def DateDiff(cls, add, date1, date2, weekstart = 1, yearstart = 1):
-        if isinstance(date1, datetime.datetime): date1 = date1.isoformat()
-        if isinstance(date2, datetime.datetime): date2 = date2.isoformat()
+        if isinstance(date1, datetime.datetime):
+            date1 = date1.isoformat()
+        if isinstance(date2, datetime.datetime):
+            date2 = date2.isoformat()
         return cls.M('PyDateDiff', _WRAPPERMODULE, add, date1, date2, 
weekstart, yearstart)
 
     @classmethod
     def DatePart(cls, add, datearg, weekstart = 1, yearstart = 1):
-        if isinstance(datearg, datetime.datetime): datearg = 
datearg.isoformat()
+        if isinstance(datearg, datetime.datetime):
+            datearg = datearg.isoformat()
         return cls.M('PyDatePart', _WRAPPERMODULE, add, datearg, weekstart, 
yearstart)
 
     @classmethod
@@ -1011,7 +1022,7 @@ class _BasicObject(object):
         elif name in self.classProperties:
             if self.internal:       # internal = True forces property setting 
even if property is read-only
                 pass
-            elif self.classProperties[name] == True: # True == Editable
+            elif self.classProperties[name]: # True == Editable
                 self.W(_vbLet, self.objectreference, name, value)
             else:
                 raise AttributeError("type object '" + self.objecttype + "' 
has no editable attribute '" + name + "'")
@@ -1024,7 +1035,8 @@ class _BasicObject(object):
 
     def __repr__(self):
         repr = "Basic object (type='" + self.objecttype + "', index=" + 
str(self.objectreference)
-        if len(self.name) > 0: repr += ", name='" + self.name + "'"
+        if len(self.name) > 0:
+            repr += ", name='" + self.name + "'"
         return repr + ")"
 
     def _Reset(self, propertyname, basicreturn = None):
@@ -1223,7 +1235,8 @@ class _Database(_BasicObject):
         return self.W(_vbMethod, self.objectreference, 'OpenSQL', SQL, option)
     def OutputTo(self, objecttype, objectname = '', outputformat = '', 
outputfile = '', autostart = False, templatefile = ''
         , encoding = acConstants.acUTF8Encoding, quality = 
acConstants.acExportQualityPrint):
-        if objecttype == acConstants.acOutputForm: encoding = 0
+        if objecttype == acConstants.acOutputForm:
+            encoding = 0
         return self.W(_vbMethod, self.objectreference, 'OutputTo', objecttype, 
objectname, outputformat, outputfile
                       , autostart, templatefile, encoding, quality)
     def QueryDefs(self, index = acConstants.Missing):
@@ -1337,7 +1350,7 @@ class _Module(_BasicObject):
         Returned = self.W(_vbMethod, self.objectreference, 'Find', target, 
startline, startcolumn, endline
                       , endcolumn, wholeword, matchcase, patternsearch)
         if isinstance(Returned, tuple):
-            if Returned[0] == True and len(Returned) == 5:
+            if Returned[0] and len(Returned) == 5:
                 self.startline = Returned[1]
                 self.startcolumn = Returned[2]
                 self.endline = Returned[3]
diff --git a/wizards/source/scriptforge/python/ScriptForgeHelper.py 
b/wizards/source/scriptforge/python/ScriptForgeHelper.py
index c9ebf6e61c88..370c760b2708 100644
--- a/wizards/source/scriptforge/python/ScriptForgeHelper.py
+++ b/wizards/source/scriptforge/python/ScriptForgeHelper.py
@@ -81,7 +81,8 @@ def _SF_Dictionary__ImportFromJson(jsonstr: str):  # used by 
Dictionary.ImportFr
             item = None
         elif isinstance(value, list):  # check every member of the list is not 
a (sub)dict
             for i in range(len(value)):
-                if isinstance(value[i], dict): value[i] = None
+                if isinstance(value[i], dict):
+                    value[i] = None
         result.append((key, item))
     return result
 
diff --git a/xmlsecurity/qa/uitest/gpg/encrypt.py 
b/xmlsecurity/qa/uitest/gpg/encrypt.py
index 2425af841d6a..ca2fa5f87f9c 100644
--- a/xmlsecurity/qa/uitest/gpg/encrypt.py
+++ b/xmlsecurity/qa/uitest/gpg/encrypt.py
@@ -9,7 +9,6 @@
 
 from uitest.framework import UITestCase
 from libreoffice.uno.propertyvalue import mkPropertyValues
-from uitest.uihelper.common import get_state_as_dict
 
 from tempfile import TemporaryDirectory
 import os.path
@@ -24,8 +23,7 @@ class GpgEncryptTest(UITestCase):
         # TODO: Maybe deduplicate with 
sw/qa/uitest/writer_tests8/save_with_password_test_policy.py
         with TemporaryDirectory() as tempdir:
             xFilePath = os.path.join(tempdir, "testfile.odt")
-            with self.ui_test.create_doc_in_start_center("writer") as document:
-                MainWindow = self.xUITest.getTopFocusWindow()
+            with self.ui_test.create_doc_in_start_center("writer"):
                 with self.ui_test.execute_dialog_through_command(".uno:Save", 
close_button="") as xSaveDialog:
                     xFileName = xSaveDialog.getChild("file_name")
                     xFileName.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"CTRL+A"}))

Reply via email to