finally:
fp.close()
+ @unittest.skipUnless(hasattr(posix, 'stat'),
+ 'test needs posix.stat()')
+ @unittest.skipUnless(os.stat in os.supports_follow_symlinks,
+ 'test needs follow_symlinks support in os.stat()')
+ def test_stat_fd_zero_follow_symlinks(self):
+ with self.assertRaisesRegex(ValueError,
+ 'cannot use fd and follow_symlinks together'):
+ posix.stat(0, follow_symlinks=False)
+ with self.assertRaisesRegex(ValueError,
+ 'cannot use fd and follow_symlinks together'):
+ posix.stat(1, follow_symlinks=False)
+
def test_stat(self):
self.assertTrue(posix.stat(os_helper.TESTFN))
self.assertTrue(posix.stat(os.fsencode(os_helper.TESTFN)))
fd_and_follow_symlinks_invalid(const char *function_name, int fd,
int follow_symlinks)
{
- if ((fd > 0) && (!follow_symlinks)) {
+ if ((fd >= 0) && (!follow_symlinks)) {
PyErr_Format(PyExc_ValueError,
"%s: cannot use fd and follow_symlinks together",
function_name);