Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename Mock to With.
  • Loading branch information
serhiy-storchaka committed May 30, 2024
commit 90029cf3e3314a56f404df1716582c0b4a780668
68 changes: 34 additions & 34 deletions Lib/test/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
(1, 0+0j),
)

class MockIndex:
class WithIndex:
def __init__(self, value):
self.value = value
def __index__(self):
return self.value

class MockFloat:
class WithFloat:
def __init__(self, value):
self.value = value
def __float__(self):
Expand All @@ -36,7 +36,7 @@ def __float__(self):
class ComplexSubclass(complex):
pass

class MockComplex:
class WithComplex:
def __init__(self, value):
self.value = value
def __complex__(self):
Expand Down Expand Up @@ -372,7 +372,7 @@ def check(z, x, y):
check(complex(4.25+0j), 4.25, 0.0)
check(complex(4.25+0.5j), 4.25, 0.5)
check(complex(ComplexSubclass(4.25+0.5j)), 4.25, 0.5)
check(complex(MockComplex(4.25+0.5j)), 4.25, 0.5)
check(complex(WithComplex(4.25+0.5j)), 4.25, 0.5)

check(complex(1, 10), 1.0, 10.0)
check(complex(1, 10.0), 1.0, 10.0)
Expand All @@ -389,8 +389,8 @@ def check(z, x, y):
"argument 'real' must be a real number, not .*ComplexSubclass"):
check(complex(ComplexSubclass(4.25+0j), 0), 4.25, 0.0)
with self.assertWarnsRegex(DeprecationWarning,
"argument 'real' must be a real number, not .*MockComplex"):
check(complex(MockComplex(4.25+0j), 0), 4.25, 0.0)
"argument 'real' must be a real number, not .*WithComplex"):
check(complex(WithComplex(4.25+0j), 0), 4.25, 0.0)
with self.assertWarnsRegex(DeprecationWarning,
"argument 'real' must be a real number, not complex"):
check(complex(4.25j, 0), 0.0, 4.25)
Expand All @@ -404,8 +404,8 @@ def check(z, x, y):
"argument 'imag' must be a real number, not .*ComplexSubclass"):
check(complex(0, ComplexSubclass(4.25+0j)), 0.0, 4.25)
with self.assertRaisesRegex(TypeError,
"argument 'imag' must be a real number, not .*MockComplex"):
complex(0, MockComplex(4.25+0j))
"argument 'imag' must be a real number, not .*WithComplex"):
complex(0, WithComplex(4.25+0j))
with self.assertWarnsRegex(DeprecationWarning,
"argument 'imag' must be a real number, not complex"):
check(complex(0.0, 4.25j), -4.25, 0.0)
Expand Down Expand Up @@ -467,13 +467,13 @@ def check(z, x, y):
"argument 'imag' must be a real number, not str",
complex, 0, '1')

self.assertRaises(TypeError, complex, MockComplex(1.5))
self.assertRaises(TypeError, complex, MockComplex(1))
self.assertRaises(TypeError, complex, MockComplex(None))
self.assertRaises(TypeError, complex, MockComplex(4.25+0j), object())
self.assertRaises(TypeError, complex, MockComplex(1.5), object())
self.assertRaises(TypeError, complex, MockComplex(1), object())
self.assertRaises(TypeError, complex, MockComplex(None), object())
self.assertRaises(TypeError, complex, WithComplex(1.5))
self.assertRaises(TypeError, complex, WithComplex(1))
self.assertRaises(TypeError, complex, WithComplex(None))
self.assertRaises(TypeError, complex, WithComplex(4.25+0j), object())
self.assertRaises(TypeError, complex, WithComplex(1.5), object())
self.assertRaises(TypeError, complex, WithComplex(1), object())
self.assertRaises(TypeError, complex, WithComplex(None), object())

class EvilExc(Exception):
pass
Expand All @@ -484,25 +484,25 @@ def __complex__(self):

self.assertRaises(EvilExc, complex, evilcomplex())

check(complex(MockFloat(4.25)), 4.25, 0.0)
check(complex(MockFloat(4.25), 1.5), 4.25, 1.5)
check(complex(1.5, MockFloat(4.25)), 1.5, 4.25)
self.assertRaises(TypeError, complex, MockFloat(42))
self.assertRaises(TypeError, complex, MockFloat(42), 1.5)
self.assertRaises(TypeError, complex, 1.5, MockFloat(42))
self.assertRaises(TypeError, complex, MockFloat(None))
self.assertRaises(TypeError, complex, MockFloat(None), 1.5)
self.assertRaises(TypeError, complex, 1.5, MockFloat(None))

check(complex(MockIndex(42)), 42.0, 0.0)
check(complex(MockIndex(42), 1.5), 42.0, 1.5)
check(complex(1.5, MockIndex(42)), 1.5, 42.0)
self.assertRaises(OverflowError, complex, MockIndex(2**2000))
self.assertRaises(OverflowError, complex, MockIndex(2**2000), 1.5)
self.assertRaises(OverflowError, complex, 1.5, MockIndex(2**2000))
self.assertRaises(TypeError, complex, MockIndex(None))
self.assertRaises(TypeError, complex, MockIndex(None), 1.5)
self.assertRaises(TypeError, complex, 1.5, MockIndex(None))
check(complex(WithFloat(4.25)), 4.25, 0.0)
check(complex(WithFloat(4.25), 1.5), 4.25, 1.5)
check(complex(1.5, WithFloat(4.25)), 1.5, 4.25)
self.assertRaises(TypeError, complex, WithFloat(42))
self.assertRaises(TypeError, complex, WithFloat(42), 1.5)
self.assertRaises(TypeError, complex, 1.5, WithFloat(42))
self.assertRaises(TypeError, complex, WithFloat(None))
self.assertRaises(TypeError, complex, WithFloat(None), 1.5)
self.assertRaises(TypeError, complex, 1.5, WithFloat(None))

check(complex(WithIndex(42)), 42.0, 0.0)
check(complex(WithIndex(42), 1.5), 42.0, 1.5)
check(complex(1.5, WithIndex(42)), 1.5, 42.0)
self.assertRaises(OverflowError, complex, WithIndex(2**2000))
self.assertRaises(OverflowError, complex, WithIndex(2**2000), 1.5)
self.assertRaises(OverflowError, complex, 1.5, WithIndex(2**2000))
self.assertRaises(TypeError, complex, WithIndex(None))
self.assertRaises(TypeError, complex, WithIndex(None), 1.5)
self.assertRaises(TypeError, complex, 1.5, WithIndex(None))

class MyInt:
def __int__(self):
Expand Down