diff options
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/demo_ui/handle_multiple_files.py | 44 | ||||
-rw-r--r-- | uitest/uitest/test.py | 9 | ||||
-rw-r--r-- | uitest/uitest/uihelper/guarded.py | 9 |
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() |