1'''Test idlelib.help_about.
2
3Coverage:
4'''
5from idlelib import aboutDialog as help_about
6from idlelib import textView as textview
7from idlelib.idle_test.mock_idle import Func
8from idlelib.idle_test.mock_tk import Mbox
9import unittest
10
11About = help_about.AboutDialog
12class Dummy_about_dialog():
13    # Dummy class for testing file display functions.
14    idle_credits = About.ShowIDLECredits.im_func
15    idle_readme = About.ShowIDLEAbout.im_func
16    idle_news = About.ShowIDLENEWS.im_func
17    # Called by the above
18    display_file_text = About.display_file_text.im_func
19
20
21class DisplayFileTest(unittest.TestCase):
22    "Test that .txt files are found and properly decoded."
23    dialog = Dummy_about_dialog()
24
25    @classmethod
26    def setUpClass(cls):
27        cls.orig_mbox = textview.tkMessageBox
28        cls.orig_view = textview.view_text
29        cls.mbox = Mbox()
30        cls.view = Func()
31        textview.tkMessageBox = cls.mbox
32        textview.view_text = cls.view
33        cls.About = Dummy_about_dialog()
34
35    @classmethod
36    def tearDownClass(cls):
37        textview.tkMessageBox = cls.orig_mbox
38        textview.view_text = cls.orig_view.im_func
39
40    def test_file_isplay(self):
41        for handler in (self.dialog.idle_credits,
42                        self.dialog.idle_readme,
43                        self.dialog.idle_news):
44            self.mbox.showerror.message = ''
45            self.view.called = False
46            handler()
47            self.assertEqual(self.mbox.showerror.message, '')
48            self.assertEqual(self.view.called, True)
49
50
51if __name__ == '__main__':
52    unittest.main(verbosity=2)
53