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

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Perform open check against temp tar file
  • Loading branch information
0x29a committed Jun 5, 2019
commit cb854029eb35cee9676f48240594726c976ad0d2
8 changes: 5 additions & 3 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,12 +1421,14 @@ def test_file_mode(self):
finally:
os.umask(original_umask)

class GzipStreamWriteTest(GzipTest, StreamWriteTest):
def test_open_by_path_object(self):
# Test for issue #37144: open gzip for stream write by path-like object
tar = tarfile.open(pathlib.Path(self.tarname), self.mode)
# Test for issue #37144: broken open for stream write by path-like object
tar = tarfile.open(pathlib.Path(tmpname), self.mode)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a context manager that automatically calls close on the object.

with tarfile.open(pathlib.Path(tmpname), self.mode) as f:
	pass

tar.close()

class GzipStreamWriteTest(GzipTest, StreamWriteTest):
pass

class Bz2StreamWriteTest(Bz2Test, StreamWriteTest):
decompressor = bz2.BZ2Decompressor if bz2 else None

Expand Down