]> granicus.if.org Git - python/commitdiff
Merged revisions 79502 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 30 Mar 2010 18:56:19 +0000 (18:56 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 30 Mar 2010 18:56:19 +0000 (18:56 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79502 | antoine.pitrou | 2010-03-30 20:49:45 +0200 (mar., 30 mars 2010) | 4 lines

  Issue #8248: Add some tests for the bool type.  Patch by Gregory Nofi.
........

Lib/test/test_bool.py
Lib/test/test_decimal.py
Lib/test/test_index.py
Misc/ACKS
Misc/NEWS

index a62ff8eff60d6dbc2b509bd22dc39d24c0d0dc1f..7282c0ae164b3f630e3bb2d4db60f8f46343210d 100644 (file)
@@ -45,6 +45,12 @@ class BoolTest(unittest.TestCase):
         self.assertEqual(int(True), 1)
         self.assertIsNot(int(True), True)
 
+    def test_float(self):
+        self.assertEqual(float(False), 0.0)
+        self.assertIsNot(float(False), False)
+        self.assertEqual(float(True), 1.0)
+        self.assertIsNot(float(True), True)
+
     def test_math(self):
         self.assertEqual(+False, 0)
         self.assertIsNot(+False, False)
@@ -235,6 +241,12 @@ class BoolTest(unittest.TestCase):
         finally:
             os.remove(support.TESTFN)
 
+    def test_types(self):
+        # types are always true.
+        for t in [bool, complex, dict, float, int, list, object,
+                  set, str, tuple, type]:
+            self.assertIs(bool(t), True)
+
     def test_operator(self):
         import operator
         self.assertIs(operator.truth(0), False)
index dada7332bf87f80cfe1fab1fc239d71f3be9dc46..360a5e89b2d07a2120e5085942cda17e30e37209 100644 (file)
@@ -472,6 +472,12 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
         self.assertRaises(ValueError, Decimal, (1, (4, 10, 4, 9, 1), 2) )
         self.assertRaises(ValueError, Decimal, (1, (4, 3, 4, 'a', 1), 2) )
 
+    def test_explicit_from_bool(self):
+        self.assertIs(bool(Decimal(0)), False)
+        self.assertIs(bool(Decimal(1)), True)
+        self.assertEqual(Decimal(False), Decimal(0))
+        self.assertEqual(Decimal(True), Decimal(1))
+
     def test_explicit_from_Decimal(self):
 
         #positive
index 79802e2b19cdad37dfe2f6b018d462d4284983d3..7a94af1b0add683fe00596c70ad3eb95c4691523 100644 (file)
@@ -39,6 +39,8 @@ class BaseTestCase(unittest.TestCase):
         self.assertEqual(-7 .__index__(), -7)
         self.assertEqual(self.o.__index__(), 4)
         self.assertEqual(self.n.__index__(), 5)
+        self.assertEqual(True.__index__(), 1)
+        self.assertEqual(False.__index__(), 0)
 
     def test_subclasses(self):
         r = list(range(10))
index 651e6e8f99b8b95a0fc55a9bf218e0d1f15ac1d3..2442656e56f43a21d8e9e33e61ea62be1e90094a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -549,6 +549,7 @@ Samuel Nicolary
 Gustavo Niemeyer
 Oscar Nierstrasz
 Hrvoje Niksic
+Gregory Nofi
 Jesse Noller
 Bill Noon
 Stefan Norberg
index 6b7632160f6136c61752b637c1074d628085063f..d6a0292855109ef848474974b5a50480b33c1dad 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -956,6 +956,8 @@ Documentation
 Tests
 -----
 
+- Issue #8248: Add some tests for the bool type.  Patch by Gregory Nofi.
+
 - Issue #8180 and #8207: Fix test_pep277 on OS X and add more tests for special
   Unicode normalization cases.