[Python-checkins] r79502 - in python/trunk: Lib/test/test_bool.py Lib/test/test_decimal.py Lib/test/test_index.py Misc/ACKS Misc/NEWS
antoine.pitrou
python-checkins at python.org
Tue Mar 30 20:49:46 CEST 2010
Author: antoine.pitrou
Date: Tue Mar 30 20:49:45 2010
New Revision: 79502
Log:
Issue #8248: Add some tests for the bool type. Patch by Gregory Nofi.
Modified:
python/trunk/Lib/test/test_bool.py
python/trunk/Lib/test/test_decimal.py
python/trunk/Lib/test/test_index.py
python/trunk/Misc/ACKS
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/test/test_bool.py
==============================================================================
--- python/trunk/Lib/test/test_bool.py (original)
+++ python/trunk/Lib/test/test_bool.py Tue Mar 30 20:49:45 2010
@@ -45,6 +45,18 @@
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_long(self):
+ self.assertEqual(int(False), 0L)
+ self.assertIsNot(int(False), False)
+ self.assertEqual(int(True), 1L)
+ self.assertIsNot(int(True), True)
+
def test_math(self):
self.assertEqual(+False, 0)
self.assertIsNot(+False, False)
@@ -157,6 +169,12 @@
self.assertIs(bool(""), False)
self.assertIs(bool(), False)
+ def test_format(self):
+ self.assertEqual("%d" % False, "0")
+ self.assertEqual("%d" % True, "1")
+ self.assertEqual("%x" % False, "0")
+ self.assertEqual("%x" % True, "1")
+
def test_hasattr(self):
self.assertIs(hasattr([], "append"), True)
self.assertIs(hasattr([], "wobble"), False)
@@ -251,6 +269,12 @@
finally:
os.remove(test_support.TESTFN)
+ def test_types(self):
+ # types are always true.
+ for t in [bool, complex, dict, file, float, int, list, long, object,
+ set, str, tuple, type]:
+ self.assertIs(bool(t), True)
+
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
Modified: python/trunk/Lib/test/test_decimal.py
==============================================================================
--- python/trunk/Lib/test/test_decimal.py (original)
+++ python/trunk/Lib/test/test_decimal.py Tue Mar 30 20:49:45 2010
@@ -476,6 +476,12 @@
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
Modified: python/trunk/Lib/test/test_index.py
==============================================================================
--- python/trunk/Lib/test/test_index.py (original)
+++ python/trunk/Lib/test/test_index.py Tue Mar 30 20:49:45 2010
@@ -49,6 +49,8 @@
self.assertEqual(-7L.__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 = range(10)
Modified: python/trunk/Misc/ACKS
==============================================================================
--- python/trunk/Misc/ACKS (original)
+++ python/trunk/Misc/ACKS Tue Mar 30 20:49:45 2010
@@ -545,6 +545,7 @@
Gustavo Niemeyer
Oscar Nierstrasz
Hrvoje Niksic
+Gregory Nofi
Jesse Noller
Bill Noon
Stefan Norberg
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Mar 30 20:49:45 2010
@@ -164,6 +164,8 @@
Tests
-----
+- Issue #8248: Add some tests for the bool type. Patch by Gregory Nofi.
+
- Issue #8263: Now regrtest.py will report a failure if it receives a
KeyboardInterrupt (SIGINT).
More information about the Python-checkins
mailing list