summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_with.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-11-22 01:24:23 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-11-22 01:24:23 (GMT)
commita3fec1543dc252934e79a4a50b1cbbf4708b4e7e (patch)
tree9388fdfbb31412809a450f2aeb86da9baef5a84c /Lib/test/test_with.py
parent4e17e042376ee5c64fad538bba19d786bbdf391c (diff)
downloadcpython-a3fec1543dc252934e79a4a50b1cbbf4708b4e7e.zip
cpython-a3fec1543dc252934e79a4a50b1cbbf4708b4e7e.tar.gz
cpython-a3fec1543dc252934e79a4a50b1cbbf4708b4e7e.tar.bz2
Issue #27100: With statement reports missing __enter__ before __exit__. (Contributed by Jonathan Ellington.)
Diffstat (limited to 'Lib/test/test_with.py')
-rw-r--r--Lib/test/test_with.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index e247ff6..cbb85da 100644
--- a/Lib/test/test_with.py
+++ b/Lib/test/test_with.py
@@ -109,7 +109,7 @@ class FailureTestCase(unittest.TestCase):
with foo: pass
self.assertRaises(NameError, fooNotDeclared)
- def testEnterAttributeError(self):
+ def testEnterAttributeError1(self):
class LacksEnter(object):
def __exit__(self, type, value, traceback):
pass
@@ -117,7 +117,16 @@ class FailureTestCase(unittest.TestCase):
def fooLacksEnter():
foo = LacksEnter()
with foo: pass
- self.assertRaises(AttributeError, fooLacksEnter)
+ self.assertRaisesRegexp(AttributeError, '__enter__', fooLacksEnter)
+
+ def testEnterAttributeError2(self):
+ class LacksEnterAndExit(object):
+ pass
+
+ def fooLacksEnterAndExit():
+ foo = LacksEnterAndExit()
+ with foo: pass
+ self.assertRaisesRegexp(AttributeError, '__enter__', fooLacksEnterAndExit)
def testExitAttributeError(self):
class LacksExit(object):
@@ -127,7 +136,7 @@ class FailureTestCase(unittest.TestCase):
def fooLacksExit():
foo = LacksExit()
with foo: pass
- self.assertRaises(AttributeError, fooLacksExit)
+ self.assertRaisesRegexp(AttributeError, '__exit__', fooLacksExit)
def assertRaisesSyntaxError(self, codestr):
def shouldRaiseSyntaxError(s):