gh-108638: Fix stat.filemode() when _stat is missing (#108639)

Change the pure Python implementation of stat.filemode() for unknown
file type: use "?", as done by the _stat.filemode().

test_stat skips TestFilemodeCStat if the _stat extension is missing.
This commit is contained in:
Victor Stinner 2023-08-29 17:46:46 +02:00 committed by GitHub
parent 7659128b9d
commit b62a76043e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -122,8 +122,11 @@ class TestFilemode:
st_mode, modestr = self.get_mode()
self.assertEqual(modestr, '-rwx------')
self.assertS_IS("REG", st_mode)
self.assertEqual(self.statmod.S_IMODE(st_mode),
imode = self.statmod.S_IMODE(st_mode)
self.assertEqual(imode,
self.statmod.S_IRWXU)
self.assertEqual(self.statmod.filemode(imode),
'?rwx------')
os.chmod(TESTFN, 0o070)
st_mode, modestr = self.get_mode()
@ -238,6 +241,7 @@ class TestFilemode:
self.assertEqual(value, modvalue, key)
@unittest.skipIf(c_stat is None, 'need _stat extension')
class TestFilemodeCStat(TestFilemode, unittest.TestCase):
statmod = c_stat