mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
parent
385521b596
commit
548fb871e0
4 changed files with 68 additions and 13 deletions
|
|
@ -190,11 +190,11 @@ def init(verbose: int = 0, dry: bool = False) -> None:
|
||||||
config.write_content(ctx)
|
config.write_content(ctx)
|
||||||
|
|
||||||
|
|
||||||
def _assert_not_dirty(vcs, filepaths: typ.Set[str], allow_dirty: bool):
|
def _assert_not_dirty(_vcs: vcs.VCS, filepaths: typ.Set[str], allow_dirty: bool):
|
||||||
dirty_files = vcs.status()
|
dirty_files = _vcs.status(required_files=filepaths)
|
||||||
|
|
||||||
if dirty_files:
|
if dirty_files:
|
||||||
log.warning(f"{vcs.name} working directory is not clean:")
|
log.warning(f"{_vcs.name} working directory is not clean. Uncomitted file(s):")
|
||||||
for dirty_file in dirty_files:
|
for dirty_file in dirty_files:
|
||||||
log.warning(" " + dirty_file)
|
log.warning(" " + dirty_file)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ VCS_SUBCOMMANDS_BY_NAME = {
|
||||||
'is_usable' : "hg root",
|
'is_usable' : "hg root",
|
||||||
'fetch' : "hg pull",
|
'fetch' : "hg pull",
|
||||||
'ls_tags' : "hg tags",
|
'ls_tags' : "hg tags",
|
||||||
'status' : "hg status -mard",
|
'status' : "hg status -umard",
|
||||||
'add_path' : "hg add {path}",
|
'add_path' : "hg add {path}",
|
||||||
'commit' : "hg commit --logfile {path}",
|
'commit' : "hg commit --logfile {path}",
|
||||||
'tag' : "hg tag {tag} --message {tag}",
|
'tag' : "hg tag {tag} --message {tag}",
|
||||||
|
|
@ -109,13 +109,15 @@ class VCS:
|
||||||
if self.has_remote:
|
if self.has_remote:
|
||||||
self('fetch')
|
self('fetch')
|
||||||
|
|
||||||
def status(self) -> typ.List[str]:
|
def status(self, required_files: typ.Set[str]) -> typ.List[str]:
|
||||||
"""Get status lines."""
|
"""Get status lines."""
|
||||||
status_output = self('status')
|
status_output = self('status')
|
||||||
|
status_items = [line.split(" ", 1) for line in status_output.splitlines()]
|
||||||
|
|
||||||
return [
|
return [
|
||||||
line[2:].strip()
|
filepath.strip()
|
||||||
for line in status_output.splitlines()
|
for status, filepath in status_items
|
||||||
if not line.strip().startswith("??")
|
if filepath.strip() in required_files or status != "??"
|
||||||
]
|
]
|
||||||
|
|
||||||
def ls_tags(self) -> typ.List[str]:
|
def ls_tags(self) -> typ.List[str]:
|
||||||
|
|
@ -142,7 +144,8 @@ class VCS:
|
||||||
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
|
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
|
||||||
assert " " not in tmp_file.name
|
assert " " not in tmp_file.name
|
||||||
|
|
||||||
fh : typ.IO[bytes]
|
fh: typ.IO[bytes]
|
||||||
|
|
||||||
with tmp_file as fh:
|
with tmp_file as fh:
|
||||||
fh.write(message_data)
|
fh.write(message_data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,7 @@ def test_novcs_pyproject_init(runner):
|
||||||
|
|
||||||
|
|
||||||
def _vcs_init(vcs):
|
def _vcs_init(vcs):
|
||||||
|
assert vcs in ("git", "hg")
|
||||||
assert not pl.Path(f".{vcs}").exists()
|
assert not pl.Path(f".{vcs}").exists()
|
||||||
sh(f"{vcs}", "init")
|
sh(f"{vcs}", "init")
|
||||||
assert pl.Path(f".{vcs}").is_dir()
|
assert pl.Path(f".{vcs}").is_dir()
|
||||||
|
|
@ -392,6 +393,9 @@ def test_git_bump(runner):
|
||||||
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
sh("git", "add", "pycalver.toml")
|
||||||
|
sh("git", "commit", "-m", "initial commit")
|
||||||
|
|
||||||
result = runner.invoke(pycalver.cli, ['bump', "--verbose"])
|
result = runner.invoke(pycalver.cli, ['bump', "--verbose"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
@ -409,6 +413,9 @@ def test_hg_bump(runner):
|
||||||
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
sh("hg", "add", "pycalver.toml")
|
||||||
|
sh("hg", "commit", "-m", "initial commit")
|
||||||
|
|
||||||
result = runner.invoke(pycalver.cli, ['bump', "--verbose"])
|
result = runner.invoke(pycalver.cli, ['bump', "--verbose"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
@ -417,3 +424,45 @@ def test_hg_bump(runner):
|
||||||
with pl.Path("README.md").open() as fh:
|
with pl.Path("README.md").open() as fh:
|
||||||
content = fh.read()
|
content = fh.read()
|
||||||
assert calver + ".0002-alpha !\n" in content
|
assert calver + ".0002-alpha !\n" in content
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_git_bump(runner, caplog):
|
||||||
|
sh("git", "init")
|
||||||
|
with pl.Path("setup.cfg").open(mode="w") as fh:
|
||||||
|
fh.write("")
|
||||||
|
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
with pl.Path("setup.cfg").open(mode="r") as fh:
|
||||||
|
default_cfg_data = fh.read()
|
||||||
|
|
||||||
|
assert "[pycalver]\n" in default_cfg_data
|
||||||
|
assert "\ncurrent_version = " in default_cfg_data
|
||||||
|
assert "\n[pycalver:file_patterns]\n" in default_cfg_data
|
||||||
|
assert "\nsetup.cfg =\n" in default_cfg_data
|
||||||
|
|
||||||
|
result = runner.invoke(pycalver.cli, ['bump'])
|
||||||
|
|
||||||
|
assert any(("working directory is not clean" in r.message) for r in caplog.records)
|
||||||
|
assert any(("setup.cfg" in r.message) for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_hg_bump(runner, caplog):
|
||||||
|
sh("hg", "init")
|
||||||
|
with pl.Path("setup.cfg").open(mode="w") as fh:
|
||||||
|
fh.write("")
|
||||||
|
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
with pl.Path("setup.cfg").open(mode="r") as fh:
|
||||||
|
default_cfg_data = fh.read()
|
||||||
|
|
||||||
|
assert "[pycalver]\n" in default_cfg_data
|
||||||
|
assert "\ncurrent_version = " in default_cfg_data
|
||||||
|
assert "\n[pycalver:file_patterns]\n" in default_cfg_data
|
||||||
|
assert "\nsetup.cfg =\n" in default_cfg_data
|
||||||
|
|
||||||
|
result = runner.invoke(pycalver.cli, ['bump'])
|
||||||
|
|
||||||
|
assert any(("working directory is not clean" in r.message) for r in caplog.records)
|
||||||
|
assert any(("setup.cfg" in r.message) for r in caplog.records)
|
||||||
|
|
|
||||||
11
test/util.py
11
test/util.py
|
|
@ -34,16 +34,19 @@ FIXTURE_PATH_PARTS = [
|
||||||
|
|
||||||
|
|
||||||
class Project:
|
class Project:
|
||||||
def __init__(self, project="a"):
|
def __init__(self, project=None):
|
||||||
if not project.startswith("project_"):
|
|
||||||
project = "project_" + project
|
|
||||||
|
|
||||||
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
|
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
|
||||||
self.tmpdir = tmpdir
|
self.tmpdir = tmpdir
|
||||||
|
|
||||||
self.dir = tmpdir / "pycalver_project"
|
self.dir = tmpdir / "pycalver_project"
|
||||||
self.dir.mkdir()
|
self.dir.mkdir()
|
||||||
|
|
||||||
|
if project is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not project.startswith("project_"):
|
||||||
|
project = "project_" + project
|
||||||
|
|
||||||
fixtures_subdir = FIXTURES_DIR / project
|
fixtures_subdir = FIXTURES_DIR / project
|
||||||
|
|
||||||
for path_parts in FIXTURE_PATH_PARTS:
|
for path_parts in FIXTURE_PATH_PARTS:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue