FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test files from CPython v3.12.0 by NakanoMiku39 · Pull Request #5122 · RustPython/RustPython · GitHub

Prev Previous commit
Next Next commit
Update Lib/test/test_bool.py from CPython v3.12.0
  • Loading branch information
NakanoMiku39 committed Nov 23, 2023
commit 81208637f52cd7686e1dd213a4bb718e2c8eed12
44 changes: 42 additions & 2 deletions Lib/test/test_bool.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def test_float(self):
self.assertEqual(float(True), 1.0)
self.assertIsNot(float(True), True)

def test_complex(self):
self.assertEqual(complex(False), 0j)
self.assertEqual(complex(False), False)
self.assertEqual(complex(True), 1+0j)
self.assertEqual(complex(True), True)

def test_math(self):
self.assertEqual(+False, 0)
self.assertIsNot(+False, False)
Expand All @@ -54,8 +60,22 @@ def test_math(self):
self.assertEqual(-True, -1)
self.assertEqual(abs(True), 1)
self.assertIsNot(abs(True), True)
self.assertEqual(~False, -1)
self.assertEqual(~True, -2)
with self.assertWarns(DeprecationWarning):
# We need to put the bool in a variable, because the constant
# ~False is evaluated at compile time due to constant folding;
# consequently the DeprecationWarning would be issued during
# module loading and not during test execution.
false = False
self.assertEqual(~false, -1)
with self.assertWarns(DeprecationWarning):
# also check that the warning is issued in case of constant
# folding at compile time
self.assertEqual(eval("~False"), -1)
with self.assertWarns(DeprecationWarning):
true = True
self.assertEqual(~true, -2)
with self.assertWarns(DeprecationWarning):
self.assertEqual(eval("~True"), -2)

self.assertEqual(False+2, 2)
self.assertEqual(True+2, 3)
Expand Down Expand Up @@ -315,6 +335,26 @@ def __len__(self):
return -1
self.assertRaises(ValueError, bool, Eggs())

def test_interpreter_convert_to_bool_raises(self):
class SymbolicBool:
def __bool__(self):
raise TypeError

class Symbol:
def __gt__(self, other):
return SymbolicBool()

x = Symbol()

with self.assertRaises(TypeError):
if x > 0:
msg = "x > 0 was true"
else:
msg = "x > 0 was false"

# This used to create negative refcounts, see gh-102250
del x

def test_from_bytes(self):
self.assertIs(bool.from_bytes(b'\x00'*8, 'big'), False)
self.assertIs(bool.from_bytes(b'abcd', 'little'), True)
Expand Down

Back | FazBrowse Home | New Git URL