Visitar URL original
bpo-21987: fix TarFile.getmember getting a dir with a trailing slash by akulakov · Pull Request #30283 · python/cpython · GitHub
Skip to content
Merged
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
use context managers and os_helper.temp_cwd in the test
  • Loading branch information
akulakov committed Dec 28, 2021
commit 153667fd1e8817db0eac0b5884ba2fd16c9291b6
26 changes: 10 additions & 16 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,16 @@ def test_add_dir_getmember(self):
self.add_dir_and_getmember('a'*101)

def add_dir_and_getmember(self, name):
tar = tarfile.open(tmpname, 'w')
cwd = os.getcwd()
try:
os.chdir(TEMPDIR)
os.mkdir(name)
tar.add(name)
finally:
os.rmdir(name)
os.chdir(cwd)
tar.close()
tar = tarfile.open(tmpname)
try:
tar.getmember(name)
tar.getmember(name + '/')
finally:
tar.close()
with os_helper.temp_cwd():
with tarfile.open(tmpname, 'w') as tar:
try:
os.mkdir(name)
tar.add(name)
finally:
os.rmdir(name)
with tarfile.open(tmpname) as tar:
tar.getmember(name)
tar.getmember(name + '/')

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.

Maybe test that these two return the same info.


class GzipUstarReadTest(GzipTest, UstarReadTest):
pass
Expand Down