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

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

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 9 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
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 15 matching lines...) Expand all
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 class D(C): 32 class D(C):
33 @property 33 @property
34 def foo(self): return super().foo 34 def foo(self): return super().foo
35 self.assertEqual(D().foo, 3) 35 self.assertEqual(D().foo, 3)
36
37 def test_abstractmethod_with_property_builtin(self):
38 class C(metaclass=abc.ABCMeta):
39 @Property
durban 2011/03/19 21:36:09 This probably should be "property" (with a lowerca
dsdale24 2011/03/19 22:13:42 Thanks
40 @abc.abstractmethod
41 def x(self):
42 pass
43 @x.setter
44 @abc.abstractmethod
45 def x(self, val):
46 pass
47 self.assertRaises(TypeError, C)
48
49 class D(C):
50 @C.x.getter
51 def x(self):
52 return 1
53 self.assertRaises(TypeError, D)
54
55 class E(D):
56 @D.x.setter
57 def x(self, val):
58 pass
59 self.assertEqual(E().x, 1)
36 60
37 def test_abstractclassmethod_basics(self): 61 def test_abstractclassmethod_basics(self):
38 @abc.abstractclassmethod 62 @abc.abstractclassmethod
39 def foo(cls): pass 63 def foo(cls): pass
40 self.assertTrue(foo.__isabstractmethod__) 64 self.assertTrue(foo.__isabstractmethod__)
41 @classmethod 65 @classmethod
42 def bar(cls): pass 66 def bar(cls): pass
43 self.assertFalse(hasattr(bar, "__isabstractmethod__")) 67 self.assertFalse(hasattr(bar, "__isabstractmethod__"))
44 68
45 class C(metaclass=abc.ABCMeta): 69 class C(metaclass=abc.ABCMeta):
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 C() 287 C()
264 self.assertEqual(B.counter, 1) 288 self.assertEqual(B.counter, 1)
265 289
266 290
267 def test_main(): 291 def test_main():
268 support.run_unittest(TestABC) 292 support.run_unittest(TestABC)
269 293
270 294
271 if __name__ == "__main__": 295 if __name__ == "__main__":
272 unittest.main() 296 unittest.main()
OLDNEW

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