uitest/uitest/test.py |   48 +++++++++++++++++++-----------------------------
 1 file changed, 19 insertions(+), 29 deletions(-)

New commits:
commit faefc434efdc38587ddad0a65618efde81431e38
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Dec 5 14:29:00 2023 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue Dec 5 19:28:28 2023 +0100

    Deduplicate execute_dialog_through_*
    
    Use Python 3.3's 'yield from', which should be OK, because the
    baseline rhel8 has Python 3.6. If needed, older Python could
    use replacement like this:
    
        for dialog in self.wait_and_yield_dialog(event, xDialogParent, 
close_button):
            yield dialog
    
    Change-Id: Ic70bdf19fed730e41b7ce2868990ec88423eab33
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160352
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index 08c9a89ef9f5..db2bc1828be1 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -124,6 +124,23 @@ class UITest(object):
         finally:
             self.close_doc()
 
+    def wait_and_yield_dialog(self, event, parent, close_button):
+        while not event.executed:
+            time.sleep(DEFAULT_SLEEP)
+        dialog = self._xUITest.getTopFocusWindow()
+        if parent == dialog:
+            raise Exception("executing the action did not open the dialog")
+        try:
+            yield dialog
+        except:
+            if not close_button:
+                if 'cancel' in dialog.getChildren():
+                    self.close_dialog_through_button(dialog.getChild("cancel"))
+            raise
+        finally:
+            if close_button:
+                self.close_dialog_through_button(dialog.getChild(close_button))
+
     # Calls UITest.close_dialog_through_button at exit
     @contextmanager
     def execute_dialog_through_command(self, command, printNames=False, 
close_button = "ok", eventName = "DialogExecute"):
@@ -131,23 +148,7 @@ class UITest(object):
             xDialogParent = self._xUITest.getTopFocusWindow()
             if not self._xUITest.executeDialog(command):
                 raise Exception("Dialog not executed for: " + command)
-            while True:
-                if event.executed:
-                    xDialog = self._xUITest.getTopFocusWindow()
-                    if xDialogParent == xDialog:
-                        raise Exception("executing the action did not open the 
dialog")
-                    try:
-                        yield xDialog
-                    except:
-                        if not close_button:
-                            if 'cancel' in xDialog.getChildren():
-                                
self.close_dialog_through_button(xDialog.getChild("cancel"))
-                        raise
-                    finally:
-                        if close_button:
-                            
self.close_dialog_through_button(xDialog.getChild(close_button))
-                    return
-                time.sleep(DEFAULT_SLEEP)
+            yield from self.wait_and_yield_dialog(event, xDialogParent, 
close_button)
 
     @contextmanager
     def execute_modeless_dialog_through_command(self, command, 
printNames=False, close_button = "ok"):
@@ -163,18 +164,7 @@ class UITest(object):
         xDialogParent = self._xUITest.getTopFocusWindow()
         with EventListener(self._xContext, event_name) as event:
             ui_object.executeAction(action, parameters)
-            while True:
-                if event.executed:
-                    xDialog = self._xUITest.getTopFocusWindow()
-                    if xDialogParent == xDialog:
-                        raise Exception("executing the action did not open the 
dialog")
-                    try:
-                        yield xDialog
-                    finally:
-                        if close_button:
-                            
self.close_dialog_through_button(xDialog.getChild(close_button))
-                    return
-                time.sleep(DEFAULT_SLEEP)
+            yield from self.wait_and_yield_dialog(event, xDialogParent, 
close_button)
 
     # Calls UITest.close_doc at exit
     @contextmanager

Reply via email to