我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用posixpath.samefile()。
def test_samefile(self): test_fn = support.TESTFN + "1" self._create_file(test_fn) self.assertTrue(posixpath.samefile(test_fn, test_fn)) self.assertRaises(TypeError, posixpath.samefile)
def test_samefile_on_links(self): test_fn1 = support.TESTFN + "1" test_fn2 = support.TESTFN + "2" self._create_file(test_fn1) os.symlink(test_fn1, test_fn2) self.assertTrue(posixpath.samefile(test_fn1, test_fn2)) os.remove(test_fn2) self._create_file(test_fn2) self.assertFalse(posixpath.samefile(test_fn1, test_fn2))
def test_samefile(self): f = open(test_support.TESTFN + "1", "wb") try: f.write("foo") f.close() self.assertIs( posixpath.samefile( test_support.TESTFN + "1", test_support.TESTFN + "1" ), True ) # If we don't have links, assume that os.stat doesn't return # reasonable inode information and thus, that samefile() doesn't # work. if hasattr(os, "symlink"): os.symlink( test_support.TESTFN + "1", test_support.TESTFN + "2" ) self.assertIs( posixpath.samefile( test_support.TESTFN + "1", test_support.TESTFN + "2" ), True ) os.remove(test_support.TESTFN + "2") f = open(test_support.TESTFN + "2", "wb") f.write("bar") f.close() self.assertIs( posixpath.samefile( test_support.TESTFN + "1", test_support.TESTFN + "2" ), False ) finally: if not f.close(): f.close()