mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
bugfixes for semver
This commit is contained in:
parent
a3499c19a6
commit
1c21e22720
3 changed files with 53 additions and 10 deletions
|
|
@ -175,7 +175,7 @@ def cli(verbose: int = 0) -> None:
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("old_version")
|
@click.argument("old_version")
|
||||||
@click.argument("pattern", default="vYYYY.BUILD[-TAG]")
|
@click.argument("pattern")
|
||||||
@click.option('-v' , '--verbose', count=True, help="Control log level. -vv for debug level.")
|
@click.option('-v' , '--verbose', count=True, help="Control log level. -vv for debug level.")
|
||||||
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
|
@click.option("--major", is_flag=True, default=False, help="Increment major component.")
|
||||||
@click.option("-m" , "--minor", is_flag=True, default=False, help="Increment minor component.")
|
@click.option("-m" , "--minor", is_flag=True, default=False, help="Increment minor component.")
|
||||||
|
|
@ -204,7 +204,7 @@ def cli(verbose: int = 0) -> None:
|
||||||
)
|
)
|
||||||
def test(
|
def test(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
pattern : str = "vYYYY.BUILD[-TAG]",
|
pattern : str,
|
||||||
verbose : int = 0,
|
verbose : int = 0,
|
||||||
tag : str = None,
|
tag : str = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
|
|
|
||||||
|
|
@ -617,6 +617,24 @@ def _incr_numeric(
|
||||||
tag : typ.Optional[str],
|
tag : typ.Optional[str],
|
||||||
tag_num : bool,
|
tag_num : bool,
|
||||||
) -> version.V2VersionInfo:
|
) -> version.V2VersionInfo:
|
||||||
|
"""Increment (and reset to zero) non CalVer parts.
|
||||||
|
|
||||||
|
>>> raw_pattern = 'MAJOR.MINOR.PATCH[PYTAGNUM]'
|
||||||
|
>>> old_vinfo = parse_field_values_to_vinfo({'major': "1", 'minor': "2", 'patch': "3"})
|
||||||
|
>>> cur_vinfo = old_vinfo
|
||||||
|
>>> new_vinfo = _incr_numeric(
|
||||||
|
... raw_pattern,
|
||||||
|
... cur_vinfo,
|
||||||
|
... old_vinfo,
|
||||||
|
... major=False,
|
||||||
|
... minor=False,
|
||||||
|
... patch=True,
|
||||||
|
... tag='beta',
|
||||||
|
... tag_num=False,
|
||||||
|
... )
|
||||||
|
>>> (new_vinfo.major, new_vinfo.minor, new_vinfo.patch, new_vinfo.tag, new_vinfo.pytag, new_vinfo.num)
|
||||||
|
(1, 2, 4, 'beta', 'b', 0)
|
||||||
|
"""
|
||||||
# Reset major/minor/patch/num/inc to zero if any part to the left of it is incremented
|
# Reset major/minor/patch/num/inc to zero if any part to the left of it is incremented
|
||||||
fields = _parse_pattern_fields(raw_pattern)
|
fields = _parse_pattern_fields(raw_pattern)
|
||||||
reset_fields = dict(_iter_reset_field_items(fields, old_vinfo, cur_vinfo))
|
reset_fields = dict(_iter_reset_field_items(fields, old_vinfo, cur_vinfo))
|
||||||
|
|
@ -653,6 +671,14 @@ def _incr_numeric(
|
||||||
if tag != cur_vinfo.tag:
|
if tag != cur_vinfo.tag:
|
||||||
cur_vinfo = cur_vinfo._replace(num=0)
|
cur_vinfo = cur_vinfo._replace(num=0)
|
||||||
cur_vinfo = cur_vinfo._replace(tag=tag)
|
cur_vinfo = cur_vinfo._replace(tag=tag)
|
||||||
|
|
||||||
|
if cur_vinfo.tag and not cur_vinfo.pytag:
|
||||||
|
pytag = version.PEP440_TAG_BY_TAG[cur_vinfo.tag]
|
||||||
|
cur_vinfo = cur_vinfo._replace(pytag=pytag)
|
||||||
|
elif cur_vinfo.pytag and not cur_vinfo.tag:
|
||||||
|
tag = version.TAG_BY_PEP440_TAG[cur_vinfo.pytag]
|
||||||
|
cur_vinfo = cur_vinfo._replace(tag=tag)
|
||||||
|
|
||||||
return cur_vinfo
|
return cur_vinfo
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,8 @@ def test_incr_default(runner):
|
||||||
|
|
||||||
def test_incr_pin_date(runner):
|
def test_incr_pin_date(runner):
|
||||||
old_version = "v2017.1999-alpha"
|
old_version = "v2017.1999-alpha"
|
||||||
result = runner.invoke(cli.cli, ['test', "-vv", "--pin-date", old_version])
|
pattern = "vYYYY.BUILD[-TAG]"
|
||||||
|
result = runner.invoke(cli.cli, ['test', "-vv", "--pin-date", old_version, pattern])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert "Version: v2017.22000-alpha\n" in result.output
|
assert "Version: v2017.22000-alpha\n" in result.output
|
||||||
|
|
||||||
|
|
@ -175,7 +176,8 @@ def test_incr_semver(runner):
|
||||||
|
|
||||||
|
|
||||||
def test_incr_semver_invalid(runner, caplog):
|
def test_incr_semver_invalid(runner, caplog):
|
||||||
result = runner.invoke(cli.cli, ['test', "-vv", "--patch", "0.1.1"])
|
pattern = "vYYYY.BUILD[-TAG]"
|
||||||
|
result = runner.invoke(cli.cli, ['test', "-vv", "0.1.1", pattern, "--patch"])
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
assert len(caplog.records) > 0
|
assert len(caplog.records) > 0
|
||||||
log_record = caplog.records[0]
|
log_record = caplog.records[0]
|
||||||
|
|
@ -184,41 +186,56 @@ def test_incr_semver_invalid(runner, caplog):
|
||||||
|
|
||||||
|
|
||||||
def test_incr_to_beta(runner):
|
def test_incr_to_beta(runner):
|
||||||
|
pattern = "vYYYY.BUILD[-TAG]"
|
||||||
old_version = "v2017.1999-alpha"
|
old_version = "v2017.1999-alpha"
|
||||||
initial_version = config._initial_version()
|
initial_version = config._initial_version()
|
||||||
|
|
||||||
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--tag", "beta"])
|
result = runner.invoke(cli.cli, ['test', "-vv", old_version, pattern, "--tag", "beta"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
new_version = initial_version.replace(".1001-alpha", ".22000-beta")
|
new_version = initial_version.replace(".1001-alpha", ".22000-beta")
|
||||||
assert f"Version: {new_version}\n" in result.output
|
assert f"Version: {new_version}\n" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_incr_to_final(runner, caplog):
|
def test_incr_to_final(runner, caplog):
|
||||||
|
pattern = "vYYYY.BUILD[-TAG]"
|
||||||
old_version = "v2017.1999-alpha"
|
old_version = "v2017.1999-alpha"
|
||||||
initial_version = config._initial_version()
|
initial_version = config._initial_version()
|
||||||
|
|
||||||
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--tag", "final"])
|
result = runner.invoke(cli.cli, ['test', "-vv", old_version, pattern, "--tag", "final"])
|
||||||
_debug_records(caplog)
|
_debug_records(caplog)
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
new_version = initial_version.replace(".1001-alpha", ".22000")
|
new_version = initial_version.replace(".1001-alpha", ".22000")
|
||||||
assert f"Version: {new_version}\n" in result.output
|
assert f"Version: {new_version}\n" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_incr_release_num(runner):
|
SEMVER = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
||||||
semver = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_incr_tag(runner):
|
||||||
|
old_version = "0.1.0"
|
||||||
|
new_version = "0.1.1b0"
|
||||||
|
|
||||||
|
result = runner.invoke(
|
||||||
|
cli.cli, ['test', "-vv", old_version, SEMVER, "--patch", "--tag", "beta"]
|
||||||
|
)
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert f"Version: {new_version}\n" in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_incr_tag_num(runner):
|
||||||
old_version = "0.1.0b0"
|
old_version = "0.1.0b0"
|
||||||
new_version = "0.1.0b1"
|
new_version = "0.1.0b1"
|
||||||
|
|
||||||
result = runner.invoke(cli.cli, ['test', "-vv", "--tag-num", old_version, semver])
|
result = runner.invoke(cli.cli, ['test', "-vv", old_version, SEMVER, "--tag-num"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert f"Version: {new_version}\n" in result.output
|
assert f"Version: {new_version}\n" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_incr_invalid(runner):
|
def test_incr_invalid(runner):
|
||||||
|
pattern = "vYYYY.BUILD[-TAG]"
|
||||||
old_version = "v2017.1999-alpha"
|
old_version = "v2017.1999-alpha"
|
||||||
|
|
||||||
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--tag", "alfa"])
|
result = runner.invoke(cli.cli, ['test', "-vv", old_version, pattern, "--tag", "alfa"])
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue