예제 #1
0
def test_rewrite_nonexisting_file(tmpdir: Path,
                                  monkeypatch: MonkeyPatch) -> None:
    monkeypatch.chdir(tmpdir)
    with rewrite("sample", "w") as f:
        f.write("csdf")
    with open("sample") as f:
        assert f.read() == "csdf"
예제 #2
0
def test_rewrite_fails(tmpdir, monkeypatch):
    monkeypatch.chdir(tmpdir)
    with open("sample", "w") as f:
        f.write("bsdf")
    with pytest.raises(Exception):
        with rewrite("sample") as f:
            f.write("csdf")
            raise Exception()
    assert open("sample").read() == "bsdf"
예제 #3
0
def test_rewrite(tmpdir, monkeypatch):
    monkeypatch.chdir(tmpdir)
    with open("sample", "w") as f:
        f.write("bsdf")
    with rewrite("sample") as f:
        f.write("csdf")
    assert open("sample").read() == "csdf"
    mode = os.stat("sample").st_mode
    assert oct(mode) == "0o100644"
예제 #4
0
def test_rewrite_fails(tmpdir: Path, monkeypatch: MonkeyPatch) -> None:
    monkeypatch.chdir(tmpdir)
    with open("sample", "w") as f:
        f.write("bsdf")
    with pytest.raises(Exception):
        with rewrite("sample") as f:  # type: ignore
            f.write("csdf")
            raise Exception()
    assert open("sample").read() == "bsdf"  # type: ignore
예제 #5
0
def test_rewrite(tmpdir: Path, monkeypatch: MonkeyPatch) -> None:
    monkeypatch.chdir(tmpdir)
    with open("sample", "w") as f:
        f.write("bsdf")
    with rewrite("sample") as f:  # type: ignore
        f.write("csdf")
    assert open("sample").read() == "csdf"
    mode = os.stat("sample").st_mode
    # chmod doesn't work on windows machines. Permissions are pinned at 666
    if not WINDOWS:
        assert oct(mode) == "0o100644"
예제 #6
0
def test_rewrite_nonexisting_file(tmpdir, monkeypatch):
    monkeypatch.chdir(tmpdir)
    with rewrite("sample") as f:
        f.write("csdf")
    assert open("sample").read() == "csdf"