bpo-33761: Fix a file leak in test_iterparse in test_xml_etree. (GH-7358)
(cherry picked from commit 13f51d9eec
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
bdab3ea8b9
commit
2332fedb8d
|
@ -617,6 +617,7 @@ class ElementTreeTest(unittest.TestCase):
|
|||
self.assertEqual(str(cm.exception),
|
||||
'junk after document element: line 1, column 12')
|
||||
|
||||
self.addCleanup(support.unlink, TESTFN)
|
||||
with open(TESTFN, "wb") as f:
|
||||
f.write(b"<document />junk")
|
||||
it = iterparse(TESTFN)
|
||||
|
@ -2849,9 +2850,6 @@ class ElementSlicingTest(unittest.TestCase):
|
|||
|
||||
|
||||
class IOTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
support.unlink(TESTFN)
|
||||
|
||||
def test_encoding(self):
|
||||
# Test encoding issues.
|
||||
elem = ET.Element("tag")
|
||||
|
@ -2922,12 +2920,14 @@ class IOTest(unittest.TestCase):
|
|||
"<tag key=\"åöö<>\" />" % enc).encode(enc))
|
||||
|
||||
def test_write_to_filename(self):
|
||||
self.addCleanup(support.unlink, TESTFN)
|
||||
tree = ET.ElementTree(ET.XML('''<site />'''))
|
||||
tree.write(TESTFN)
|
||||
with open(TESTFN, 'rb') as f:
|
||||
self.assertEqual(f.read(), b'''<site />''')
|
||||
|
||||
def test_write_to_text_file(self):
|
||||
self.addCleanup(support.unlink, TESTFN)
|
||||
tree = ET.ElementTree(ET.XML('''<site />'''))
|
||||
with open(TESTFN, 'w', encoding='utf-8') as f:
|
||||
tree.write(f, encoding='unicode')
|
||||
|
@ -2936,6 +2936,7 @@ class IOTest(unittest.TestCase):
|
|||
self.assertEqual(f.read(), b'''<site />''')
|
||||
|
||||
def test_write_to_binary_file(self):
|
||||
self.addCleanup(support.unlink, TESTFN)
|
||||
tree = ET.ElementTree(ET.XML('''<site />'''))
|
||||
with open(TESTFN, 'wb') as f:
|
||||
tree.write(f)
|
||||
|
@ -2944,6 +2945,7 @@ class IOTest(unittest.TestCase):
|
|||
self.assertEqual(f.read(), b'''<site />''')
|
||||
|
||||
def test_write_to_binary_file_with_bom(self):
|
||||
self.addCleanup(support.unlink, TESTFN)
|
||||
tree = ET.ElementTree(ET.XML('''<site />'''))
|
||||
# test BOM writing to buffered file
|
||||
with open(TESTFN, 'wb') as f:
|
||||
|
|
Loading…
Reference in New Issue