diff -r bf3631622be4 Lib/test/test_bound_method_repr.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/test/test_bound_method_repr.py Tue Aug 19 22:38:03 2014 -0700 @@ -0,0 +1,82 @@ +import unittest +from test import support +from types import MethodType + +class TestBoundMethodRepr(unittest.TestCase): + def test_basic_method_repr(self): + class Foo: + def method(self): + pass + + f = Foo() + self.assertRegex(repr(f.method), + r">") + + + def test_inherited_method_repr(self): + class Base: + def method(self): + pass + + class Derived1(Base): + pass + + class Derived2(Base): + def method(self): + pass + + base = Base() + derived1 = Derived1() + derived2 = Derived2() + super_d2 = super(Derived2, derived2) + + self.assertRegex(repr(base.method), + r">") + self.assertRegex(repr(derived1.method), + r">") + self.assertRegex(repr(derived2.method), + r">") + self.assertRegex(repr(super_d2.method), + r">") + + + def test_classmethod_repr(self): + class Foo: + @classmethod + def method(cls): + pass + + foo = Foo() + + self.assertRegex(repr(foo.method), # access via instance + r">") + self.assertRegex(repr(Foo.method), # access via the class + r">") + + + def test_strange_method_repr(self): + class MyCallable: + def __call__(self, arg): + pass + + func = MyCallable() # func has no __name__ or __qualname__ attributes + instance = object() + method = MethodType(func, instance) + + self.assertRegex(repr(method), + r">") + + func.__name__ = "name" + self.assertRegex(repr(method), + r">") + + func.__qualname__ = "qualname" + self.assertRegex(repr(method), + r">") + + +def test_main(): + support.run_unittest(TestBoundMethodRepr) + +if __name__ == "__main__": + test_main() diff -r bf3631622be4 Lib/test/test_defaultdict.py --- a/Lib/test/test_defaultdict.py Tue Aug 19 20:32:08 2014 -0700 +++ b/Lib/test/test_defaultdict.py Tue Aug 19 22:38:03 2014 -0700 @@ -157,8 +157,9 @@ def _factory(self): return [] d = sub() - self.assertTrue(repr(d).startswith( - "defaultdict(, \{\}\)") # NOTE: printing a subclass of a builtin type does not call its # tp_print slot. So this part is essentially the same test as above.