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 os
13import unittest
14
15from ..directory_dialog import DirectoryDialog
16from ..gui import GUI
17from ..toolkit import toolkit_object
18
19GuiTestAssistant = toolkit_object("util.gui_test_assistant:GuiTestAssistant")
20no_gui_test_assistant = GuiTestAssistant.__name__ == "Unimplemented"
21
22ModalDialogTester = toolkit_object(
23    "util.modal_dialog_tester:ModalDialogTester"
24)
25no_modal_dialog_tester = ModalDialogTester.__name__ == "Unimplemented"
26
27
28@unittest.skipIf(no_gui_test_assistant, "No GuiTestAssistant")
29class TestDirectoryDialog(unittest.TestCase, GuiTestAssistant):
30    def setUp(self):
31        GuiTestAssistant.setUp(self)
32        self.dialog = DirectoryDialog()
33
34    def tearDown(self):
35        if self.dialog.control is not None:
36            with self.delete_widget(self.dialog.control):
37                self.dialog.destroy()
38        del self.dialog
39        GuiTestAssistant.tearDown(self)
40
41    def test_create(self):
42        # test that creation and destruction works as expected
43        with self.event_loop():
44            self.dialog._create()
45        with self.event_loop():
46            self.dialog.destroy()
47
48    def test_destroy(self):
49        # test that destroy works even when no control
50        with self.event_loop():
51            self.dialog.destroy()
52
53    def test_close(self):
54        # test that close works
55        with self.event_loop():
56            self.dialog._create()
57        with self.event_loop():
58            self.dialog.close()
59
60    def test_default_path(self):
61        # test that default path works
62        self.dialog.default_path = os.path.join("images", "core.png")
63        with self.event_loop():
64            self.dialog._create()
65        with self.event_loop():
66            self.dialog.close()
67
68    def test_no_new_directory(self):
69        # test that block on new directories works
70        self.dialog.new_directory = False
71        with self.event_loop():
72            self.dialog._create()
73        with self.event_loop():
74            self.dialog.close()
75
76    def test_message(self):
77        # test that message setting works
78        self.dialog.message = "Select a directory"
79        with self.event_loop():
80            self.dialog._create()
81        with self.event_loop():
82            self.dialog.close()
83
84    # XXX would be nice to actually test with an open dialog, but not right now
85