def test_remove(self): f = Path(self.tpath, 'remove.f') d = Path(self.tpath, 'remove.d') n = Path(self.tpath, 'remove.n') f.open() d.mkdir() self.assertIsNone(f.remove()) self.assertFalse(f.exists) self.assertIsNone(d.remove()) self.assertFalse(d.exists) self.assertIsNone(n.remove()) self.assertFalse(n.exists)
def test_makepipe(self): mask = os.umask(0) try: n = Path(self.tpath, 'makepipe.n') # does not exist f = Path(self.tpath, 'makepipe.f') # existing file readonly = int('0666', 8) readwrite = int('0777', 8) f.open() self.assertRaises(TypeError, f.makepipe) self.assertIsNone(n.makepipe()) self.assertEqual(n.type, Path.TYPE.PIPE) self.assertEqual(n.mode, readonly) n.remove() self.assertIsNone(n.makepipe(readwrite)) self.assertEqual(n.type, Path.TYPE.PIPE) self.assertEqual(n.mode, readwrite) finally: os.umask(mask)
def test_makelink(self): n = Path(self.tpath, 'makelink.n') # does not exist l = Path(self.tpath, 'makelink.l') # existing link f = Path(self.tpath, 'makelink.f') # existing file d = Path(self.tpath, 'makelink.d') # existing directory ptr = 'foobar' pptr = Path(ptr) self.assertIsNone(n.makelink(ptr)) # passing str value self.assertTrue(n.islink) self.assertEqual(os.readlink(n.value), ptr) n.remove() self.assertIsNone(n.makelink(pptr)) # passing Path instance self.assertTrue(n.islink) self.assertEqual(os.readlink(n.value), ptr) f.open() d.mkdir() os.symlink('xyzzy', l.value) self.assertRaises(TypeError, f.makelink, ptr) self.assertRaises(TypeError, d.makelink, ptr) self.assertIsNone(l.makelink(ptr)) self.assertTrue(l.islink) self.assertEqual(os.readlink(l.value), ptr)