mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #26325: Added test.support.check_no_resource_warning() to check that
no ResourceWarning is emitted.
This commit is contained in:
parent
e93b06a0a3
commit
94a619d48b
5 changed files with 32 additions and 20 deletions
|
@ -567,14 +567,11 @@ class ElementTreeTest(unittest.TestCase):
|
|||
self.assertFalse(f.closed)
|
||||
self.assertEqual(str(cm.exception), "unknown event 'bogus'")
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.filterwarnings("always", category=ResourceWarning)
|
||||
with support.check_no_resource_warning(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
iterparse(SIMPLE_XMLFILE, events)
|
||||
self.assertEqual(str(cm.exception), "unknown event 'bogus'")
|
||||
del cm
|
||||
support.gc_collect()
|
||||
self.assertEqual(w, [])
|
||||
|
||||
source = io.BytesIO(
|
||||
b"<?xml version='1.0' encoding='iso-8859-1'?>\n"
|
||||
|
@ -601,15 +598,12 @@ class ElementTreeTest(unittest.TestCase):
|
|||
it = iterparse(TESTFN)
|
||||
action, elem = next(it)
|
||||
self.assertEqual((action, elem.tag), ('end', 'document'))
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.filterwarnings("always", category=ResourceWarning)
|
||||
with support.check_no_resource_warning(self):
|
||||
with self.assertRaises(ET.ParseError) as cm:
|
||||
next(it)
|
||||
self.assertEqual(str(cm.exception),
|
||||
'junk after document element: line 1, column 12')
|
||||
del cm, it
|
||||
support.gc_collect()
|
||||
self.assertEqual(w, [])
|
||||
|
||||
def test_writefile(self):
|
||||
elem = ET.Element("tag")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue