summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
diff options
context:
space:
mode:
authorBen Avrahami <avrahami.ben@gmail.com>2020-10-06 17:40:50 (GMT)
committerGitHub <noreply@github.com>2020-10-06 17:40:50 (GMT)
commitbef7d299eb911086ea5a7ccf7a9da337e38a8491 (patch)
tree25508f320dada76441df02c0ce5b756608524b39 /Lib/test/test_dataclasses.py
parenta8bf44d04915f7366d9f8dfbf84822ac37a4bab3 (diff)
downloadcpython-bef7d299eb911086ea5a7ccf7a9da337e38a8491.zip
cpython-bef7d299eb911086ea5a7ccf7a9da337e38a8491.tar.gz
cpython-bef7d299eb911086ea5a7ccf7a9da337e38a8491.tar.bz2
bpo-41905: Add abc.update_abstractmethods() (GH-22485)
This function recomputes `cls.__abstractmethods__`. Also update `@dataclass` to use it.
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r--Lib/test/test_dataclasses.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index b20103b..b31a469 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -4,6 +4,7 @@
from dataclasses import *
+import abc
import pickle
import inspect
import builtins
@@ -3332,6 +3333,42 @@ class TestReplace(unittest.TestCase):
## replace(c, x=5)
+class TestAbstract(unittest.TestCase):
+ def test_abc_implementation(self):
+ class Ordered(abc.ABC):
+ @abc.abstractmethod
+ def __lt__(self, other):
+ pass
+
+ @abc.abstractmethod
+ def __le__(self, other):
+ pass
+
+ @dataclass(order=True)
+ class Date(Ordered):
+ year: int
+ month: 'Month'
+ day: 'int'
+
+ self.assertFalse(inspect.isabstract(Date))
+ self.assertGreater(Date(2020,12,25), Date(2020,8,31))
+
+ def test_maintain_abc(self):
+ class A(abc.ABC):
+ @abc.abstractmethod
+ def foo(self):
+ pass
+
+ @dataclass
+ class Date(A):
+ year: int
+ month: 'Month'
+ day: 'int'
+
+ self.assertTrue(inspect.isabstract(Date))
+ msg = 'class Date with abstract method foo'
+ self.assertRaisesRegex(TypeError, msg, Date)
+
if __name__ == '__main__':
unittest.main()