1# (C) Copyright 2005-2020 Enthought, Inc., Austin, TX
2# All rights reserved.
3#
4# This software is provided without warranty under the terms of the BSD
5# license included in LICENSE.txt and may be redistributed only under
6# the conditions described in the aforementioned license. The license
7# is also available online at http://www.enthought.com/licenses/BSD.txt
8#
9# Thanks for using Enthought open source!
10import unittest
11
12from pyface.tasks.api import Editor, AdvancedEditorAreaPane
13from pyface.toolkit import toolkit_object
14
15GuiTestAssistant = toolkit_object("util.gui_test_assistant:GuiTestAssistant")
16no_gui_test_assistant = GuiTestAssistant.__name__ == "Unimplemented"
17
18
19@unittest.skipIf(no_gui_test_assistant, "No GuiTestAssistant")
20class TestAdvancedEditorAreaPane(unittest.TestCase, GuiTestAssistant):
21    def setUp(self):
22        GuiTestAssistant.setUp(self)
23        self.area_pane = AdvancedEditorAreaPane()
24
25    def tearDown(self):
26        if self.area_pane.control is not None:
27            with self.delete_widget(self.area_pane.control):
28                self.area_pane.destroy()
29        GuiTestAssistant.tearDown(self)
30
31    def test_create_destroy(self):
32        # test that creating and destroying works as expected
33        with self.event_loop():
34            self.area_pane.create(None)
35        with self.event_loop():
36            self.area_pane.destroy()
37
38    def test_create_destroy_with_editor(self):
39        # test that creating and destroying works as expected when there are
40        # editors
41        with self.event_loop():
42            self.area_pane.create(None)
43        with self.event_loop():
44            editor = self.area_pane.create_editor("Hello", Editor)
45        with self.event_loop():
46            self.area_pane.add_editor(editor)
47        with self.event_loop():
48            self.area_pane.activate_editor(editor)
49        with self.event_loop():
50            self.area_pane.destroy()
51