add regression test for #12

This commit is contained in:
Manuel Barkhau 2020-10-05 18:20:16 +00:00
parent 54a5892957
commit 768b34ffb8
2 changed files with 39 additions and 7 deletions

View file

@ -499,7 +499,7 @@ def init(verbose: int = 0, dry: bool = False) -> None:
config.write_content(ctx) config.write_content(ctx)
def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config: def get_latest_vcs_version_tag(cfg: config.Config, fetch: bool) -> typ.Optional[str]:
all_tags = vcs.get_tags(fetch=fetch) all_tags = vcs.get_tags(fetch=fetch)
if cfg.is_new_pattern: if cfg.is_new_pattern:
@ -507,17 +507,24 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
else: else:
version_tags = [tag for tag in all_tags if v1version.is_valid(tag, cfg.version_pattern)] version_tags = [tag for tag in all_tags if v1version.is_valid(tag, cfg.version_pattern)]
if not version_tags: if version_tags:
version_tags.sort(key=pkg_resources.parse_version, reverse=True)
_debug_tags = ", ".join(version_tags[:3])
logger.debug(f"found tags: {_debug_tags} ... ({len(version_tags)} in total)")
return version_tags[0]
else:
return None
def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
latest_version_tag = get_latest_vcs_version_tag(cfg, fetch)
if latest_version_tag is None:
logger.debug("no vcs tags found") logger.debug("no vcs tags found")
return cfg return cfg
else: else:
version_tags.sort(key=pkg_resources.parse_version, reverse=True)
_debug_tags = ", ".join(version_tags[:3])
logger.debug(f"found tags: {_debug_tags} ... ({len(version_tags)} in total)")
latest_version_tag = version_tags[0]
latest_version_pep440 = version.to_pep440(latest_version_tag) latest_version_pep440 = version.to_pep440(latest_version_tag)
if latest_version_tag <= cfg.current_version: if latest_version_tag <= cfg.current_version:
# current_version already newer/up-to-date
return cfg return cfg
else: else:
logger.info(f"Working dir version : {cfg.current_version}") logger.info(f"Working dir version : {cfg.current_version}")

View file

@ -829,3 +829,28 @@ def test_rollover(version_pattern, old_version, expected, kwargs):
assert expected is None assert expected is None
else: else:
assert new_version == expected assert new_version == expected
def test_get_latest_vcs_version_tag(runner):
result = runner.invoke(main.cli, ['init', "-vv"])
assert result.exit_code == 0
_update_config_val("pycalver.toml", push="false")
_update_config_val("pycalver.toml", current_version='"0.1.8"')
_update_config_val("pycalver.toml", version_pattern='"MAJOR.MINOR.PATCH"')
_vcs_init("git", files=["pycalver.toml"])
result = runner.invoke(main.cli, ['bump', "--patch"])
assert result.exit_code == 0
_, cfg = config.init()
latest_version = main.get_latest_vcs_version_tag(cfg, fetch=False)
assert latest_version == "0.1.9"
result = runner.invoke(main.cli, ['bump', "--patch"])
assert result.exit_code == 0
_, cfg = config.init()
latest_version = main.get_latest_vcs_version_tag(cfg, fetch=False)
assert latest_version == "0.1.10"