~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/idlelib/idle_test/test_config_name.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Unit tests for idlelib.configSectionNameDialog"""
 
2
import unittest
 
3
from idlelib.idle_test.mock_tk import Var, Mbox
 
4
from idlelib import configSectionNameDialog as name_dialog_module
 
5
 
 
6
name_dialog = name_dialog_module.GetCfgSectionNameDialog
 
7
 
 
8
class Dummy_name_dialog:
 
9
    # Mock for testing the following methods of name_dialog
 
10
    name_ok = name_dialog.name_ok
 
11
    Ok = name_dialog.Ok
 
12
    Cancel = name_dialog.Cancel
 
13
    # Attributes, constant or variable, needed for tests
 
14
    used_names = ['used']
 
15
    name = Var()
 
16
    result = None
 
17
    destroyed = False
 
18
    def destroy(self):
 
19
        self.destroyed = True
 
20
 
 
21
# name_ok calls Mbox.showerror if name is not ok
 
22
orig_mbox = name_dialog_module.tkMessageBox
 
23
showerror = Mbox.showerror
 
24
 
 
25
class ConfigNameTest(unittest.TestCase):
 
26
    dialog = Dummy_name_dialog()
 
27
 
 
28
    @classmethod
 
29
    def setUpClass(cls):
 
30
        name_dialog_module.tkMessageBox = Mbox
 
31
 
 
32
    @classmethod
 
33
    def tearDownClass(cls):
 
34
        name_dialog_module.tkMessageBox = orig_mbox
 
35
 
 
36
    def test_blank_name(self):
 
37
        self.dialog.name.set(' ')
 
38
        self.assertEqual(self.dialog.name_ok(), '')
 
39
        self.assertEqual(showerror.title, 'Name Error')
 
40
        self.assertIn('No', showerror.message)
 
41
 
 
42
    def test_used_name(self):
 
43
        self.dialog.name.set('used')
 
44
        self.assertEqual(self.dialog.name_ok(), '')
 
45
        self.assertEqual(showerror.title, 'Name Error')
 
46
        self.assertIn('use', showerror.message)
 
47
 
 
48
    def test_long_name(self):
 
49
        self.dialog.name.set('good'*8)
 
50
        self.assertEqual(self.dialog.name_ok(), '')
 
51
        self.assertEqual(showerror.title, 'Name Error')
 
52
        self.assertIn('too long', showerror.message)
 
53
 
 
54
    def test_good_name(self):
 
55
        self.dialog.name.set('  good ')
 
56
        showerror.title = 'No Error'  # should not be called
 
57
        self.assertEqual(self.dialog.name_ok(), 'good')
 
58
        self.assertEqual(showerror.title, 'No Error')
 
59
 
 
60
    def test_ok(self):
 
61
        self.dialog.destroyed = False
 
62
        self.dialog.name.set('good')
 
63
        self.dialog.Ok()
 
64
        self.assertEqual(self.dialog.result, 'good')
 
65
        self.assertTrue(self.dialog.destroyed)
 
66
 
 
67
    def test_cancel(self):
 
68
        self.dialog.destroyed = False
 
69
        self.dialog.Cancel()
 
70
        self.assertEqual(self.dialog.result, '')
 
71
        self.assertTrue(self.dialog.destroyed)
 
72
 
 
73
 
 
74
if __name__ == '__main__':
 
75
    unittest.main(verbosity=2, exit=False)