summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-30 11:08:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-30 11:08:49 (GMT)
commit88c56cbba5b7485aa2a0aac75a91b4c273253eca (patch)
tree47419bae86331141fe9fbf690c286dab1a3292b6 /Lib/test
parent35db43955cf231a4040d32c77b1ff5a4b639039f (diff)
parent9f1f4f40e460c44cbe236d7db82a4c036aa77770 (diff)
downloadcpython-88c56cbba5b7485aa2a0aac75a91b4c273253eca.zip
cpython-88c56cbba5b7485aa2a0aac75a91b4c273253eca.tar.gz
cpython-88c56cbba5b7485aa2a0aac75a91b4c273253eca.tar.bz2
Add tests for getint, getdouble and getboolean methods of the tkapp object.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_tcl.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py
index c9a558c..cc9f6c2 100644
--- a/Lib/test/test_tcl.py
+++ b/Lib/test/test_tcl.py
@@ -133,6 +133,50 @@ 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, b'42')
+ self.assertRaises(TypeError, tcl.getint, 42.0)
+ self.assertRaises(TclError, tcl.getint, 'a')
+ self.assertRaises((TypeError, ValueError, TclError),
+ tcl.getint, '42\0')
+ self.assertRaises((UnicodeEncodeError, ValueError, TclError),
+ tcl.getint, '42\ud800')
+
+ 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, b'42.5')
+ self.assertRaises(TypeError, tcl.getdouble, 42)
+ self.assertRaises(TclError, tcl.getdouble, 'a')
+ self.assertRaises((TypeError, ValueError, TclError),
+ tcl.getdouble, '42.5\0')
+ self.assertRaises((UnicodeEncodeError, ValueError, TclError),
+ tcl.getdouble, '42.5\ud800')
+
+ 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, b'on')
+ self.assertRaises(TypeError, tcl.getboolean, 1.0)
+ self.assertRaises(TclError, tcl.getboolean, 'a')
+ self.assertRaises((TypeError, ValueError, TclError),
+ tcl.getboolean, 'on\0')
+ self.assertRaises((UnicodeEncodeError, ValueError, TclError),
+ tcl.getboolean, 'on\ud800')
+
def testEvalFile(self):
tcl = self.interp
with open(support.TESTFN, 'w') as f: