def test_ensure_toml_stability(monkeypatch, tmpdir): pyproject_file = tmpdir.join("pyproject.toml") pyproject_file.write( textwrap.dedent( """ [tool.copyist] [tool.copyist.files] "pyproject.toml" = ["fake_sync_module.ensure_black_section"] """ ).strip() ) monkeypatch.chdir(tmpdir) sync.sync_files( {"pyproject.toml": ["fake_sync_module.ensure_black_section"]}, context={}, ) with open("pyproject.toml") as f: first_version = f.read() sync.sync_files( {"pyproject.toml": ["fake_sync_module.ensure_black_section"]}, context={}, ) with open("pyproject.toml") as f: second_version = f.read() assert first_version == second_version
def test_with_context(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) sync.sync_files( {"test": ["fake_sync_module.ensure_with_context"]}, context={"prefix": "foobar"}, ) with open("test") as f: assert f.read() == "foobar"
def test_combined(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) with open("test", "w") as f: f.write("xxx") sync.sync_files( { "test": [ "fake_sync_module.ensure_toto", "fake_sync_module.ensure_odd_number_of_o", ] }, context={}, ) with open("test") as f: assert f.read() == "totoo"
def test_new_file(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) changed_files = sync.sync_files( {"test": ["fake_sync_module.ensure_toto"]}, context={}, ) with open("test") as f: assert f.read() == "toto" assert changed_files == {"test"}
def test_uptodate_file(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) with open("test", "w") as f: f.write("toto") changed_files = sync.sync_files( {"test": ["fake_sync_module.ensure_toto"]}, context={}, ) assert not changed_files
def test_update_file(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) with open("test", "w") as f: f.write("oo") changed_files = sync.sync_files( {"test": ["fake_sync_module.ensure_odd_number_of_o"]}, context={}, ) with open("test") as f: assert f.read() == "ooo" assert changed_files == {"test"}
def test_multiple_files(monkeypatch, tmpdir): monkeypatch.chdir(tmpdir) with open("test", "w") as f: f.write("toto") changed_files = sync.sync_files( { "test": ["fake_sync_module.ensure_toto"], "test2": ["fake_sync_module.ensure_toto"], }, context={}, ) assert changed_files == {"test2"}
def test_ensure_toml(monkeypatch, tmpdir): pyproject_file = tmpdir.join("pyproject.toml") pyproject_file.write( textwrap.dedent( """ [tool.copyist] [tool.copyist.files] "pyproject.toml" = ["fake_sync_module.ensure_black_section"] """ ).strip() ) monkeypatch.chdir(tmpdir) sync.sync_files( {"pyproject.toml": ["fake_sync_module.ensure_black_section"]}, context={}, ) with open("pyproject.toml") as f: data = tomlkit.parse(f.read()) assert data["tool"]["black"]["line-length"] == 88 # copyist configuration is still here assert data["tool"]["copyist"]