[Python-checkins] bpo-33761: Fix a file leak in test_iterparse in test_xml_etree. (GH-7358)

Miss Islington (bot) webhook-mailer at python.org
Mon Jun 4 13:22:21 EDT 2018


https://github.com/python/cpython/commit/a7de1483c28eb818135a8c9a2e414e3a1d0fe648
commit: a7de1483c28eb818135a8c9a2e414e3a1d0fe648
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018年06月04日T10:22:18-07:00
summary:
bpo-33761: Fix a file leak in test_iterparse in test_xml_etree. (GH-7358)
(cherry picked from commit 13f51d9eec569e08475390e2a8f49f4afed1ea06)
Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
files:
M Lib/test/test_xml_etree.py
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index f8af69fa110d..c14f8397ae7d 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -606,6 +606,7 @@ def test_iterparse(self):
 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)
@@ -2794,9 +2795,6 @@ def test_setslice_negative_steps(self):
 
 
 class IOTest(unittest.TestCase):
- def tearDown(self):
- support.unlink(TESTFN)
-
 def test_encoding(self):
 # Test encoding issues.
 elem = ET.Element("tag")
@@ -2867,12 +2865,14 @@ def test_encoding(self):
 "<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')
@@ -2881,6 +2881,7 @@ def test_write_to_text_file(self):
 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)
@@ -2889,6 +2890,7 @@ def test_write_to_binary_file(self):
 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:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /