]> granicus.if.org Git - python/commitdiff
Add tests for getint, getdouble and getboolean methods of the tkapp object.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 30 May 2014 11:07:38 +0000 (14:07 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 30 May 2014 11:07:38 +0000 (14:07 +0300)
Lib/test/test_tcl.py

index d12fb224849f00afe6b0661ac9f50d8d6f7ba112..c226233be1a608b7f149e9ec12449002870d1a7e 100644 (file)
@@ -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: