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! 10 11 12import unittest 13 14from ..heading_text import HeadingText 15from ..split_application_window import SplitApplicationWindow 16from ..toolkit import toolkit_object 17 18GuiTestAssistant = toolkit_object("util.gui_test_assistant:GuiTestAssistant") 19no_gui_test_assistant = GuiTestAssistant.__name__ == "Unimplemented" 20 21 22@unittest.skipIf(no_gui_test_assistant, "No GuiTestAssistant") 23class TestSplitApplicationWindow(unittest.TestCase, GuiTestAssistant): 24 def setUp(self): 25 GuiTestAssistant.setUp(self) 26 self.window = SplitApplicationWindow() 27 28 def tearDown(self): 29 if self.window.control is not None: 30 with self.delete_widget(self.window.control): 31 self.window.destroy() 32 del self.window 33 GuiTestAssistant.tearDown(self) 34 35 def test_destroy(self): 36 # test that destroy works even when no control 37 with self.event_loop(): 38 self.window.destroy() 39 40 def test_open_close(self): 41 # test that opening and closing works as expected 42 with self.assertTraitChanges(self.window, "opening", count=1): 43 with self.assertTraitChanges(self.window, "opened", count=1): 44 with self.event_loop(): 45 self.window.open() 46 47 with self.assertTraitChanges(self.window, "closing", count=1): 48 with self.assertTraitChanges(self.window, "closed", count=1): 49 with self.event_loop(): 50 self.window.close() 51 52 def test_horizontal_split(self): 53 # test that horizontal split works 54 self.window.direction = "horizontal" 55 with self.assertTraitChanges(self.window, "opening", count=1): 56 with self.assertTraitChanges(self.window, "opened", count=1): 57 with self.event_loop(): 58 self.window.open() 59 60 with self.assertTraitChanges(self.window, "closing", count=1): 61 with self.assertTraitChanges(self.window, "closed", count=1): 62 with self.event_loop(): 63 self.window.close() 64 65 def test_contents(self): 66 # test that contents works 67 self.window.lhs = HeadingText 68 self.window.rhs = HeadingText 69 with self.assertTraitChanges(self.window, "opening", count=1): 70 with self.assertTraitChanges(self.window, "opened", count=1): 71 with self.event_loop(): 72 self.window.open() 73 74 with self.assertTraitChanges(self.window, "closing", count=1): 75 with self.assertTraitChanges(self.window, "closed", count=1): 76 with self.event_loop(): 77 self.window.close() 78 79 def test_ratio(self): 80 # test that ratio split works 81 self.window.ratio = 0.25 82 with self.assertTraitChanges(self.window, "opening", count=1): 83 with self.assertTraitChanges(self.window, "opened", count=1): 84 with self.event_loop(): 85 self.window.open() 86 87 with self.assertTraitChanges(self.window, "closing", count=1): 88 with self.assertTraitChanges(self.window, "closed", count=1): 89 with self.event_loop(): 90 self.window.close() 91