MCPcopy Create free account
hub / github.com/python/cpython / check_statlike_dir_fd

Method check_statlike_dir_fd

Lib/test/test_os/test_posix.py:1695–1724  ·  view source on GitHub ↗
(self, func, prefix)

Source from the content-addressed store, hash-verified

1693 posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)
1694
1695 def check_statlike_dir_fd(self, func, prefix):
1696 with self.prepare() as (dir_fd, name, fullname):
1697 with open(fullname, 'w') as outfile:
1698 outfile.write("testline\n")
1699 self.addCleanup(posix.unlink, fullname)
1700
1701 def get(result, attr):
1702 return getattr(result, prefix + attr)
1703
1704 s1 = func(fullname)
1705 s2 = func(name, dir_fd=dir_fd)
1706 self.assertEqual((get(s1, "dev"), get(s1, "ino")),
1707 (get(s2, "dev"), get(s2, "ino")))
1708 s2 = func(fullname, dir_fd=None)
1709 self.assertEqual((get(s1, "dev"), get(s1, "ino")),
1710 (get(s2, "dev"), get(s2, "ino")))
1711
1712 self.assertRaisesRegex(TypeError, 'should be integer or None, not',
1713 func, name, dir_fd=posix.getcwd())
1714 self.assertRaisesRegex(TypeError, 'should be integer or None, not',
1715 func, name, dir_fd=float(dir_fd))
1716 self.assertRaises(OverflowError,
1717 func, name, dir_fd=10**20)
1718
1719 for fd in False, True:
1720 with self.assertWarnsRegex(RuntimeWarning,
1721 'bool is used as a file descriptor') as cm:
1722 with self.assertRaises(OSError):
1723 func('nonexisting', dir_fd=fd)
1724 self.assertEqual(cm.filename, __file__)
1725
1726 @unittest.skipUnless(os.stat in os.supports_dir_fd, "test needs dir_fd support in os.stat()")
1727 def test_stat_dir_fd(self):

Callers 2

test_stat_dir_fdMethod · 0.95
test_statx_dir_fdMethod · 0.95

Calls 10

prepareMethod · 0.95
addCleanupMethod · 0.80
assertRaisesRegexMethod · 0.80
assertWarnsRegexMethod · 0.80
openFunction · 0.50
funcFunction · 0.50
getFunction · 0.50
writeMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected