Skip to content

Commit

Permalink
bpo-26067: Do not fail test_shutil / chown when gid/uid cannot be res…
Browse files Browse the repository at this point in the history
…olved (#19032)

* bpo-26067: Do not fail test_shutil.chown when gid/uid cannot be resolved

There is no guarantee that the users primary uid or gid can be resolved
in the unix group/account databases. Skip the last part of the chown
test if we cannot resolve the gid or uid to a name.

* 📜🤖 Added by blurb_it.

* Address review feedback

* address review feedback correctly

* fix typo

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
  • Loading branch information
MatzeB and blurb-it[bot] committed Mar 17, 2020
1 parent 982307b commit 5226894
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Lib/test/test_shutil.py
Expand Up @@ -1666,12 +1666,17 @@ def check_chown(path, uid=None, gid=None):
shutil.chown(dirname, group=gid)
check_chown(dirname, gid=gid)

user = pwd.getpwuid(uid)[0]
group = grp.getgrgid(gid)[0]
shutil.chown(filename, user, group)
check_chown(filename, uid, gid)
shutil.chown(dirname, user, group)
check_chown(dirname, uid, gid)
try:
user = pwd.getpwuid(uid)[0]
group = grp.getgrgid(gid)[0]
except KeyError:
# On some systems uid/gid cannot be resolved.
pass
else:
shutil.chown(filename, user, group)
check_chown(filename, uid, gid)
shutil.chown(dirname, user, group)
check_chown(dirname, uid, gid)


class TestWhich(BaseTest, unittest.TestCase):
Expand Down
@@ -0,0 +1 @@
Do not fail test_shutil test_chown test when uid or gid of user cannot be resolved to a name.

0 comments on commit 5226894

Please sign in to comment.