mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
pycalver -> bumpver
This commit is contained in:
parent
2c01699b99
commit
bbf5bfa31c
35 changed files with 764 additions and 1235 deletions
134
test/test_cli.py
134
test/test_cli.py
|
|
@ -17,9 +17,9 @@ import pytest
|
|||
import pathlib2 as pl
|
||||
from click.testing import CliRunner
|
||||
|
||||
from pycalver2 import cli
|
||||
from pycalver2 import config
|
||||
from pycalver2 import v2patterns
|
||||
from bumpver import cli
|
||||
from bumpver import config
|
||||
from bumpver import v2patterns
|
||||
|
||||
# pylint:disable=redefined-outer-name ; pytest fixtures
|
||||
# pylint:disable=protected-access ; allowed for test code
|
||||
|
|
@ -51,11 +51,11 @@ requires = ["setuptools", "wheel"]
|
|||
"""
|
||||
|
||||
ENV = {
|
||||
'GIT_AUTHOR_NAME' : "calver_tester",
|
||||
'GIT_COMMITTER_NAME' : "calver_tester",
|
||||
'GIT_AUTHOR_EMAIL' : "calver_tester@nowhere.com",
|
||||
'GIT_COMMITTER_EMAIL': "calver_tester@nowhere.com",
|
||||
'HGUSER' : "calver_tester",
|
||||
'GIT_AUTHOR_NAME' : "bumpver_tester",
|
||||
'GIT_COMMITTER_NAME' : "bumpver_tester",
|
||||
'GIT_AUTHOR_EMAIL' : "bumpver_tester@nowhere.com",
|
||||
'GIT_COMMITTER_EMAIL': "bumpver_tester@nowhere.com",
|
||||
'HGUSER' : "bumpver_tester",
|
||||
'PATH' : os.environ['PATH'],
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ def runner(tmpdir):
|
|||
|
||||
_debug = 0
|
||||
if _debug:
|
||||
tmpdir = pl.Path("..") / "tmp_test_pycalver_project"
|
||||
tmpdir = pl.Path("..") / "tmp_test_bumpver_project"
|
||||
if tmpdir.exists():
|
||||
time.sleep(0.2)
|
||||
shutil.rmtree(str(tmpdir))
|
||||
|
|
@ -101,7 +101,7 @@ def test_help(runner):
|
|||
result = runner.invoke(cli.cli, ['--help', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
assert "CalVer" in result.output
|
||||
assert "bump " in result.output
|
||||
assert "update " in result.output
|
||||
assert "test " in result.output
|
||||
assert "init " in result.output
|
||||
assert "show " in result.output
|
||||
|
|
@ -110,8 +110,8 @@ def test_help(runner):
|
|||
def test_version(runner):
|
||||
result = runner.invoke(cli.cli, ['--version', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
assert " version v20" in result.output
|
||||
pattern = v2patterns.compile_pattern("vYYYY.BUILD[-TAG]")
|
||||
assert " version 20" in result.output
|
||||
pattern = v2patterns.compile_pattern("YYYY.BUILD[-TAG]")
|
||||
match = pattern.regexp.search(result.output)
|
||||
assert match
|
||||
|
||||
|
|
@ -186,25 +186,23 @@ def test_incr_semver_invalid(runner, caplog):
|
|||
|
||||
|
||||
def test_incr_to_beta(runner):
|
||||
pattern = "vYYYY.BUILD[-TAG]"
|
||||
old_version = "v2017.1999-alpha"
|
||||
initial_version = config._initial_version()
|
||||
pattern = "vYYYY.BUILD[-TAG]"
|
||||
old_version = "v2017.1999-alpha"
|
||||
new_version = dt.datetime.utcnow().strftime("v%Y.22000-beta")
|
||||
|
||||
result = runner.invoke(cli.cli, ['test', "-vv", old_version, pattern, "--tag", "beta"])
|
||||
assert result.exit_code == 0
|
||||
new_version = initial_version.replace(".1001-alpha", ".22000-beta")
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
|
||||
|
||||
def test_incr_to_final(runner, caplog):
|
||||
pattern = "vYYYY.BUILD[-TAG]"
|
||||
old_version = "v2017.1999-alpha"
|
||||
initial_version = config._initial_version()
|
||||
pattern = "vYYYY.BUILD[-TAG]"
|
||||
old_version = "v2017.1999-alpha"
|
||||
new_version = dt.datetime.utcnow().strftime("v%Y.22000")
|
||||
|
||||
result = runner.invoke(cli.cli, ['test', "-vv", old_version, pattern, "--tag", "final"])
|
||||
_debug_records(caplog)
|
||||
assert result.exit_code == 0
|
||||
new_version = initial_version.replace(".1001-alpha", ".22000")
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
|
||||
|
||||
|
|
@ -252,14 +250,14 @@ def _add_project_files(*files):
|
|||
with pl.Path("pycalver.toml").open(mode="wt", encoding="utf-8") as fobj:
|
||||
fobj.write(CALVER_TOML_FIXTURE)
|
||||
|
||||
if "calver.toml" in files:
|
||||
with pl.Path("calver.toml").open(mode="wt", encoding="utf-8") as fobj:
|
||||
fobj.write(CALVER_TOML_FIXTURE)
|
||||
|
||||
if "pyproject.toml" in files:
|
||||
with pl.Path("pyproject.toml").open(mode="wt", encoding="utf-8") as fobj:
|
||||
fobj.write(PYPROJECT_TOML_FIXTURE)
|
||||
|
||||
if "bumpver.toml" in files:
|
||||
with pl.Path("bumpver.toml").open(mode="wt", encoding="utf-8") as fobj:
|
||||
fobj.write(CALVER_TOML_FIXTURE)
|
||||
|
||||
|
||||
def _update_config_val(filename, **kwargs):
|
||||
with io.open(filename, mode="r", encoding="utf-8") as fobj:
|
||||
|
|
@ -281,7 +279,8 @@ def test_nocfg(runner, caplog):
|
|||
_add_project_files("README.md")
|
||||
result = runner.invoke(cli.cli, ['show', "-vv"])
|
||||
assert result.exit_code == 1
|
||||
expected_msg = "Could not parse configuration. Perhaps try 'calver init'."
|
||||
expected_msg = "Could not parse configuration. Perhaps try 'bumpver init'."
|
||||
_debug_records(caplog)
|
||||
assert any(expected_msg in r.message for r in caplog.records)
|
||||
|
||||
|
||||
|
|
@ -290,14 +289,14 @@ def test_novcs_nocfg_init(runner, caplog):
|
|||
# dry mode test
|
||||
result = runner.invoke(cli.cli, ['init', "-vv", "--dry"])
|
||||
assert result.exit_code == 0
|
||||
assert not os.path.exists("calver.toml")
|
||||
assert not os.path.exists("bumpver.toml")
|
||||
|
||||
# non dry mode
|
||||
result = runner.invoke(cli.cli, ['init', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
assert os.path.exists("calver.toml")
|
||||
with pl.Path("calver.toml").open(mode="r", encoding="utf-8") as fobj:
|
||||
assert os.path.exists("bumpver.toml")
|
||||
with pl.Path("bumpver.toml").open(mode="r", encoding="utf-8") as fobj:
|
||||
cfg_content = fobj.read()
|
||||
|
||||
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
|
||||
|
|
@ -305,6 +304,7 @@ def test_novcs_nocfg_init(runner, caplog):
|
|||
assert config.DEFAULT_TOML_README_MD_STR in cfg_content
|
||||
|
||||
result = runner.invoke(cli.cli, ['show', "-vv"])
|
||||
_debug_records(caplog)
|
||||
assert result.exit_code == 0
|
||||
assert f"Current Version: {config._initial_version()}\n" in result.output
|
||||
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
||||
|
|
@ -390,7 +390,7 @@ def test_git_init(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
|
@ -409,7 +409,7 @@ def test_hg_init(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
|
@ -430,7 +430,7 @@ def test_v1_git_tag_eval(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
|
@ -456,7 +456,7 @@ def test_hg_tag_eval(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
|
@ -480,7 +480,7 @@ def test_novcs_bump(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
|
@ -488,7 +488,7 @@ def test_novcs_bump(runner, version_pattern, cur_version, cur_pep440):
|
|||
with pl.Path("README.md").open(mode="r") as fobj:
|
||||
content = fobj.read()
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
calver = cur_version.split(".")[0]
|
||||
|
|
@ -498,7 +498,7 @@ def test_novcs_bump(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert calver + ".1002-alpha !\n" in content
|
||||
assert calver[1:] + ".1002a0 !]\n" in content
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "--tag", "beta"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "--tag", "beta"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
with pl.Path("README.md").open() as fobj:
|
||||
|
|
@ -516,15 +516,15 @@ def test_git_bump(runner, caplog, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
||||
shell("git", "add", "calver.toml")
|
||||
shell("git", "add", "bumpver.toml")
|
||||
shell("git", "commit", "-m", "initial commit")
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv"])
|
||||
_debug_records(caplog)
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
|
@ -544,15 +544,15 @@ def test_hg_bump(runner, version_pattern, cur_version, cur_pep440):
|
|||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val(
|
||||
"calver.toml",
|
||||
"bumpver.toml",
|
||||
version_pattern=version_pattern,
|
||||
current_version='"' + cur_version + '"',
|
||||
)
|
||||
|
||||
shell("hg", "add", "calver.toml")
|
||||
shell("hg", "add", "bumpver.toml")
|
||||
shell("hg", "commit", "-m", "initial commit")
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
calver = cur_version.split(".")[0]
|
||||
|
|
@ -573,12 +573,12 @@ def test_empty_git_bump(runner, caplog):
|
|||
with pl.Path("setup.cfg").open(mode="r") as fobj:
|
||||
default_cfg_data = fobj.read()
|
||||
|
||||
assert "[calver]\n" in default_cfg_data
|
||||
assert "[bumpver]\n" in default_cfg_data
|
||||
assert "\ncurrent_version = " in default_cfg_data
|
||||
assert "\n[calver:file_patterns]\n" in default_cfg_data
|
||||
assert "\n[bumpver:file_patterns]\n" in default_cfg_data
|
||||
assert "\nsetup.cfg =\n" in default_cfg_data
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump'])
|
||||
result = runner.invoke(cli.cli, ['update'])
|
||||
|
||||
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)
|
||||
|
|
@ -595,12 +595,12 @@ def test_empty_hg_bump(runner, caplog):
|
|||
with pl.Path("setup.cfg").open(mode="r") as fobj:
|
||||
default_cfg_text = fobj.read()
|
||||
|
||||
assert "[calver]\n" in default_cfg_text
|
||||
assert "[bumpver]\n" in default_cfg_text
|
||||
assert "\ncurrent_version = " in default_cfg_text
|
||||
assert "\n[calver:file_patterns]\n" in default_cfg_text
|
||||
assert "\n[bumpver:file_patterns]\n" in default_cfg_text
|
||||
assert "\nsetup.cfg =\n" in default_cfg_text
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump'])
|
||||
result = runner.invoke(cli.cli, ['update'])
|
||||
|
||||
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)
|
||||
|
|
@ -640,13 +640,13 @@ def test_v1_bump_semver_warning(runner, caplog, version_pattern):
|
|||
|
||||
_vcs_init("hg", files=["README.md", "setup.cfg"])
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "-n", "--dry"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "-n", "--dry"])
|
||||
assert result.exit_code == 1
|
||||
|
||||
assert any("version did not change" in r.message for r in caplog.records)
|
||||
assert any("[--major/--minor/--patch] required" in r.message for r in caplog.records)
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "-n", "--dry", "--patch"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "-n", "--dry", "--patch"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
|
||||
|
|
@ -664,7 +664,7 @@ def test_v1_bump_semver_diff(runner, caplog, version_pattern):
|
|||
cases = [("--major", "1.0.0"), ("--minor", "0.2.0"), ("--patch", "0.1.1")]
|
||||
|
||||
for flag, expected in cases:
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "-n", "--dry", flag])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "-n", "--dry", flag])
|
||||
assert result.exit_code == 0
|
||||
assert len(caplog.records) == 0
|
||||
|
||||
|
|
@ -769,13 +769,17 @@ def test_hg_commit_message(runner, caplog):
|
|||
commit_message = """
|
||||
"bump from {old_version} ({old_version_pep440}) to {new_version} ({new_version_pep440})"
|
||||
"""
|
||||
_update_config_val("setup.cfg", current_version='"v2019.1001-alpha"')
|
||||
_update_config_val("setup.cfg", commit_message=commit_message.strip())
|
||||
_update_config_val(
|
||||
"setup.cfg",
|
||||
current_version='"v2019.1001-alpha"',
|
||||
version_pattern="vYYYY.BUILD[-TAG]",
|
||||
commit_message=commit_message.strip(),
|
||||
)
|
||||
|
||||
_vcs_init("hg", ["README.md", "setup.cfg"])
|
||||
assert len(caplog.records) > 0
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "--pin-date", "--tag", "beta"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "--pin-date", "--tag", "beta"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
tags = shell("hg", "tags").decode("utf-8")
|
||||
|
|
@ -796,13 +800,17 @@ def test_git_commit_message(runner, caplog):
|
|||
commit_message = """
|
||||
"bump: {old_version} ({old_version_pep440}) -> {new_version} ({new_version_pep440})"
|
||||
"""
|
||||
_update_config_val("setup.cfg", current_version='"v2019.1001-alpha"')
|
||||
_update_config_val("setup.cfg", commit_message=commit_message.strip())
|
||||
_update_config_val(
|
||||
"setup.cfg",
|
||||
current_version='"v2019.1001-alpha"',
|
||||
version_pattern="vYYYY.BUILD[-TAG]",
|
||||
commit_message=commit_message.strip(),
|
||||
)
|
||||
|
||||
_vcs_init("git", ["README.md", "setup.cfg"])
|
||||
assert len(caplog.records) > 0
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "-vv", "--pin-date", "--tag", "beta"])
|
||||
result = runner.invoke(cli.cli, ['update', "-vv", "--pin-date", "--tag", "beta"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
tags = shell("git", "tag", "--list").decode("utf-8")
|
||||
|
|
@ -870,7 +878,7 @@ def test_multimatch_file_patterns(runner):
|
|||
with pl.Path("setup.cfg").open(mode="w", encoding="utf-8") as fobj:
|
||||
fobj.write(SETUP_CFG_MULTIMATCH_FILE_PATTERNS_FIXTURE)
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', '--tag', 'beta', '--date', "2020-11-22"])
|
||||
result = runner.invoke(cli.cli, ['update', '--tag', 'beta', '--date', "2020-11-22"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
with pl.Path("README.md").open(mode="r", encoding="utf-8") as fobj:
|
||||
|
|
@ -921,20 +929,20 @@ def test_get_latest_vcs_version_tag(runner):
|
|||
result = runner.invoke(cli.cli, ['init', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val("calver.toml", push="false")
|
||||
_update_config_val("calver.toml", current_version='"0.1.8"')
|
||||
_update_config_val("calver.toml", version_pattern='"MAJOR.MINOR.PATCH"')
|
||||
_update_config_val("bumpver.toml", push="false")
|
||||
_update_config_val("bumpver.toml", current_version='"0.1.8"')
|
||||
_update_config_val("bumpver.toml", version_pattern='"MAJOR.MINOR.PATCH"')
|
||||
|
||||
_vcs_init("git", files=["calver.toml"])
|
||||
_vcs_init("git", files=["bumpver.toml"])
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "--patch"])
|
||||
result = runner.invoke(cli.cli, ['update', "--patch"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
_, cfg = config.init()
|
||||
latest_version = cli.get_latest_vcs_version_tag(cfg, fetch=False)
|
||||
assert latest_version == "0.1.9"
|
||||
|
||||
result = runner.invoke(cli.cli, ['bump', "--patch"])
|
||||
result = runner.invoke(cli.cli, ['update', "--patch"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
_, cfg = config.init()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue