Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_bool.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | 622cf101eccf |
| children |
| rev | line source |
|---|---|
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # Test properties of bool promised by PEP 285 |
|
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
3 import unittest |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
4 from test import support |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
5 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
6 import os |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
7 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
8 class BoolTest(unittest.TestCase): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
9 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
10 def test_subclass(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
11 try: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
12 class C(bool): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
13 pass |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
14 except TypeError: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
15 pass |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
16 else: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
17 self.fail("bool should not be subclassable") |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
19 self.assertRaises(TypeError, int.__new__, bool, 0) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
21 def test_print(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
22 try: |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
23 fo = open(support.TESTFN, "w") |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
24 print(False, True, file=fo) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
25 fo.close() |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
26 fo = open(support.TESTFN, "r") |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
27 self.assertEqual(fo.read(), 'False True\n') |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
28 finally: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
29 fo.close() |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
30 os.remove(support.TESTFN) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
31 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
32 def test_repr(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
33 self.assertEqual(repr(False), 'False') |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
34 self.assertEqual(repr(True), 'True') |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
35 self.assertEqual(eval(repr(False)), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
36 self.assertEqual(eval(repr(True)), True) |
|
23027
03c39640d81a
Patch #542569: tp_print tp_repr tp_str in test_bool.py.
Martin v. Löwis <martin@v.loewis.de>
parents:
22853
diff
changeset
|
37 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
38 def test_str(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
39 self.assertEqual(str(False), 'False') |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
40 self.assertEqual(str(True), 'True') |
|
23027
03c39640d81a
Patch #542569: tp_print tp_repr tp_str in test_bool.py.
Martin v. Löwis <martin@v.loewis.de>
parents:
22853
diff
changeset
|
41 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
42 def test_int(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
43 self.assertEqual(int(False), 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
44 self.assertIsNot(int(False), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
45 self.assertEqual(int(True), 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
46 self.assertIsNot(int(True), True) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 |
|
60083
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
48 def test_float(self): |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
49 self.assertEqual(float(False), 0.0) |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
50 self.assertIsNot(float(False), False) |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
51 self.assertEqual(float(True), 1.0) |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
52 self.assertIsNot(float(True), True) |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
53 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
54 def test_math(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
55 self.assertEqual(+False, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
56 self.assertIsNot(+False, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
57 self.assertEqual(-False, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
58 self.assertIsNot(-False, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
59 self.assertEqual(abs(False), 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
60 self.assertIsNot(abs(False), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
61 self.assertEqual(+True, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
62 self.assertIsNot(+True, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
63 self.assertEqual(-True, -1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
64 self.assertEqual(abs(True), 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
65 self.assertIsNot(abs(True), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
66 self.assertEqual(~False, -1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
67 self.assertEqual(~True, -2) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
69 self.assertEqual(False+2, 2) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
70 self.assertEqual(True+2, 3) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
71 self.assertEqual(2+False, 2) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
72 self.assertEqual(2+True, 3) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
73 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
74 self.assertEqual(False+False, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
75 self.assertIsNot(False+False, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
76 self.assertEqual(False+True, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
77 self.assertIsNot(False+True, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
78 self.assertEqual(True+False, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
79 self.assertIsNot(True+False, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
80 self.assertEqual(True+True, 2) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
82 self.assertEqual(True-True, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
83 self.assertIsNot(True-True, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
84 self.assertEqual(False-False, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
85 self.assertIsNot(False-False, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
86 self.assertEqual(True-False, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
87 self.assertIsNot(True-False, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
88 self.assertEqual(False-True, -1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
89 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
90 self.assertEqual(True*1, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
91 self.assertEqual(False*1, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
92 self.assertIsNot(False*1, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
93 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
94 self.assertEqual(True/1, 1) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
95 self.assertIsNot(True/1, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
96 self.assertEqual(False/1, 0) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
97 self.assertIsNot(False/1, False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
99 for b in False, True: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
100 for i in 0, 1, 2: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
101 self.assertEqual(b**i, int(b)**i) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
102 self.assertIsNot(b**i, bool(int(b)**i)) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
104 for a in False, True: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
105 for b in False, True: |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
106 self.assertIs(a&b, bool(int(a)&int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
107 self.assertIs(a|b, bool(int(a)|int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
108 self.assertIs(a^b, bool(int(a)^int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
109 self.assertEqual(a&int(b), int(a)&int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
110 self.assertIsNot(a&int(b), bool(int(a)&int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
111 self.assertEqual(a|int(b), int(a)|int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
112 self.assertIsNot(a|int(b), bool(int(a)|int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
113 self.assertEqual(a^int(b), int(a)^int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
114 self.assertIsNot(a^int(b), bool(int(a)^int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
115 self.assertEqual(int(a)&b, int(a)&int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
116 self.assertIsNot(int(a)&b, bool(int(a)&int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
117 self.assertEqual(int(a)|b, int(a)|int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
118 self.assertIsNot(int(a)|b, bool(int(a)|int(b))) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
119 self.assertEqual(int(a)^b, int(a)^int(b)) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
120 self.assertIsNot(int(a)^b, bool(int(a)^int(b))) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
122 self.assertIs(1==1, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
123 self.assertIs(1==0, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
124 self.assertIs(0<1, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
125 self.assertIs(1<0, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
126 self.assertIs(0<=0, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
127 self.assertIs(1<=0, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
128 self.assertIs(1>0, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
129 self.assertIs(1>1, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
130 self.assertIs(1>=1, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
131 self.assertIs(0>=1, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
132 self.assertIs(0!=1, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
133 self.assertIs(0!=0, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
134 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
135 x = [1] |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
136 self.assertIs(x is x, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
137 self.assertIs(x is not x, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
138 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
139 self.assertIs(1 in x, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
140 self.assertIs(0 in x, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
141 self.assertIs(1 not in x, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
142 self.assertIs(0 not in x, True) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
144 x = {1: 2} |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
145 self.assertIs(x is x, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
146 self.assertIs(x is not x, False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
148 self.assertIs(1 in x, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
149 self.assertIs(0 in x, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
150 self.assertIs(1 not in x, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
151 self.assertIs(0 not in x, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
152 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
153 self.assertIs(not True, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
154 self.assertIs(not False, True) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
156 def test_convert(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
157 self.assertRaises(TypeError, bool, 42, 42) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
158 self.assertIs(bool(10), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
159 self.assertIs(bool(1), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
160 self.assertIs(bool(-1), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
161 self.assertIs(bool(0), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
162 self.assertIs(bool("hello"), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
163 self.assertIs(bool(""), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
164 self.assertIs(bool(), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 |
|
42594
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
166 def test_format(self): |
|
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
167 self.assertEqual("%d" % False, "0") |
|
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
168 self.assertEqual("%d" % True, "1") |
|
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
169 self.assertEqual("%x" % False, "0") |
|
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
170 self.assertEqual("%x" % True, "1") |
|
ac5ce7c43ee7
Format bools properly in %d.
Martin v. Löwis <martin@v.loewis.de>
parents:
42322
diff
changeset
|
171 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
172 def test_hasattr(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
173 self.assertIs(hasattr([], "append"), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
174 self.assertIs(hasattr([], "wobble"), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
176 def test_callable(self): |
|
66521
1b77f2eb1606
Issue #10518: Bring back the callable() builtin.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60083
diff
changeset
|
177 self.assertIs(callable(len), True) |
|
1b77f2eb1606
Issue #10518: Bring back the callable() builtin.
Antoine Pitrou <solipsis@pitrou.net>
parents:
60083
diff
changeset
|
178 self.assertIs(callable(1), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
180 def test_isinstance(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
181 self.assertIs(isinstance(True, bool), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
182 self.assertIs(isinstance(False, bool), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
183 self.assertIs(isinstance(True, int), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
184 self.assertIs(isinstance(False, int), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
185 self.assertIs(isinstance(1, bool), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
186 self.assertIs(isinstance(0, bool), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
188 def test_issubclass(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
189 self.assertIs(issubclass(bool, int), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
190 self.assertIs(issubclass(int, bool), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
191 |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
39543
diff
changeset
|
192 def test_contains(self): |
|
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
39543
diff
changeset
|
193 self.assertIs(1 in {}, False) |
|
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
39543
diff
changeset
|
194 self.assertIs(1 in {1:1}, True) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
196 def test_string(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
197 self.assertIs("xyz".endswith("z"), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
198 self.assertIs("xyz".endswith("x"), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
199 self.assertIs("xyz0123".isalnum(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
200 self.assertIs("@#$%".isalnum(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
201 self.assertIs("xyz".isalpha(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
202 self.assertIs("@#$%".isalpha(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
203 self.assertIs("0123".isdigit(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
204 self.assertIs("xyz".isdigit(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
205 self.assertIs("xyz".islower(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
206 self.assertIs("XYZ".islower(), False) |
|
41625
46b00c73e32f
Remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
207 self.assertIs("0123".isdecimal(), True) |
|
46b00c73e32f
Remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
208 self.assertIs("xyz".isdecimal(), False) |
|
46b00c73e32f
Remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
209 self.assertIs("0123".isnumeric(), True) |
|
46b00c73e32f
Remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41575
diff
changeset
|
210 self.assertIs("xyz".isnumeric(), False) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
211 self.assertIs(" ".isspace(), True) |
|
41626
1440bbb67150
Add two more space tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41625
diff
changeset
|
212 self.assertIs("\xa0".isspace(), True) |
|
1440bbb67150
Add two more space tests.
Walter Dörwald <walter@livinglogic.de>
parents:
41625
diff
changeset
|
213 self.assertIs("\u3000".isspace(), True) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
214 self.assertIs("XYZ".isspace(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
215 self.assertIs("X".istitle(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
216 self.assertIs("x".istitle(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
217 self.assertIs("XYZ".isupper(), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
218 self.assertIs("xyz".isupper(), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
219 self.assertIs("xyz".startswith("x"), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
220 self.assertIs("xyz".startswith("z"), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
222 def test_boolean(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
223 self.assertEqual(True & 1, 1) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
224 self.assertNotIsInstance(True & 1, bool) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
225 self.assertIs(True & True, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
226 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
227 self.assertEqual(True | 1, 1) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
228 self.assertNotIsInstance(True | 1, bool) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
229 self.assertIs(True | True, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
230 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
231 self.assertEqual(True ^ 1, 0) |
|
58473
71acd4482e65
Merged revisions 77727 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55593
diff
changeset
|
232 self.assertNotIsInstance(True ^ 1, bool) |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
233 self.assertIs(True ^ True, False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
235 def test_fileclosed(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
236 try: |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
237 f = open(support.TESTFN, "w") |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
238 self.assertIs(f.closed, False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
239 f.close() |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
240 self.assertIs(f.closed, True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
241 finally: |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
242 os.remove(support.TESTFN) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 |
|
60083
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
244 def test_types(self): |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
245 # types are always true. |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
246 for t in [bool, complex, dict, float, int, list, object, |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
247 set, str, tuple, type]: |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
248 self.assertIs(bool(t), True) |
|
5e0ff65284fa
Merged revisions 79502 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58966
diff
changeset
|
249 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
250 def test_operator(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
251 import operator |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
252 self.assertIs(operator.truth(0), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
253 self.assertIs(operator.truth(1), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
254 self.assertIs(operator.not_(1), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
255 self.assertIs(operator.not_(0), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
256 self.assertIs(operator.contains([], 1), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
257 self.assertIs(operator.contains([1], 1), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
258 self.assertIs(operator.lt(0, 0), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
259 self.assertIs(operator.lt(0, 1), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
260 self.assertIs(operator.is_(True, True), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
261 self.assertIs(operator.is_(True, False), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
262 self.assertIs(operator.is_not(True, True), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
263 self.assertIs(operator.is_not(True, False), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
264 |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
265 def test_marshal(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
266 import marshal |
|
28916
39ad76143288
Consistently use test_support.foo everywhere.
Walter Dörwald <walter@livinglogic.de>
parents:
28863
diff
changeset
|
267 self.assertIs(marshal.loads(marshal.dumps(True)), True) |
|
39ad76143288
Consistently use test_support.foo everywhere.
Walter Dörwald <walter@livinglogic.de>
parents:
28863
diff
changeset
|
268 self.assertIs(marshal.loads(marshal.dumps(False)), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
270 def test_pickle(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
271 import pickle |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
272 self.assertIs(pickle.loads(pickle.dumps(True)), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
273 self.assertIs(pickle.loads(pickle.dumps(False)), False) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
274 self.assertIs(pickle.loads(pickle.dumps(True, True)), True) |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
275 self.assertIs(pickle.loads(pickle.dumps(False, True)), False) |
|
22787
028ebc8fb390
Oops. Here are the new files. My apologies.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
277 def test_picklevalues(self): |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
278 # Test for specific backwards-compatible pickle values |
|
39543
9bc0bc0ad1bf
Quite a few fixes to make the library and test suite more robust when
Guido van Rossum <guido@python.org>
parents:
29668
diff
changeset
|
279 import pickle |
|
41718
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
280 self.assertEqual(pickle.dumps(True, protocol=0), b"I01\n.") |
|
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
281 self.assertEqual(pickle.dumps(False, protocol=0), b"I00\n.") |
|
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
282 self.assertEqual(pickle.dumps(True, protocol=1), b"I01\n.") |
|
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
283 self.assertEqual(pickle.dumps(False, protocol=1), b"I00\n.") |
|
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
284 self.assertEqual(pickle.dumps(True, protocol=2), b'\x80\x02\x88.') |
|
6ca3d5f3d1be
Fix the picklevalue test; it broke due to the change in default protocol.
Guido van Rossum <guido@python.org>
parents:
41626
diff
changeset
|
285 self.assertEqual(pickle.dumps(False, protocol=2), b'\x80\x02\x89.') |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41269
diff
changeset
|
286 |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
287 def test_convert_to_bool(self): |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
288 # Verify that TypeError occurs when bad things are returned |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
289 # from __bool__(). This isn't really a bool test, but |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
290 # it's related. |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
291 check = lambda o: self.assertRaises(TypeError, bool, o) |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
292 class Foo(object): |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
293 def __bool__(self): |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
294 return self |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
295 check(Foo()) |
|
29668
36a17904a3ed
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
29612
diff
changeset
|
296 |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
297 class Bar(object): |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
298 def __bool__(self): |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
299 return "Yes" |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
300 check(Bar()) |
|
29668
36a17904a3ed
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
29612
diff
changeset
|
301 |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
302 class Baz(int): |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
303 def __bool__(self): |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
304 return self |
|
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
305 check(Baz()) |
|
29668
36a17904a3ed
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
29612
diff
changeset
|
306 |
|
40401
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
307 # __bool__() must return a bool not an int |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
308 class Spam(int): |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
309 def __bool__(self): |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
310 return 1 |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
311 check(Spam()) |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
312 |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
313 class Eggs: |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
314 def __len__(self): |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
315 return -1 |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
316 self.assertRaises(ValueError, bool, Eggs()) |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
317 |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
318 def test_sane_len(self): |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
319 # this test just tests our assumptions about __len__ |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
320 # this will start failing if __len__ changes assertions |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
321 for badval in ['illegal', -1, 1 << 32]: |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
322 class A: |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
323 def __len__(self): |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
324 return badval |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
325 try: |
|
88133417dfd0
- patch #1600346 submitted by Tomer Filiba
Jack Diederich <jackdied@gmail.com>
parents:
39647
diff
changeset
|
326 bool(A()) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40401
diff
changeset
|
327 except (Exception) as e_bool: |
|
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40401
diff
changeset
|
328 try: |
|
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40401
diff
changeset
|
329 len(A()) |
|
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40401
diff
changeset
|
330 except (Exception) as e_len: |
|
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40401
diff
changeset
|
331 self.assertEqual(str(e_bool), str(e_len)) |
|
29612
86342fa8920d
Add tests for __nonzero__() problems.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29087
diff
changeset
|
332 |
|
70372
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
333 def test_real_and_imag(self): |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
334 self.assertEqual(True.real, 1) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
335 self.assertEqual(True.imag, 0) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
336 self.assertIs(type(True.real), int) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
337 self.assertIs(type(True.imag), int) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
338 self.assertEqual(False.real, 0) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
339 self.assertEqual(False.imag, 0) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
340 self.assertIs(type(False.real), int) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
341 self.assertIs(type(False.imag), int) |
|
622cf101eccf
test values and types of (True/False).(imag/real)
Benjamin Peterson <benjamin@python.org>
parents:
66521
diff
changeset
|
342 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
343 def test_main(): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
42594
diff
changeset
|
344 support.run_unittest(BoolTest) |
|
22851
ed03806d88cd
Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents:
22787
diff
changeset
|
345 |
|
28822
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
346 if __name__ == "__main__": |
|
def09ec0bc31
Port test_bool.py to PyUnit. From SF patch #662807.
Walter Dörwald <walter@livinglogic.de>
parents:
28696
diff
changeset
|
347 test_main() |
