Esempio n. 1
0
def test_move_first_nonexistent_backup_ext(tmpdir):
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    fp = InPlace(str(p), backup_ext="~", move_first=True, delay_open=True)
    with pytest.raises(EnvironmentError):
        fp.open()
    assert pylistdir(tmpdir) == []
Esempio n. 2
0
def test_nonexistent(tmpdir):
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    fp = InPlace(str(p), delay_open=True)
    with pytest.raises(EnvironmentError):
        fp.open()
    assert pylistdir(tmpdir) == []
Esempio n. 3
0
def test_bad_mode_delay_open_open(tmpdir, move_first, backup):
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    p.write(TEXT)
    fp = InPlace(
        str(p),
        mode="q",
        delay_open=True,
        move_first=move_first,
        backup=tmpdir.join(backup) if backup is not None else None,
    )
    with pytest.raises(ValueError, match="invalid mode"):
        fp.open()
    assert fp.closed
    assert pylistdir(tmpdir) == ["file.txt"]
    assert p.read() == TEXT
Esempio n. 4
0
def test_move_first_backup_nosuchdir(tmpdir):
    """
    Assert that using a path to a file in a nonexistent directory as the backup
    path raises an error when opening
    """
    assert pylistdir(tmpdir) == []
    p = tmpdir.join("file.txt")
    p.write(TEXT)
    fp = InPlace(
        str(p),
        backup=str(tmpdir.join("nonexistent", "backup.txt")),
        move_first=True,
        delay_open=True,
    )
    with pytest.raises(EnvironmentError):
        fp.open()
    assert pylistdir(tmpdir) == ["file.txt"]
    assert p.read() == TEXT