uitest/mass-testing/calc.py    |   94 +++++++++++++----------------------------
 uitest/mass-testing/impress.py |   54 +++++++++--------------
 uitest/mass-testing/run.py     |    8 +++
 uitest/mass-testing/writer.py  |   60 +++++++++-----------------
 4 files changed, 80 insertions(+), 136 deletions(-)

New commits:
commit 440b0829fbc323910644b93b395b14392984b2c9
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jan 25 18:32:25 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jan 25 20:10:11 2022 +0100

    mass-testing: Adapt code to new uitest code
    
    Change-Id: Iee0161d1e404436fb3a23a740ecb2418eb5caaf5

diff --git a/uitest/mass-testing/calc.py b/uitest/mass-testing/calc.py
index b8c1879..6b9c5c5 100755
--- a/uitest/mass-testing/calc.py
+++ b/uitest/mass-testing/calc.py
@@ -8,40 +8,37 @@ import os
 import signal
 from uitest.framework import UITestCase
 from libreoffice.uno.propertyvalue import mkPropertyValues
-import time
+from contextlib import contextmanager
 
 #Max number of sheets to jump to
 maxSheets = 10
 
 class massTesting(UITestCase):
 
+    @contextmanager
     def load_file(self):
         #TODO: Ignore password protected files
 
         fileName = os.environ["TESTFILENAME"]
 
-        self.ui_test.create_doc_in_start_center("calc")
+        with self.ui_test.load_file(fileName) as document:
 
-        self.ui_test.load_file(fileName)
-        document = self.ui_test.get_component()
-
-
-        # Ignore read-only or protected files
-        if not hasattr(document, 'isReadonly') or document.isReadonly() or 
document.isProtected():
-            print("mass-uitesting:skipped", flush=True)
-            return
+            # Ignore read-only or protected files
+            if not hasattr(document, 'isReadonly') or document.isReadonly() or 
document.isProtected():
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        try:
-            xDoc = self.xUITest.getTopFocusWindow()
-            xEdit = xDoc.getChild("grid_window")
-        except:
-            #In case the mimetype is wrong and the file is open with another 
component
-            print("mass-uitesting:skipped", flush=True)
-            return
+            try:
+                xDoc = self.xUITest.getTopFocusWindow()
+                xEdit = xDoc.getChild("grid_window")
+            except:
+                #In case the mimetype is wrong and the file is open with 
another component
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        print("mass-uitesting:loaded", flush=True)
+            print("mass-uitesting:loaded", flush=True)
 
-        return xEdit
+            yield xEdit
 
     def go_to_first_sheet(self):
         document = self.ui_test.get_component()
@@ -63,8 +60,7 @@ class massTesting(UITestCase):
         return nrSheets
 
     def test_remove_all_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -74,11 +70,8 @@ class massTesting(UITestCase):
                 self.xUITest.executeCommand(".uno:Undo")
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_insert_column_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -86,11 +79,8 @@ class massTesting(UITestCase):
                 self.xUITest.executeCommand(".uno:Undo")
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_insert_row_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -98,11 +88,8 @@ class massTesting(UITestCase):
                 self.xUITest.executeCommand(".uno:Undo")
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_copy_all_paste_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -118,11 +105,8 @@ class massTesting(UITestCase):
 
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_print_preview(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -132,11 +116,8 @@ class massTesting(UITestCase):
 
                 self.xUITest.getTopFocusWindow()
 
-        self.ui_test.close_doc()
-
     def test_hide_column_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -144,11 +125,8 @@ class massTesting(UITestCase):
                 self.xUITest.executeCommand(".uno:Undo")
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_hide_row_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             for i in range(nrSheets)[:maxSheets]:
@@ -156,23 +134,17 @@ class massTesting(UITestCase):
                 self.xUITest.executeCommand(".uno:Undo")
                 self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
-
     def test_copy_sheet_undo_delete_sheet(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             ignoreSheets = 0
             document = self.ui_test.get_component()
             for i in range(nrSheets)[:maxSheets]:
                 #copy sheet, undo and delete
-                self.ui_test.execute_dialog_through_command(".uno:Move")
-                xDialog = self.xUITest.getTopFocusWindow()
-                xCopy = xDialog.getChild("copy")
-                xCopy.executeAction("CLICK", tuple())
-                xOKBtn = xDialog.getChild("ok")
-                self.ui_test.close_dialog_through_button(xOKBtn)
+                with self.ui_test.execute_dialog_through_command(".uno:Move") 
as xDialog:
+                    xCopy = xDialog.getChild("copy")
+                    xCopy.executeAction("CLICK", tuple())
 
                 self.xUITest.executeCommand(".uno:Undo")
 
@@ -184,18 +156,13 @@ class massTesting(UITestCase):
                 else:
                     #Do not delete the last sheet
                     if i < nrSheets - 1:
-                        
self.ui_test.execute_dialog_through_command(".uno:Remove")  #delete sheet
-                        xDialog = self.xUITest.getTopFocusWindow()
-                        xOKButton = xDialog.getChild("yes")
-                        xOKButton.executeAction("CLICK", tuple())
+                        with 
self.ui_test.execute_dialog_through_command(".uno:Remove", close_button="yes"):
+                            pass
 
             self.assertEqual(document.Sheets.getCount(), 1 + ignoreSheets + 
len(range(nrSheets)[maxSheets + 1:]))
 
-        self.ui_test.close_doc()
-
     def test_change_text_formatting_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             nrSheets = self.go_to_first_sheet()
 
             document = self.ui_test.get_component()
@@ -245,5 +212,4 @@ class massTesting(UITestCase):
 
                     self.xUITest.executeCommand(".uno:JumpToNextTable")
 
-        self.ui_test.close_doc()
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/mass-testing/impress.py b/uitest/mass-testing/impress.py
index a2adcf6..7ffc3de 100755
--- a/uitest/mass-testing/impress.py
+++ b/uitest/mass-testing/impress.py
@@ -7,43 +7,40 @@
 import os
 from uitest.framework import UITestCase
 from libreoffice.uno.propertyvalue import mkPropertyValues
-import time
+from contextlib import contextmanager
 
 class massTesting(UITestCase):
 
+    @contextmanager
     def load_file(self):
         #TODO: Ignore password protected files
 
         fileName = os.environ["TESTFILENAME"]
 
-        self.ui_test.create_doc_in_start_center("impress")
+        with self.ui_test.load_file(fileName) as document:
 
-        self.ui_test.load_file(fileName)
-        document = self.ui_test.get_component()
+            # Ignore read-only files
+            if not hasattr(document, 'isReadonly') or document.isReadonly():
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        # Ignore read-only files
-        if not hasattr(document, 'isReadonly') or document.isReadonly():
-            print("mass-uitesting:skipped", flush=True)
-            return
+            # Go to the normal view
+            self.xUITest.executeCommand(".uno:NormalMultiPaneGUI")
 
-        # Go to the normal view
-        self.xUITest.executeCommand(".uno:NormalMultiPaneGUI")
+            try:
+                xDoc = self.xUITest.getTopFocusWindow()
+                xEdit = xDoc.getChild("impress_win")
+            except:
+                #In case the mimetype is wrong and the file is open with 
another component
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        try:
-            xDoc = self.xUITest.getTopFocusWindow()
-            xEdit = xDoc.getChild("impress_win")
-        except:
-            #In case the mimetype is wrong and the file is open with another 
component
-            print("mass-uitesting:skipped", flush=True)
-            return
-
-        print("mass-uitesting:loaded", flush=True)
+            print("mass-uitesting:loaded", flush=True)
 
-        return xEdit
+            yield xEdit
 
     def test_copy_all_paste_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             self.xUITest.executeCommand(".uno:SelectAll")
 
             self.xUITest.executeCommand(".uno:Copy")
@@ -53,11 +50,9 @@ class massTesting(UITestCase):
 
             for i in range(5):
                 self.xUITest.executeCommand(".uno:Undo")
-        self.ui_test.close_doc()
 
     def test_traverse_all_slides_and_delete_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             document = self.ui_test.get_component()
             slideCount = document.DrawPages.getCount()
 
@@ -69,11 +64,9 @@ class massTesting(UITestCase):
                 xEdit.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"DELETE"}))
 
                 self.xUITest.executeCommand(".uno:Undo")
-        self.ui_test.close_doc()
 
     def test_duplicate_all_slides_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             # Go to the slide sorter view
             self.xUITest.executeCommand(".uno:DiaMode")
 
@@ -85,11 +78,9 @@ class massTesting(UITestCase):
             self.xUITest.executeCommand(".uno:DuplicatePage")
 
             self.xUITest.executeCommand(".uno:Undo")
-        self.ui_test.close_doc()
 
     def test_remove_all_slides_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             # Go to the slide sorter view
             self.xUITest.executeCommand(".uno:DiaMode")
 
@@ -101,6 +92,5 @@ class massTesting(UITestCase):
             xEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"DELETE"}))
 
             self.xUITest.executeCommand(".uno:Undo")
-        self.ui_test.close_doc()
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/mass-testing/run.py b/uitest/mass-testing/run.py
index 3acd8bc..af1b47d 100755
--- a/uitest/mass-testing/run.py
+++ b/uitest/mass-testing/run.py
@@ -228,6 +228,12 @@ if __name__ == '__main__':
                 "Copy uitest folder from LibreOffice codebase and paste it 
here")
         sys.exit(1)
 
+    pythonPath = os.path.join(currentPath, 'python/')
+    if not os.path.exists(pythonPath):
+        print("ERROR: " + pythonPath + " doesn't exists. " + \
+                "Copy unotest/source/python/ folder from LibreOffice codebase 
and paste it here")
+        sys.exit(1)
+
     parser = DefaultHelpParser()
 
     parser.add_argument(
@@ -247,7 +253,7 @@ if __name__ == '__main__':
     if not os.path.exists(sofficePath) or not sofficePath.endswith('/soffice'):
         parser.error(sofficePath + " is an invalid LibreOffice path")
 
-    os.environ["PYTHONPATH"] = sofficePath.split('/soffice')[0]
+    os.environ["PYTHONPATH"] = sofficePath.split('/soffice')[0] + os.pathsep + 
pythonPath
     os.environ["URE_BOOTSTRAP"] = "file://" + sofficePath.split('/soffice')[0] 
+ '/fundamentalrc'
     os.environ["SAL_USE_VCLPLUGIN"] = "gen"
 
diff --git a/uitest/mass-testing/writer.py b/uitest/mass-testing/writer.py
index 9f93ed8..3d84770 100755
--- a/uitest/mass-testing/writer.py
+++ b/uitest/mass-testing/writer.py
@@ -8,40 +8,36 @@ import os
 import signal
 from uitest.framework import UITestCase
 from libreoffice.uno.propertyvalue import mkPropertyValues
-import time
+from contextlib import contextmanager
 
 class massTesting(UITestCase):
 
+    @contextmanager
     def load_file(self):
         #TODO: Ignore password protected files
 
         fileName = os.environ["TESTFILENAME"]
 
-        self.ui_test.create_doc_in_start_center("writer")
+        with self.ui_test.load_file(fileName) as document:
+            # Ignore read-only files
+            if not hasattr(document, 'isReadonly') or document.isReadonly():
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        self.ui_test.load_file(fileName)
-        document = self.ui_test.get_component()
+            try:
+                xDoc = self.xUITest.getTopFocusWindow()
+                xEdit = xDoc.getChild("writer_edit")
+            except:
+                #In case the mimetype is wrong and the file is open with 
another component
+                print("mass-uitesting:skipped", flush=True)
+                raise
 
-        # Ignore read-only files
-        if not hasattr(document, 'isReadonly') or document.isReadonly():
-            print("mass-uitesting:skipped", flush=True)
-            return
+            print("mass-uitesting:loaded", flush=True)
 
-        try:
-            xDoc = self.xUITest.getTopFocusWindow()
-            xEdit = xDoc.getChild("writer_edit")
-        except:
-            #In case the mimetype is wrong and the file is open with another 
component
-            print("mass-uitesting:skipped", flush=True)
-            return
-
-        print("mass-uitesting:loaded", flush=True)
-
-        return xEdit
+            yield xEdit
 
     def test_remove_all_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             self.xUITest.executeCommand(".uno:SelectAll")
             self.xUITest.executeCommand(".uno:SelectAll")
             self.xUITest.executeCommand(".uno:SelectAll")
@@ -49,33 +45,24 @@ class massTesting(UITestCase):
 
             self.xUITest.executeCommand(".uno:Undo")
 
-        self.ui_test.close_doc()
-
     def test_insert_returns_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             for i in range(60):
                 xEdit.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"RETURN"}))
 
             for i in range(60):
                 self.xUITest.executeCommand(".uno:Undo")
 
-        self.ui_test.close_doc()
-
     def test_insert_pageBreaks_and_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             for i in range(5):
                 self.xUITest.executeCommand(".uno:InsertPagebreak")
 
             for i in range(5):
                 self.xUITest.executeCommand(".uno:Undo")
 
-        self.ui_test.close_doc()
-
     def test_copy_all_paste_undo(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             self.xUITest.executeCommand(".uno:SelectAll")
             self.xUITest.executeCommand(".uno:SelectAll")
             self.xUITest.executeCommand(".uno:SelectAll")
@@ -88,11 +75,8 @@ class massTesting(UITestCase):
             for i in range(5):
                 self.xUITest.executeCommand(".uno:Undo")
 
-        self.ui_test.close_doc()
-
     def test_traverse_all_pages(self):
-        xEdit = self.load_file()
-        if xEdit:
+        with self.load_file() as xEdit:
             document = self.ui_test.get_component()
             pageCount = document.CurrentController.PageCount
 
@@ -102,6 +86,4 @@ class massTesting(UITestCase):
             for i in range(pageCount):
                 xEdit.executeAction("TYPE", 
mkPropertyValues({"KEYCODE":"PAGEUP"}))
 
-        self.ui_test.close_doc()
-
 # vim: set shiftwidth=4 softtabstop=4 expandtab:

Reply via email to