From 503ab33e54f5edb3c8b925c0d7b22c892084c5db Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 30 Mar 2010 18:56:19 +0000 Subject: [PATCH] Merged revisions 79502 via svnmerge from 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 | 12 ++++++++++++ Lib/test/test_decimal.py | 6 ++++++ Lib/test/test_index.py | 2 ++ Misc/ACKS | 1 + Misc/NEWS | 2 ++ 5 files changed, 23 insertions(+) diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index a62ff8eff60..7282c0ae164 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -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) diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index dada7332bf8..360a5e89b2d 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -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 diff --git a/Lib/test/test_index.py b/Lib/test/test_index.py index 79802e2b19c..7a94af1b0ad 100644 --- a/Lib/test/test_index.py +++ b/Lib/test/test_index.py @@ -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)) diff --git a/Misc/ACKS b/Misc/ACKS index 651e6e8f99b..2442656e56f 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 6b7632160f6..d6a02928551 100644 --- 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.