Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(172)

Unified Diff: Lib/test/test_abc.py

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/numbers.py ('k') | Misc/NEWS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_abc.py Fri Jun 10 19:05:16 2011 +0100
+++ b/Lib/test/test_abc.py Fri Jun 10 17:38:08 2011 -0400
@@ -20,6 +20,7 @@
self.assertFalse(hasattr(bar, "__isabstractmethod__"))
def test_abstractproperty_basics(self):
+ "abstractproperty is deprecated in python-3.3"
@abc.abstractproperty
def foo(self): pass
self.assertTrue(foo.__isabstractmethod__)
@@ -29,6 +30,7 @@
class C(metaclass=abc.ABCMeta):
@abc.abstractproperty
def foo(self): return 3
+ self.assertRaises(TypeError, C)
class D(C):
@property
def foo(self): return super().foo
@@ -98,6 +100,47 @@
self.assertRaises(TypeError, F) # because bar is abstract now
self.assertTrue(isabstract(F))
+ def test_descriptors_with_abstractmethod(self):
+ class C(metaclass=abc.ABCMeta):
+ @property
+ @abc.abstractmethod
+ def foo(self): return 3
+ @foo.setter
+ @abc.abstractmethod
+ def foo(self, val): pass
+ self.assertRaises(TypeError, C)
+ class D(C):
+ @C.foo.getter
+ def foo(self): return super().foo
+ self.assertRaises(TypeError, D)
+ class E(D):
+ @D.foo.setter
+ def foo(self, val): pass
+ self.assertEqual(E().foo, 3)
+ class F(C):
+ @property
+ def foo(self): return 3
+ self.assertRaises(TypeError, F)
+
+ def test_pathologically_named_descriptors(self):
+ """Test that attribute names containing "." doesn't choke ABCMeta"""
+ class MyProperty(property):
+ pass
+ class C(metaclass=abc.ABCMeta):
+ @MyProperty
+ @abc.abstractmethod
+ def foo(self): return 1
+ setattr(foo, 'pathological.desc_method', None)
+ @MyProperty
+ def bar(self): return
+ setattr(bar, 'pathological.desc_method', None)
+ setattr(self, 'pathological.bar', foo)
+ self.assertRaises(TypeError, C)
+ class D(C):
+ @C.foo.getter
+ def foo(self): return 2
+ self.assertEqual(D().foo, 2)
+
def test_metaclass_abc(self):
# Metaclasses can be ABCs, too.
class A(metaclass=abc.ABCMeta):
« no previous file with comments | « Lib/numbers.py ('k') | Misc/NEWS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+