summaryrefslogtreecommitdiff
path: root/Lib/test/test_with.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_with.py')
-rw-r--r--Lib/test/test_with.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py
index e8d789bc2c..c70f6859b4 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.assertRaisesRegex(AttributeError, '__enter__', fooLacksEnter)
+
+ def testEnterAttributeError2(self):
+ class LacksEnterAndExit(object):
+ pass
+
+ def fooLacksEnterAndExit():
+ foo = LacksEnterAndExit()
+ with foo: pass
+ self.assertRaisesRegex(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.assertRaisesRegex(AttributeError, '__exit__', fooLacksExit)
def assertRaisesSyntaxError(self, codestr):
def shouldRaiseSyntaxError(s):
@@ -140,11 +149,6 @@ class FailureTestCase(unittest.TestCase):
'with mock as (None):\n'
' pass')
- def testAssignmentToEmptyTupleError(self):
- self.assertRaisesSyntaxError(
- 'with mock as ():\n'
- ' pass')
-
def testAssignmentToTupleOnlyContainingNoneError(self):
self.assertRaisesSyntaxError('with mock as None,:\n pass')
self.assertRaisesSyntaxError(
@@ -454,7 +458,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm():
raise StopIteration("from with")
- with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+ with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow)
def testRaisedStopIteration2(self):
@@ -482,7 +486,7 @@ class ExceptionalTestCase(ContextmanagerAssertionMixin, unittest.TestCase):
with cm():
raise next(iter([]))
- with self.assertWarnsRegex(PendingDeprecationWarning, "StopIteration"):
+ with self.assertWarnsRegex(DeprecationWarning, "StopIteration"):
self.assertRaises(StopIteration, shouldThrow)
def testRaisedGeneratorExit1(self):