diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-05-30 11:07:20 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-05-30 11:07:20 (GMT) |
commit | d11e8b6af79789cbb64202167ebdc0c4e55067af (patch) | |
tree | 2504e577056bdc265f5ff6fdb42f1d96661d06e7 /Lib | |
parent | 0344a0643d72c0a3557b329c64fc5f04be677bba (diff) | |
download | cpython-d11e8b6af79789cbb64202167ebdc0c4e55067af.zip cpython-d11e8b6af79789cbb64202167ebdc0c4e55067af.tar.gz cpython-d11e8b6af79789cbb64202167ebdc0c4e55067af.tar.bz2 |
Add tests for getint, getdouble and getboolean methods of the tkapp object.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_tcl.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index 6fa73d1..7062e7e 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -127,6 +127,53 @@ class TclTest(unittest.TestCase): tcl = self.interp self.assertRaises(TclError,tcl.unsetvar,'a') + def test_getint(self): + tcl = self.interp.tk + self.assertEqual(tcl.getint(' 42 '), 42) + self.assertEqual(tcl.getint(42), 42) + self.assertRaises(TypeError, tcl.getint) + self.assertRaises(TypeError, tcl.getint, '42', '10') + self.assertRaises(TypeError, tcl.getint, 42.0) + self.assertRaises(TclError, tcl.getint, 'a') + self.assertRaises((TypeError, ValueError, TclError), + tcl.getint, '42\0') + if test_support.have_unicode: + self.assertEqual(tcl.getint(unicode('42')), 42) + self.assertRaises((UnicodeEncodeError, ValueError, TclError), + tcl.getint, '42' + unichr(0xd800)) + + def test_getdouble(self): + tcl = self.interp.tk + self.assertEqual(tcl.getdouble(' 42 '), 42.0) + self.assertEqual(tcl.getdouble(' 42.5 '), 42.5) + self.assertEqual(tcl.getdouble(42.5), 42.5) + self.assertRaises(TypeError, tcl.getdouble) + self.assertRaises(TypeError, tcl.getdouble, '42.5', '10') + self.assertRaises(TypeError, tcl.getdouble, 42) + self.assertRaises(TclError, tcl.getdouble, 'a') + self.assertRaises((TypeError, ValueError, TclError), + tcl.getdouble, '42.5\0') + if test_support.have_unicode: + self.assertEqual(tcl.getdouble(unicode('42.5')), 42.5) + self.assertRaises((UnicodeEncodeError, ValueError, TclError), + tcl.getdouble, '42.5' + unichr(0xd800)) + + def test_getboolean(self): + tcl = self.interp.tk + self.assertIs(tcl.getboolean('on'), True) + self.assertIs(tcl.getboolean('1'), True) + self.assertEqual(tcl.getboolean(42), 42) + self.assertRaises(TypeError, tcl.getboolean) + self.assertRaises(TypeError, tcl.getboolean, 'on', '1') + self.assertRaises(TypeError, tcl.getboolean, 1.0) + self.assertRaises(TclError, tcl.getboolean, 'a') + self.assertRaises((TypeError, ValueError, TclError), + tcl.getboolean, 'on\0') + if test_support.have_unicode: + self.assertIs(tcl.getboolean(unicode('on')), True) + self.assertRaises((UnicodeEncodeError, ValueError, TclError), + tcl.getboolean, 'on' + unichr(0xd800)) + def testEvalFile(self): tcl = self.interp filename = "testEvalFile.tcl" |