Skip to content

Commit c2622a0

Browse files
authored
pythonGH-89812: Improve test for pathlib.Path.stat() (pythonGH-106064)
Make assertions about the `st_mode`, `st_ino` and `st_dev` attributes of the stat results from two files and a directory, rather than checking if `chmod()` affects `st_mode` (which is already tested elsewhere).
1 parent cbc33e4 commit c2622a0

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Lib/test/test_pathlib.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,15 +2145,25 @@ def test_resolve_dot(self):
21452145
# Non-strict
21462146
self.assertEqual(r.resolve(strict=False), p / '3' / '4')
21472147

2148-
@os_helper.skip_unless_working_chmod
21492148
def test_stat(self):
2150-
p = self.cls(BASE) / 'fileA'
2151-
st = p.stat()
2152-
self.assertEqual(p.stat(), st)
2153-
# Change file mode by flipping write bit.
2154-
p.chmod(st.st_mode ^ 0o222)
2155-
self.addCleanup(p.chmod, st.st_mode)
2156-
self.assertNotEqual(p.stat(), st)
2149+
statA = self.cls(BASE).joinpath('fileA').stat()
2150+
statB = self.cls(BASE).joinpath('dirB', 'fileB').stat()
2151+
statC = self.cls(BASE).joinpath('dirC').stat()
2152+
# st_mode: files are the same, directory differs.
2153+
self.assertIsInstance(statA.st_mode, int)
2154+
self.assertEqual(statA.st_mode, statB.st_mode)
2155+
self.assertNotEqual(statA.st_mode, statC.st_mode)
2156+
self.assertNotEqual(statB.st_mode, statC.st_mode)
2157+
# st_ino: all different,
2158+
self.assertIsInstance(statA.st_ino, int)
2159+
self.assertNotEqual(statA.st_ino, statB.st_ino)
2160+
self.assertNotEqual(statA.st_ino, statC.st_ino)
2161+
self.assertNotEqual(statB.st_ino, statC.st_ino)
2162+
# st_dev: all the same.
2163+
self.assertIsInstance(statA.st_dev, int)
2164+
self.assertEqual(statA.st_dev, statB.st_dev)
2165+
self.assertEqual(statA.st_dev, statC.st_dev)
2166+
# other attributes not used by pathlib.
21572167

21582168
def test_stat_no_follow_symlinks(self):
21592169
if not self.can_symlink:

0 commit comments

Comments
 (0)