summaryrefslogtreecommitdiff
path: root/uitest
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2021-06-21 16:21:30 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-06-22 14:46:39 +0200
commitbe0a41679fea524e0935dc6617b5e65349812dd1 (patch)
treef14372226d5054c045f954e38ea09da5c412215b /uitest
parent14069d84174ca7a4e60db4d75912903e9679b643 (diff)
uitest: guard load_file
Mostly done by a script for motivation, see 89aaa17a0a4413f07da2bc5084b0164f15dc01ac < UITest: introduce guarded context managers > Change-Id: Ia924293dc2a12230fd13f69fd734875ced86be8a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117593 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'uitest')
-rw-r--r--uitest/demo_ui/handle_multiple_files.py44
-rw-r--r--uitest/uitest/test.py9
-rw-r--r--uitest/uitest/uihelper/guarded.py9
3 files changed, 26 insertions, 36 deletions
diff --git a/uitest/demo_ui/handle_multiple_files.py b/uitest/demo_ui/handle_multiple_files.py
index 01e086f3d422..8abb59d9b17f 100644
--- a/uitest/demo_ui/handle_multiple_files.py
+++ b/uitest/demo_ui/handle_multiple_files.py
@@ -15,39 +15,33 @@ class HandleFiles(UITestCase):
def test_load_file(self):
- calc_file = self.ui_test.load_file(get_url_for_data_file("test.ods"))
+ with self.ui_test.load_file(get_url_for_data_file("test.ods")) as calc_file:
- calc_file2 = self.ui_test.load_file(get_url_for_data_file("test2.ods"))
+ with self.ui_test.load_file(get_url_for_data_file("test2.ods")):
- frames = self.ui_test.get_frames()
- self.assertEqual(len(frames), 2)
+ frames = self.ui_test.get_frames()
+ self.assertEqual(len(frames), 2)
- self.ui_test.close_doc()
+ frames = self.ui_test.get_frames()
+ self.assertEqual(len(frames), 1)
- frames = self.ui_test.get_frames()
- self.assertEqual(len(frames), 1)
-
- # this is currently still necessary as otherwise
- # the command is not forwarded to the correct frame
- # TODO: provide an additional event that we can use
- # and get rid of the sleep
- time.sleep(1)
-
- self.ui_test.close_doc()
+ # this is currently still necessary as otherwise
+ # the command is not forwarded to the correct frame
+ # TODO: provide an additional event that we can use
+ # and get rid of the sleep
+ time.sleep(1)
def test_select_frame(self):
- calc_file = self.ui_test.load_file(get_url_for_data_file("test.ods"))
-
- calc_file2 = self.ui_test.load_file(get_url_for_data_file("test2.ods"))
- frames = self.ui_test.get_frames()
- self.assertEqual(len(frames), 2)
- frames[0].activate()
+ with self.ui_test.load_file(get_url_for_data_file("test.ods")) as calc_file:
- self.ui_test.close_doc()
+ with self.ui_test.load_file(get_url_for_data_file("test2.ods")):
+ frames = self.ui_test.get_frames()
+ self.assertEqual(len(frames), 2)
+ frames[0].activate()
- frames = self.ui_test.get_frames()
- self.assertEqual(len(frames), 1)
+ frames = self.ui_test.get_frames()
+ self.assertEqual(len(frames), 1)
- self.assertTrue(frames[0].getTitle().startswith("test2.ods"))
+ self.assertTrue(frames[0].getTitle().startswith("test2.ods"))
# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/uitest/uitest/test.py b/uitest/uitest/test.py
index c83759bf6b80..86da1ac79cb2 100644
--- a/uitest/uitest/test.py
+++ b/uitest/uitest/test.py
@@ -88,9 +88,14 @@ class UITest(object):
time_ += DEFAULT_SLEEP
time.sleep(DEFAULT_SLEEP)
+ # Calls UITest.close_doc at exit
+ @contextmanager
def load_file(self, url):
- with self.wait_until_component_loaded():
- return self.get_desktop().loadComponentFromURL(url, "_default", 0, tuple())
+ try:
+ with self.wait_until_component_loaded():
+ yield self.get_desktop().loadComponentFromURL(url, "_default", 0, tuple())
+ finally:
+ self.close_doc()
def execute_dialog_through_command(self, command, printNames=False):
with EventListener(self._xContext, "DialogExecute", printNames=printNames) as event:
diff --git a/uitest/uitest/uihelper/guarded.py b/uitest/uitest/uihelper/guarded.py
index b75aea332ff3..5cfed2d49e1a 100644
--- a/uitest/uitest/uihelper/guarded.py
+++ b/uitest/uitest/uihelper/guarded.py
@@ -11,15 +11,6 @@ from contextlib import contextmanager
# Calls UITest.close_doc at exit
@contextmanager
-def load_file(testCase, url):
- component = testCase.ui_test.load_file(url)
- try:
- yield component
- finally:
- testCase.ui_test.close_doc()
-
-# Calls UITest.close_doc at exit
-@contextmanager
def create_doc_in_start_center(testCase, app):
testCase.ui_test.create_doc_in_start_center(app)
component = testCase.ui_test.get_component()