diff options
| author | Barney Gale <barney.gale@gmail.com> | 2023-07-01 12:33:29 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-01 12:33:29 (GMT) |
| commit | c2622a0d82078a7ab17597707b4dd42446a043ae (patch) | |
| tree | 6aa2d91be21a7a54ade2e16a9e6d3a12a88181c2 /Lib/test/test_pathlib.py | |
| parent | cbc33e4aede10f4d5799d9f7aa9ec5b91414f65b (diff) | |
| download | cpython-c2622a0d82078a7ab17597707b4dd42446a043ae.zip cpython-c2622a0d82078a7ab17597707b4dd42446a043ae.tar.gz cpython-c2622a0d82078a7ab17597707b4dd42446a043ae.tar.bz2 | |
GH-89812: Improve test for `pathlib.Path.stat()` (GH-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).
Diffstat (limited to 'Lib/test/test_pathlib.py')
| -rw-r--r-- | Lib/test/test_pathlib.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 5be5a77..464a835 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2145,15 +2145,25 @@ class PathTest(unittest.TestCase): # Non-strict self.assertEqual(r.resolve(strict=False), p / '3' / '4') - @os_helper.skip_unless_working_chmod def test_stat(self): - p = self.cls(BASE) / 'fileA' - st = p.stat() - self.assertEqual(p.stat(), st) - # Change file mode by flipping write bit. - p.chmod(st.st_mode ^ 0o222) - self.addCleanup(p.chmod, st.st_mode) - self.assertNotEqual(p.stat(), st) + statA = self.cls(BASE).joinpath('fileA').stat() + statB = self.cls(BASE).joinpath('dirB', 'fileB').stat() + statC = self.cls(BASE).joinpath('dirC').stat() + # st_mode: files are the same, directory differs. + self.assertIsInstance(statA.st_mode, int) + self.assertEqual(statA.st_mode, statB.st_mode) + self.assertNotEqual(statA.st_mode, statC.st_mode) + self.assertNotEqual(statB.st_mode, statC.st_mode) + # st_ino: all different, + self.assertIsInstance(statA.st_ino, int) + self.assertNotEqual(statA.st_ino, statB.st_ino) + self.assertNotEqual(statA.st_ino, statC.st_ino) + self.assertNotEqual(statB.st_ino, statC.st_ino) + # st_dev: all the same. + self.assertIsInstance(statA.st_dev, int) + self.assertEqual(statA.st_dev, statB.st_dev) + self.assertEqual(statA.st_dev, statC.st_dev) + # other attributes not used by pathlib. def test_stat_no_follow_symlinks(self): if not self.can_symlink: |
