我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用posix.stat_result()。
def test_ismount_different_device(self): # Simulate the path being on a different device from its parent by # mocking out st_dev. save_lstat = os.lstat def fake_lstat(path): st_ino = 0 st_dev = 0 if path == ABSTFN: st_dev = 1 st_ino = 1 return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0)) try: os.lstat = fake_lstat self.assertIs(posixpath.ismount(ABSTFN), True) finally: os.lstat = save_lstat
def test_ismount_directory_not_readable(self): # issue #2466: Simulate ismount run on a directory that is not # readable, which used to return False. save_lstat = os.lstat def fake_lstat(path): st_ino = 0 st_dev = 0 if path.startswith(ABSTFN) and path != ABSTFN: # ismount tries to read something inside the ABSTFN directory; # simulate this being forbidden (no read permission). raise OSError("Fake [Errno 13] Permission denied") if path == ABSTFN: st_dev = 1 st_ino = 1 return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0)) try: os.lstat = fake_lstat self.assertIs(posixpath.ismount(ABSTFN), True) finally: os.lstat = save_lstat
def test_get_device_number(self, lstat): lstat.return_value = posix.stat_result([ 16877, 16, 51729, 3, 0, 0, 217, 0, 1458086872, 1458086872 ]) major, minor = replace_osd.get_device_number(1) assert major == 202 assert minor == 17
def test_statfile_exception(self): f = ntf(dir=self.tempdir) omode = os.stat(self.tempdir).st_mode os.chmod(self.tempdir, 0) if 0 != os.getuid(): with self.assertRaises(Exception) as ecm: statfile(f.name) e = ecm.exception self.assertIn(e.errno, (errno.EPERM, errno.EACCES)) os.chmod(self.tempdir, omode) stbuf = statfile(f.name) self.assertIsInstance(stbuf, posix.stat_result)