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

Side by Side Diff: Lib/test/test_abc.py

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 10 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « Lib/abc.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2007 Google, Inc. All Rights Reserved. 1 # Copyright 2007 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """Unit tests for abc.py.""" 4 """Unit tests for abc.py."""
5 5
6 import unittest 6 import unittest
7 from test import support 7 from test import support
8 8
9 import abc 9 import abc
10 from inspect import isabstract 10 from inspect import isabstract
(...skipping 11 matching lines...) Expand all
22 def test_abstractproperty_basics(self): 22 def test_abstractproperty_basics(self):
23 @abc.abstractproperty 23 @abc.abstractproperty
24 def foo(self): pass 24 def foo(self): pass
25 self.assertTrue(foo.__isabstractmethod__) 25 self.assertTrue(foo.__isabstractmethod__)
26 def bar(self): pass 26 def bar(self): pass
27 self.assertFalse(hasattr(bar, "__isabstractmethod__")) 27 self.assertFalse(hasattr(bar, "__isabstractmethod__"))
28 28
29 class C(metaclass=abc.ABCMeta): 29 class C(metaclass=abc.ABCMeta):
30 @abc.abstractproperty 30 @abc.abstractproperty
31 def foo(self): return 3 31 def foo(self): return 3
32 self.assertRaises(TypeError, C)
32 class D(C): 33 class D(C):
33 @property 34 @property
34 def foo(self): return super().foo 35 def foo(self): return super().foo
35 self.assertEqual(D().foo, 3) 36 self.assertEqual(D().foo, 3)
36 37
38 def test_abstractproperty_with_subclassing(self):
39 class C(metaclass=abc.ABCMeta):
40 @abc.abstractproperty
41 @abc.abstractmethod
42 def foo(self): return 3
43 @foo.setter
44 @abc.abstractmethod
45 def foo(self, val): pass
46 self.assertRaises(TypeError, C)
47 class D(C):
48 @C.foo.getter
49 def foo(self): return super().foo
50 self.assertRaises(TypeError, D)
51 self.assertTrue(isinstance(D.foo, abc.abstractproperty))
52 class E(D):
53 @D.foo.setter
54 def foo(self, val): pass
55 self.assertEqual(E().foo, 3)
56 self.assertFalse(isinstance(E.foo, abc.abstractproperty))
57 self.assertTrue(isinstance(E.foo, property))
58
37 def test_abstractclassmethod_basics(self): 59 def test_abstractclassmethod_basics(self):
38 @abc.abstractclassmethod 60 @abc.abstractclassmethod
39 def foo(cls): pass 61 def foo(cls): pass
40 self.assertTrue(foo.__isabstractmethod__) 62 self.assertTrue(foo.__isabstractmethod__)
41 @classmethod 63 @classmethod
42 def bar(cls): pass 64 def bar(cls): pass
43 self.assertFalse(hasattr(bar, "__isabstractmethod__")) 65 self.assertFalse(hasattr(bar, "__isabstractmethod__"))
44 66
45 class C(metaclass=abc.ABCMeta): 67 class C(metaclass=abc.ABCMeta):
46 @abc.abstractclassmethod 68 @abc.abstractclassmethod
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 C() 285 C()
264 self.assertEqual(B.counter, 1) 286 self.assertEqual(B.counter, 1)
265 287
266 288
267 def test_main(): 289 def test_main():
268 support.run_unittest(TestABC) 290 support.run_unittest(TestABC)
269 291
270 292
271 if __name__ == "__main__": 293 if __name__ == "__main__":
272 unittest.main() 294 unittest.main()
OLDNEW
« no previous file with comments | « Lib/abc.py ('k') | no next file » | no next file with comments »

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