Example #1
0
def test_readlines_nobackup(tmpdir):
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    p.write(TEXT)
    with InPlace(str(p)) as fp:
        assert fp.readlines() == TEXT.splitlines(True)
    assert pylistdir(tmpdir) == ["file.txt"]
    assert p.read() == ""
Example #2
0
def test_writelines_backup(tmpdir):
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    p.write("")
    bkp = tmpdir.join("backup.txt")
    with InPlace(str(p), backup=str(bkp)) as fp:
        fp.writelines(TEXT.splitlines(True))
    assert pylistdir(tmpdir) == ["backup.txt", "file.txt"]
    assert bkp.read() == ""
    assert p.read() == TEXT