summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-30 11:07:38 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-30 11:07:38 (GMT)
commit9f1f4f40e460c44cbe236d7db82a4c036aa77770 (patch)
treea4709987caeb8a5791071cafa8599a8989086c4a
parent0af8a86be85ecf1899d0770c6d31541128ea8cad (diff)
downloadcpython-9f1f4f40e460c44cbe236d7db82a4c036aa77770.zip
cpython-9f1f4f40e460c44cbe236d7db82a4c036aa77770.tar.gz
cpython-9f1f4f40e460c44cbe236d7db82a4c036aa77770.tar.bz2
Add tests for getint, getdouble and getboolean methods of the tkapp object.
-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 d12fb22..c226233 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: