Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2cca057

Browse files
author
Victor Stinner
committed
test_codecs now removes the temporay file (created by the test)
1 parent 3c8d12d commit 2cca057

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Lib/test/test_codecs.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,11 @@ def test_bug691291(self):
515515
s1 = 'Hello\r\nworld\r\n'
516516

517517
s = s1.encode(self.encoding)
518-
try:
519-
with open(support.TESTFN, 'wb') as fp:
520-
fp.write(s)
521-
with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
522-
self.assertEqual(reader.read(), s1)
523-
finally:
524-
support.unlink(support.TESTFN)
518+
self.addCleanup(support.unlink, support.TESTFN)
519+
with open(support.TESTFN, 'wb') as fp:
520+
fp.write(s)
521+
with codecs.open(support.TESTFN, 'U', encoding=self.encoding) as reader:
522+
self.assertEqual(reader.read(), s1)
525523

526524
class UTF16LETest(ReadTest):
527525
encoding = "utf-16-le"
@@ -1628,6 +1626,7 @@ def test_seek0(self):
16281626
"utf-32",
16291627
"utf-32-le",
16301628
"utf-32-be")
1629+
self.addCleanup(support.unlink, support.TESTFN)
16311630
for encoding in tests:
16321631
# Check if the BOM is written only once
16331632
with codecs.open(support.TESTFN, 'w+', encoding=encoding) as f:

0 commit comments

Comments
 (0)