summaryrefslogtreecommitdiff
path: root/Lib/test/test_contextlib.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@microsoft.com>2017-02-06 14:12:19 -0800
committerSteve Dower <steve.dower@microsoft.com>2017-02-06 14:12:19 -0800
commit5b4df5813c20fe96f117d0201965b52e86a1a66d (patch)
treed991f61bc824ca1b1b92bf7fb16fe3dacd4b1335 /Lib/test/test_contextlib.py
parent3e0bdff8a0793d305b972f4a653e4698d440b3ae (diff)
parent95b272b4e0d5438a12702e51e05d03f5a5a8e505 (diff)
downloadcpython-5b4df5813c20fe96f117d0201965b52e86a1a66d.tar.gz
Includes ensurepip and venv packages in nuget package.
Diffstat (limited to 'Lib/test/test_contextlib.py')
-rw-r--r--Lib/test/test_contextlib.py35
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