summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-12 19:56:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-12 19:56:08 (GMT)
commita60c2fe4807e89a5844979fe46b3ea39572fc3be (patch)
tree0177eec0d55bb6325897ed7a19db9dad2e5df304 /Lib/test
parent18987a11ce0f8f55aa6ec63a9d2f8e84d7460984 (diff)
downloadcpython-a60c2fe4807e89a5844979fe46b3ea39572fc3be.zip
cpython-a60c2fe4807e89a5844979fe46b3ea39572fc3be.tar.gz
cpython-a60c2fe4807e89a5844979fe46b3ea39572fc3be.tar.bz2
Issue #23641: Cleaned out legacy dunder names from tests and docs.
Fixed 2 to 3 porting bug in pynche.ColorDB.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/mapping_tests.py2
-rw-r--r--Lib/test/test_abc.py4
-rw-r--r--Lib/test/test_augassign.py8
-rw-r--r--Lib/test/test_class.py34
-rw-r--r--Lib/test/test_descr.py24
-rw-r--r--Lib/test/test_dynamicclassattribute.py4
-rw-r--r--Lib/test/test_inspect.py2
-rw-r--r--Lib/test/test_itertools.py2
-rw-r--r--Lib/test/test_property.py4
-rw-r--r--Lib/test/test_unicode.py56
10 files changed, 50 insertions, 90 deletions
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py
index bc12c77..ff82f4e 100644
--- a/Lib/test/mapping_tests.py
+++ b/Lib/test/mapping_tests.py
@@ -64,7 +64,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
self.assertEqual(d, d)
self.assertNotEqual(p, d)
self.assertNotEqual(d, p)
- #__non__zero__
+ #bool
if p: self.fail("Empty mapping must compare to False")
if not d: self.fail("Full mapping must compare to True")
# keys(), items(), iterkeys() ...
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 93f9dae..e1765f0 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -194,9 +194,9 @@ class TestABC(unittest.TestCase):
# check that the property's __isabstractmethod__ descriptor does the
# right thing when presented with a value that fails truth testing:
class NotBool(object):
- def __nonzero__(self):
+ def __bool__(self):
raise ValueError()
- __len__ = __nonzero__
+ __len__ = __bool__
with self.assertRaises(ValueError):
class F(C):
def bar(self):
diff --git a/Lib/test/test_augassign.py b/Lib/test/test_augassign.py
index 9a59c58..0e75c6b 100644
--- a/Lib/test/test_augassign.py
+++ b/Lib/test/test_augassign.py
@@ -136,14 +136,6 @@ class AugAssignTest(unittest.TestCase):
output.append("__imul__ called")
return self
- def __div__(self, val):
- output.append("__div__ called")
- def __rdiv__(self, val):
- output.append("__rdiv__ called")
- def __idiv__(self, val):
- output.append("__idiv__ called")
- return self
-
def __floordiv__(self, val):
output.append("__floordiv__ called")
return self
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index c7003fb..e3883d6 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -15,6 +15,8 @@ testmeths = [
"rmul",
"truediv",
"rtruediv",
+ "floordiv",
+ "rfloordiv",
"mod",
"rmod",
"divmod",
@@ -174,15 +176,23 @@ class ClassTests(unittest.TestCase):
1 * testme
self.assertCallStack([("__rmul__", (testme, 1))])
- if 1/2 == 0:
- callLst[:] = []
- testme / 1
- self.assertCallStack([("__div__", (testme, 1))])
+ callLst[:] = []
+ testme / 1
+ self.assertCallStack([("__truediv__", (testme, 1))])
+
+ callLst[:] = []
+ 1 / testme
+ self.assertCallStack([("__rtruediv__", (testme, 1))])
- callLst[:] = []
- 1 / testme
- self.assertCallStack([("__rdiv__", (testme, 1))])
+ callLst[:] = []
+ testme // 1
+ self.assertCallStack([("__floordiv__", (testme, 1))])
+
+
+ callLst[:] = []
+ 1 // testme
+ self.assertCallStack([("__rfloordiv__", (testme, 1))])
callLst[:] = []
testme % 1
@@ -444,12 +454,16 @@ class ClassTests(unittest.TestCase):
def __int__(self):
return None
__float__ = __int__
+ __complex__ = __int__
__str__ = __int__
__repr__ = __int__
- __oct__ = __int__
- __hex__ = __int__
+ __bytes__ = __int__
+ __bool__ = __int__
+ __index__ = __int__
+ def index(x):
+ return [][x]
- for f in [int, float, str, repr, oct, hex]:
+ for f in [float, complex, str, repr, bytes, bin, oct, hex, bool, index]:
self.assertRaises(TypeError, f, BadTypeClass())
def testHashStuff(self):
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 1de2a99..9a60a12 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -21,7 +21,8 @@ class OperatorsTest(unittest.TestCase):
'add': '+',
'sub': '-',
'mul': '*',
- 'div': '/',
+ 'truediv': '/',
+ 'floordiv': '//',
'divmod': 'divmod',
'pow': '**',
'lshift': '<<',
@@ -52,8 +53,6 @@ class OperatorsTest(unittest.TestCase):
'invert': '~',
'int': 'int',
'float': 'float',
- 'oct': 'oct',
- 'hex': 'hex',
}
for name, expr in list(self.unops.items()):
@@ -82,12 +81,6 @@ class OperatorsTest(unittest.TestCase):
def binop_test(self, a, b, res, expr="a+b", meth="__add__"):
d = {'a': a, 'b': b}
- # XXX Hack so this passes before 2.3 when -Qnew is specified.
- if meth == "__div__" and 1/2 == 0.5:
- meth = "__truediv__"
-
- if meth == '__divmod__': pass
-
self.assertEqual(eval(expr, d), res)
t = type(a)
m = getattr(t, meth)
@@ -221,7 +214,7 @@ class OperatorsTest(unittest.TestCase):
def number_operators(self, a, b, skip=[]):
dict = {'a': a, 'b': b}
- for name, expr in list(self.binops.items()):
+ for name, expr in self.binops.items():
if name not in skip:
name = "__%s__" % name
if hasattr(a, name):
@@ -261,7 +254,7 @@ class OperatorsTest(unittest.TestCase):
# Testing complex operations...
self.number_operators(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge',
'int', 'float',
- 'divmod', 'mod'])
+ 'floordiv', 'divmod', 'mod'])
class Number(complex):
__slots__ = ['prec']
@@ -4160,9 +4153,8 @@ order (MRO) for bases """
('__add__', 'x + y', 'x += y'),
('__sub__', 'x - y', 'x -= y'),
('__mul__', 'x * y', 'x *= y'),
- ('__truediv__', 'operator.truediv(x, y)', None),
- ('__floordiv__', 'operator.floordiv(x, y)', None),
- ('__div__', 'x / y', 'x /= y'),
+ ('__truediv__', 'x / y', 'x /= y'),
+ ('__floordiv__', 'x // y', 'x //= y'),
('__mod__', 'x % y', 'x %= y'),
('__divmod__', 'divmod(x, y)', None),
('__pow__', 'x ** y', 'x **= y'),
@@ -4224,8 +4216,8 @@ order (MRO) for bases """
# Also check type_getattro for correctness.
class Meta(type):
pass
- class X(object):
- __metaclass__ = Meta
+ class X(metaclass=Meta):
+ pass
X.a = 42
Meta.a = Descr("a")
self.assertEqual(X.a, 42)
diff --git a/Lib/test/test_dynamicclassattribute.py b/Lib/test/test_dynamicclassattribute.py
index 079d6c3..bc6a39b 100644
--- a/Lib/test/test_dynamicclassattribute.py
+++ b/Lib/test/test_dynamicclassattribute.py
@@ -158,9 +158,9 @@ class PropertyTests(unittest.TestCase):
# check that the DynamicClassAttribute's __isabstractmethod__ descriptor does the
# right thing when presented with a value that fails truth testing:
class NotBool(object):
- def __nonzero__(self):
+ def __bool__(self):
raise ValueError()
- __len__ = __nonzero__
+ __len__ = __bool__
with self.assertRaises(ValueError):
class C(object):
def foo(self):
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index fc3bf07..a2bb9b6 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -786,7 +786,7 @@ class TestClassesAndFunctions(unittest.TestCase):
class Meta(type):
fish = 'slap'
def __dir__(self):
- return ['__class__', '__modules__', '__name__', 'fish']
+ return ['__class__', '__module__', '__name__', 'fish']
class Class(metaclass=Meta):
pass
should_find = inspect.Attribute('fish', 'data', Meta, 'slap')
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 244598b..eb51be4 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -698,7 +698,7 @@ class TestBasicOps(unittest.TestCase):
# iter.__next__ failure on inner object
self.assertRaises(ExpectedError, gulp, delayed_raise(1))
- # __cmp__ failure
+ # __eq__ failure
class DummyCmp:
def __eq__(self, dst):
raise ExpectedError
diff --git a/Lib/test/test_property.py b/Lib/test/test_property.py
index 96eeb88..cee7203 100644
--- a/Lib/test/test_property.py
+++ b/Lib/test/test_property.py
@@ -140,9 +140,9 @@ class PropertyTests(unittest.TestCase):
# check that the property's __isabstractmethod__ descriptor does the
# right thing when presented with a value that fails truth testing:
class NotBool(object):
- def __nonzero__(self):
+ def __bool__(self):
raise ValueError()
- __len__ = __nonzero__
+ __len__ = __bool__
with self.assertRaises(ValueError):
class C(object):
def foo(self):
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 7735a6b..4f45d39 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1988,64 +1988,26 @@ class UnicodeTest(string_tests.CommonTest,
self.fail("Should have raised UnicodeDecodeError")
def test_conversion(self):
- # Make sure __unicode__() works properly
- class Foo0:
+ # Make sure __str__() works properly
+ class ObjectToStr:
def __str__(self):
return "foo"
- class Foo1:
+ class StrSubclassToStr(str):
def __str__(self):
return "foo"
- class Foo2(object):
- def __str__(self):
- return "foo"
-
- class Foo3(object):
- def __str__(self):
- return "foo"
-
- class Foo4(str):
- def __str__(self):
- return "foo"
-
- class Foo5(str):
- def __str__(self):
- return "foo"
-
- class Foo6(str):
- def __str__(self):
- return "foos"
-
- def __str__(self):
- return "foou"
-
- class Foo7(str):
- def __str__(self):
- return "foos"
- def __str__(self):
- return "foou"
-
- class Foo8(str):
+ class StrSubclassToStrSubclass(str):
def __new__(cls, content=""):
return str.__new__(cls, 2*content)
def __str__(self):
return self
- class Foo9(str):
- def __str__(self):
- return "not unicode"
-
- self.assertEqual(str(Foo0()), "foo")
- self.assertEqual(str(Foo1()), "foo")
- self.assertEqual(str(Foo2()), "foo")
- self.assertEqual(str(Foo3()), "foo")
- self.assertEqual(str(Foo4("bar")), "foo")
- self.assertEqual(str(Foo5("bar")), "foo")
- self.assertEqual(str(Foo6("bar")), "foou")
- self.assertEqual(str(Foo7("bar")), "foou")
- self.assertEqual(str(Foo8("foo")), "foofoo")
- self.assertEqual(str(Foo9("foo")), "not unicode")
+ self.assertEqual(str(ObjectToStr()), "foo")
+ self.assertEqual(str(StrSubclassToStr("bar")), "foo")
+ s = str(StrSubclassToStrSubclass("foo"))
+ self.assertEqual(s, "foofoo")
+ self.assertIs(type(s), StrSubclassToStrSubclass)
def test_unicode_repr(self):
class s1: