diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-20 05:30:31 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-06-20 05:30:31 +0300 |
commit | 5eb1b24eb5ed234f2a53b9936bcd9e11535ce280 (patch) | |
tree | fdd67808243ff96ce8717de1de598a3471e6fe59 /Lib/test/test_contextlib.py | |
parent | 596b094ed669e84cc7790d26b20777f8e466b150 (diff) | |
parent | 7d742d8ed628b0d5fd74e1b902b59b72da14364f (diff) | |
download | cpython-5eb1b24eb5ed234f2a53b9936bcd9e11535ce280.tar.gz |
Added more tests for issue #27122.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r-- | Lib/test/test_contextlib.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index 516403ef65..c04c804af5 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -12,6 +12,39 @@ except ImportError: threading = None +class TestAbstractContextManager(unittest.TestCase): + + def test_enter(self): + class DefaultEnter(AbstractContextManager): + def __exit__(self, *args): + super().__exit__(*args) + + manager = DefaultEnter() + self.assertIs(manager.__enter__(), manager) + + def test_exit_is_abstract(self): + class MissingExit(AbstractContextManager): + pass + + with self.assertRaises(TypeError): + MissingExit() + + def test_structural_subclassing(self): + class ManagerFromScratch: + def __enter__(self): + return self + def __exit__(self, exc_type, exc_value, traceback): + return None + + self.assertTrue(issubclass(ManagerFromScratch, AbstractContextManager)) + + class DefaultEnter(AbstractContextManager): + def __exit__(self, *args): + super().__exit__(*args) + + self.assertTrue(issubclass(DefaultEnter, AbstractContextManager)) + + class ContextManagerTestCase(unittest.TestCase): def test_contextmanager_plain(self): @@ -89,7 +122,7 @@ class ContextManagerTestCase(unittest.TestCase): def woohoo(): yield try: - with self.assertWarnsRegex(PendingDeprecationWarning, + with self.assertWarnsRegex(DeprecationWarning, "StopIteration"): with woohoo(): raise stop_exc |