def test_copy(tmpdir): tmpdir = Path(tmpdir) test1 = tmpdir / 'test1' test2 = tmpdir / 'test2' test1.write_text('1') test2.write_text('2') with pytest.raises(OSError): fs.copy(test1, test2, False) assert test1.read_text() == '1' assert test2.read_text() == '2' fs.copy(test1, test2, True) assert test1.read_text() == '1' assert test2.read_text() == '1' dir1 = tmpdir / 'dir1' dir2 = tmpdir / 'dir2' dir1.mkdir() dir2.mkdir() fs.copy(test1, dir1 / 'test1') with pytest.raises(OSError): fs.copy(dir1, dir2, False) fs.copy(dir1, dir2) fs.exists(dir1 / 'test1') fs.exists(dir2 / 'test2') # copy same file, don't do anything fs.link(test1, test2) assert fs.samefile(test1, test2) assert fs.islink(test2) fs.copy(test2, test1) assert fs.samefile(test1, test2) assert fs.islink(test2)
def test_gzip(tmpdir): tmpdir = Path(tmpdir) test1 = tmpdir / 'test1.gz' test2 = tmpdir / 'test2' test3 = tmpdir / 'test3' test2.write_text('1') with pytest.raises(OSError): fs.gzip(test1, test2, False) fs.gzip(test2, test1) assert fs.exists(test1) fs.gunzip(test1, test3) assert fs.exists(test3) assert test3.read_text() == '1' dir1 = tmpdir / 'dir1' dir2 = tmpdir / 'dir2' tgz = tmpdir / 'dir1.tgz' fs.mkdir(dir1) test3 = dir1 / 'test' test3.write_text('2') fs.gzip(dir1, tgz) assert fs.exists(tgz) fs.gunzip(tgz, dir2) assert fs.isdir(dir2) assert fs.exists(dir2 / 'test') with pytest.raises(OSError): fs.gunzip(tgz, dir2, False)
def test_alias(tmpdir): assert fs.exists(tmpdir) assert fs.isdir(tmpdir) test1 = tmpdir / 'test1' test1.write_text('', encoding = 'utf-8') assert fs.isfile(test1) test2 = tmpdir / 'test2' if fs.exists(test2): test2.unlink() Path(test2).symlink_to(test1) assert fs.islink(test2)
def test_move(tmpdir): tmpdir = Path(tmpdir) test1 = tmpdir / 'test1' test2 = tmpdir / 'test2' test1.write_text('1') test2.write_text('2') with pytest.raises(OSError): fs.move(test1, test2, False) assert test2.read_text() == '2' assert fs.exists(test1) test1.write_text('1') fs.move(test1, test2, True) assert test2.read_text() == '1' assert not fs.exists(test1) # same file fs.link(test2, test1) fs.move(test1, test2) assert not fs.exists(test1) assert fs.isfile(test2)
def test_remove(tmpdir): test1 = Path(tmpdir / 'link') test2 = tmpdir / 'file' test2.write_text('', encoding = 'utf-8') test1.symlink_to(test2) test3 = tmpdir / 'dir' test3.mkdir() assert fs.exists(test3) fs.remove(test3) assert not fs.exists(test3) assert fs.exists(test1) assert fs.islink(test1) fs.remove(test1) assert not fs.exists(test1) assert not fs.islink(test1) assert fs.exists(test2) fs.remove(test2) assert not fs.exists(test2) with pytest.raises(OSError): fs.remove(tmpdir / 'notexists', False)