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"
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"
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"
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
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"
def test_rewrite_nonexisting_file(tmpdir, monkeypatch): monkeypatch.chdir(tmpdir) with rewrite("sample") as f: f.write("csdf") assert open("sample").read() == "csdf"