mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 06:20:08 +01:00
much bugfixing
This commit is contained in:
parent
56c9f9b36c
commit
49e19fbf89
18 changed files with 687 additions and 451 deletions
118
test/test_cli.py
118
test/test_cli.py
|
|
@ -4,7 +4,9 @@ from __future__ import print_function
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import shutil
|
||||
import subprocess as sp
|
||||
|
|
@ -13,6 +15,8 @@ import pytest
|
|||
import pathlib2 as pl
|
||||
from click.testing import CliRunner
|
||||
|
||||
from pycalver import v1cli
|
||||
from pycalver import v2cli
|
||||
from pycalver import config
|
||||
from pycalver import v1patterns
|
||||
from pycalver.__main__ import cli
|
||||
|
|
@ -21,6 +25,12 @@ from pycalver.__main__ import cli
|
|||
# pylint:disable=protected-access ; allowed for test code
|
||||
|
||||
|
||||
README_TEXT_FIXTURE = """
|
||||
Hello World v201701.1002-alpha !
|
||||
aka. 201701.1002a0 !
|
||||
"""
|
||||
|
||||
|
||||
SETUP_CFG_FIXTURE = """
|
||||
[metadata]
|
||||
license_file = LICENSE
|
||||
|
|
@ -110,31 +120,33 @@ def test_incr_pin_date(runner):
|
|||
|
||||
|
||||
def test_incr_semver(runner):
|
||||
semver_pattern = "{MAJOR}.{MINOR}.{PATCH}"
|
||||
old_version = "0.1.0"
|
||||
new_version = "0.1.1"
|
||||
semver_patterns = [
|
||||
"{semver}",
|
||||
"{MAJOR}.{MINOR}.{PATCH}",
|
||||
"MAJOR.MINOR.PATCH",
|
||||
]
|
||||
|
||||
result = runner.invoke(cli, ['test', "-vv", "--patch", old_version, "{semver}"])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
for semver_pattern in semver_patterns:
|
||||
old_version = "0.1.0"
|
||||
new_version = "0.1.1"
|
||||
|
||||
result = runner.invoke(cli, ['test', "-vv", "--patch", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
result = runner.invoke(cli, ['test', "-vv", "--patch", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
|
||||
old_version = "0.1.1"
|
||||
new_version = "0.2.0"
|
||||
old_version = "0.1.1"
|
||||
new_version = "0.2.0"
|
||||
|
||||
result = runner.invoke(cli, ['test', "-vv", "--minor", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
result = runner.invoke(cli, ['test', "-vv", "--minor", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
|
||||
old_version = "0.1.1"
|
||||
new_version = "1.0.0"
|
||||
old_version = "0.1.1"
|
||||
new_version = "1.0.0"
|
||||
|
||||
result = runner.invoke(cli, ['test', "-vv", "--major", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
result = runner.invoke(cli, ['test', "-vv", "--major", old_version, semver_pattern])
|
||||
assert result.exit_code == 0
|
||||
assert f"Version: {new_version}\n" in result.output
|
||||
|
||||
|
||||
def test_incr_semver_invalid(runner, caplog):
|
||||
|
|
@ -175,12 +187,8 @@ def test_incr_invalid(runner):
|
|||
|
||||
def _add_project_files(*files):
|
||||
if "README.md" in files:
|
||||
README_TEXT = """
|
||||
Hello World v201701.1002-alpha !
|
||||
aka. 201701.1002a0 !
|
||||
"""
|
||||
with pl.Path("README.md").open(mode="wt", encoding="utf-8") as fobj:
|
||||
fobj.write(README_TEXT)
|
||||
fobj.write(README_TEXT_FIXTURE)
|
||||
|
||||
if "setup.cfg" in files:
|
||||
with pl.Path("setup.cfg").open(mode="wt", encoding="utf-8") as fobj:
|
||||
|
|
@ -195,6 +203,22 @@ def _add_project_files(*files):
|
|||
fobj.write(PYPROJECT_TOML_FIXTURE)
|
||||
|
||||
|
||||
def _update_config_val(filename, **kwargs):
|
||||
with io.open(filename, mode="r", encoding="utf-8") as fobj:
|
||||
old_cfg_text = fobj.read()
|
||||
|
||||
new_cfg_text = old_cfg_text
|
||||
for key, val in kwargs.items():
|
||||
replacement = "{} = {}\n".format(key, val)
|
||||
if replacement not in new_cfg_text:
|
||||
pattern = r"^{} = .*$".format(key)
|
||||
new_cfg_text = re.sub(pattern, replacement, new_cfg_text, flags=re.MULTILINE)
|
||||
assert old_cfg_text != new_cfg_text
|
||||
|
||||
with io.open(filename, mode="w", encoding="utf-8") as fobj:
|
||||
fobj.write(new_cfg_text)
|
||||
|
||||
|
||||
def test_nocfg(runner, caplog):
|
||||
_add_project_files("README.md")
|
||||
result = runner.invoke(cli, ['show', "-vv"])
|
||||
|
|
@ -491,7 +515,7 @@ setup.cfg =
|
|||
"""
|
||||
|
||||
|
||||
def test_bump_semver_warning(runner, caplog):
|
||||
def test_v1_bump_semver_warning(runner, caplog):
|
||||
_add_project_files("README.md")
|
||||
|
||||
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
||||
|
|
@ -509,7 +533,7 @@ def test_bump_semver_warning(runner, caplog):
|
|||
assert result.exit_code == 0
|
||||
|
||||
|
||||
def test_bump_semver_diff(runner, caplog):
|
||||
def test_v1_bump_semver_diff(runner, caplog):
|
||||
_add_project_files("README.md")
|
||||
|
||||
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
||||
|
|
@ -531,6 +555,48 @@ def test_bump_semver_diff(runner, caplog):
|
|||
assert f"+current_version = \"{expected}\"" in out_lines
|
||||
|
||||
|
||||
def test_v1_get_diff(runner):
|
||||
_add_project_files("README.md", "setup.cfg")
|
||||
result = runner.invoke(cli, ['init', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val("setup.cfg", version_pattern='"{pycalver}"')
|
||||
|
||||
_, cfg = config.init()
|
||||
new_version = "v202010.1003-beta"
|
||||
diff_str = v1cli.get_diff(cfg, new_version)
|
||||
diff_lines = set(diff_str.splitlines())
|
||||
|
||||
assert "- Hello World v201701.1002-alpha !" in diff_lines
|
||||
assert "- aka. 201701.1002a0 !" in diff_lines
|
||||
assert "+ Hello World v202010.1003-beta !" in diff_lines
|
||||
assert "+ aka. 202010.1003b0 !" in diff_lines
|
||||
|
||||
assert '-current_version = "v202010.1001-alpha"' in diff_lines
|
||||
assert '+current_version = "v202010.1003-beta"' in diff_lines
|
||||
|
||||
|
||||
def test_v2_get_diff(runner):
|
||||
_add_project_files("README.md", "setup.cfg")
|
||||
result = runner.invoke(cli, ['init', "-vv"])
|
||||
assert result.exit_code == 0
|
||||
|
||||
_update_config_val("setup.cfg", version_pattern='"vYYYY0M.BUILD[-RELEASE]"')
|
||||
|
||||
_, cfg = config.init()
|
||||
new_version = "v202010.1003-beta"
|
||||
diff_str = v2cli.get_diff(cfg, new_version)
|
||||
diff_lines = set(diff_str.splitlines())
|
||||
|
||||
assert "- Hello World v201701.1002-alpha !" in diff_lines
|
||||
assert "- aka. 201701.1002a0 !" in diff_lines
|
||||
assert "+ Hello World v202010.1003-beta !" in diff_lines
|
||||
assert "+ aka. 202010.1003b0 !" in diff_lines
|
||||
|
||||
assert '-current_version = "v202010.1001-alpha"' in diff_lines
|
||||
assert '+current_version = "v202010.1003-beta"' in diff_lines
|
||||
|
||||
|
||||
# def test_custom_commit_message(runner):
|
||||
# # TODO (mb 2020-09-18):
|
||||
# assert False
|
||||
|
|
|
|||
|
|
@ -90,6 +90,13 @@ def mk_buf(text):
|
|||
return buf
|
||||
|
||||
|
||||
def _parse_raw_patterns_by_filepath(cfg):
|
||||
return {
|
||||
filepath: [pattern.raw_pattern for pattern in patterns]
|
||||
for filepath, patterns in cfg.file_patterns.items()
|
||||
}
|
||||
|
||||
|
||||
def test_parse_toml_1():
|
||||
buf = mk_buf(PYCALVER_TOML_FIXTURE_1)
|
||||
|
||||
|
|
@ -103,8 +110,10 @@ def test_parse_toml_1():
|
|||
assert cfg.push is True
|
||||
|
||||
assert "pycalver.toml" in cfg.file_patterns
|
||||
assert cfg.file_patterns["README.md" ] == ["{pycalver}", "{pep440_pycalver}"]
|
||||
assert cfg.file_patterns["pycalver.toml"] == ['current_version = "{pycalver}"']
|
||||
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath["README.md" ] == ["{pycalver}", "{pep440_pycalver}"]
|
||||
assert raw_patterns_by_filepath["pycalver.toml"] == ['current_version = "{pycalver}"']
|
||||
|
||||
|
||||
def test_parse_toml_2():
|
||||
|
|
@ -120,8 +129,10 @@ def test_parse_toml_2():
|
|||
assert cfg.push is False
|
||||
|
||||
assert "pycalver.toml" in cfg.file_patterns
|
||||
assert cfg.file_patterns["README.md" ] == ["{semver}", "{semver}"]
|
||||
assert cfg.file_patterns["pycalver.toml"] == ['current_version = "{semver}"']
|
||||
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath["README.md" ] == ["{semver}", "{semver}"]
|
||||
assert raw_patterns_by_filepath["pycalver.toml"] == ['current_version = "{semver}"']
|
||||
|
||||
|
||||
def test_parse_v1_cfg():
|
||||
|
|
@ -136,8 +147,10 @@ def test_parse_v1_cfg():
|
|||
assert cfg.push is True
|
||||
|
||||
assert "setup.cfg" in cfg.file_patterns
|
||||
assert cfg.file_patterns["setup.py" ] == ["{pycalver}", "{pep440_pycalver}"]
|
||||
assert cfg.file_patterns["setup.cfg"] == ['current_version = "{pycalver}"']
|
||||
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath["setup.py" ] == ["{pycalver}", "{pep440_pycalver}"]
|
||||
assert raw_patterns_by_filepath["setup.cfg"] == ['current_version = "{pycalver}"']
|
||||
|
||||
|
||||
def test_parse_v2_cfg():
|
||||
|
|
@ -153,10 +166,12 @@ def test_parse_v2_cfg():
|
|||
|
||||
assert "setup.py" in cfg.file_patterns
|
||||
assert "setup.cfg" in cfg.file_patterns
|
||||
|
||||
# TODO (mb 2020-09-18):
|
||||
# assert cfg.file_patterns["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
|
||||
# assert cfg.file_patterns["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-RELEASE]"']
|
||||
# assert cfg.file_patterns["src/project/*.py"] == ['Copyright (c) 2018-YYYY"']
|
||||
# raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
# assert raw_patterns_by_filepath["setup.py" ] == ["vYYYY0M.BUILD[-RELEASE]", "YYYY0M.BLD[PYTAGNUM]"]
|
||||
# assert raw_patterns_by_filepath["setup.cfg" ] == ['current_version = "vYYYY0M.BUILD[-RELEASE]"']
|
||||
# assert raw_patterns_by_filepath["src/project/*.py"] == ['Copyright (c) 2018-YYYY"']
|
||||
|
||||
|
||||
def test_parse_default_toml():
|
||||
|
|
@ -186,8 +201,9 @@ def test_parse_default_cfg():
|
|||
|
||||
|
||||
def test_parse_project_toml():
|
||||
project_path = util.FIXTURES_DIR / "project_a"
|
||||
config_path = util.FIXTURES_DIR / "project_a" / "pycalver.toml"
|
||||
project_path = util.FIXTURES_DIR / "project_a"
|
||||
config_path = util.FIXTURES_DIR / "project_a" / "pycalver.toml"
|
||||
config_rel_path = "pycalver.toml"
|
||||
|
||||
with config_path.open() as fobj:
|
||||
config_data = fobj.read()
|
||||
|
|
@ -195,7 +211,7 @@ def test_parse_project_toml():
|
|||
assert "v201710.0123-alpha" in config_data
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, "toml", None)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, config_rel_path, "toml", None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
|
|
@ -210,8 +226,9 @@ def test_parse_project_toml():
|
|||
|
||||
|
||||
def test_parse_project_cfg():
|
||||
project_path = util.FIXTURES_DIR / "project_b"
|
||||
config_path = util.FIXTURES_DIR / "project_b" / "setup.cfg"
|
||||
project_path = util.FIXTURES_DIR / "project_b"
|
||||
config_path = util.FIXTURES_DIR / "project_b" / "setup.cfg"
|
||||
config_rel_path = "setup.cfg"
|
||||
|
||||
with config_path.open() as fobj:
|
||||
config_data = fobj.read()
|
||||
|
|
@ -219,7 +236,7 @@ def test_parse_project_cfg():
|
|||
assert "v201307.0456-beta" in config_data
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, 'cfg', None)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, config_rel_path, 'cfg', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
|
|
@ -241,9 +258,10 @@ def test_parse_toml_file(tmpdir):
|
|||
project_path = tmpdir.mkdir("minimal")
|
||||
setup_cfg = project_path.join("pycalver.toml")
|
||||
setup_cfg.write(PYCALVER_TOML_FIXTURE_1)
|
||||
setup_cfg_rel_path = "pycalver.toml"
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, 'toml', None)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, setup_cfg_rel_path, 'toml', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
|
|
@ -253,19 +271,21 @@ def test_parse_toml_file(tmpdir):
|
|||
assert cfg.commit is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert cfg.file_patterns == {
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath == {
|
||||
"README.md" : ["{pycalver}", "{pep440_pycalver}"],
|
||||
"pycalver.toml": ['current_version = "{pycalver}"'],
|
||||
}
|
||||
|
||||
|
||||
def test_parse_default_pattern():
|
||||
project_path = util.FIXTURES_DIR / "project_c"
|
||||
config_path = util.FIXTURES_DIR / "project_c" / "pyproject.toml"
|
||||
project_path = util.FIXTURES_DIR / "project_c"
|
||||
config_path = util.FIXTURES_DIR / "project_c" / "pyproject.toml"
|
||||
config_rel_path = "pyproject.toml"
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
|
||||
assert ctx == config.ProjectContext(project_path, config_path, "toml", None)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, config_rel_path, "toml", None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
|
|
@ -276,7 +296,8 @@ def test_parse_default_pattern():
|
|||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert cfg.file_patterns == {
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath == {
|
||||
"pyproject.toml": [r'current_version = "v{year}q{quarter}.{build_no}"']
|
||||
}
|
||||
|
||||
|
|
@ -285,9 +306,10 @@ def test_parse_cfg_file(tmpdir):
|
|||
project_path = tmpdir.mkdir("minimal")
|
||||
setup_cfg = project_path.join("setup.cfg")
|
||||
setup_cfg.write(SETUP_CFG_FIXTURE)
|
||||
setup_cfg_rel_path = "setup.cfg"
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, 'cfg', None)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, setup_cfg_rel_path, 'cfg', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
|
|
@ -297,7 +319,8 @@ def test_parse_cfg_file(tmpdir):
|
|||
assert cfg.commit is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert cfg.file_patterns == {
|
||||
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
|
||||
assert raw_patterns_by_filepath == {
|
||||
"setup.py" : ["{pycalver}", "{pep440_pycalver}"],
|
||||
"setup.cfg": ['current_version = "{pycalver}"'],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ from __future__ import print_function
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import copy
|
||||
from test import util
|
||||
|
||||
|
|
@ -13,35 +14,77 @@ from pycalver import v1rewrite
|
|||
from pycalver import v1version
|
||||
from pycalver import v2rewrite
|
||||
from pycalver import v2version
|
||||
from pycalver import v1patterns
|
||||
from pycalver import v2patterns
|
||||
|
||||
# pylint:disable=protected-access ; allowed for test code
|
||||
|
||||
|
||||
# Fix for Python<3.7
|
||||
# https://stackoverflow.com/a/56935186/62997
|
||||
copy._deepcopy_dispatch[type(re.compile(''))] = lambda r, _: r
|
||||
|
||||
|
||||
REWRITE_FIXTURE = """
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "v201809.0002-beta"
|
||||
"""
|
||||
|
||||
|
||||
def test_rewrite_lines():
|
||||
old_lines = REWRITE_FIXTURE.splitlines()
|
||||
patterns = ['__version__ = "{pycalver}"']
|
||||
def test_v1_rewrite_lines_basic():
|
||||
pattern = v1patterns.compile_pattern("{pycalver}", '__version__ = "{pycalver}"')
|
||||
new_vinfo = v1version.parse_version_info("v201911.0003")
|
||||
new_lines = v1rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
|
||||
old_lines = REWRITE_FIXTURE.splitlines()
|
||||
new_lines = v1rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "v201911.0003" not in "\n".join(old_lines)
|
||||
assert "v201911.0003" in "\n".join(new_lines)
|
||||
|
||||
|
||||
def test_rewrite_final():
|
||||
def test_v1_rewrite_lines():
|
||||
version_pattern = "{pycalver}"
|
||||
new_vinfo = v1version.parse_version_info("v201811.0123-beta", version_pattern)
|
||||
patterns = [v1patterns.compile_pattern(version_pattern, '__version__ = "{pycalver}"')]
|
||||
lines = v1rewrite.rewrite_lines(patterns, new_vinfo, ['__version__ = "v201809.0002-beta"'])
|
||||
assert lines == ['__version__ = "v201811.0123-beta"']
|
||||
|
||||
patterns = [v1patterns.compile_pattern(version_pattern, '__version__ = "{pep440_version}"')]
|
||||
lines = v1rewrite.rewrite_lines(patterns, new_vinfo, ['__version__ = "201809.2b0"'])
|
||||
assert lines == ['__version__ = "201811.123b0"']
|
||||
|
||||
|
||||
def test_v2_rewrite_lines():
|
||||
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
new_vinfo = v2version.parse_version_info("v201811.0123-beta", version_pattern)
|
||||
patterns = [v2patterns.compile_pattern(version_pattern, '__version__ = "{version}"')]
|
||||
lines = v2rewrite.rewrite_lines(patterns, new_vinfo, ['__version__ = "v201809.0002-alpha" '])
|
||||
assert lines == ['__version__ = "v201811.0123-beta" ']
|
||||
|
||||
lines = v2rewrite.rewrite_lines(
|
||||
patterns, new_vinfo, ['__version__ = "v201809.0002-alpha" # comment']
|
||||
)
|
||||
assert lines == ['__version__ = "v201811.0123-beta" # comment']
|
||||
|
||||
patterns = [v2patterns.compile_pattern(version_pattern, '__version__ = "YYYY0M.BLD[PYTAGNUM]"')]
|
||||
old_lines = ['__version__ = "201809.2a0"']
|
||||
lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
assert lines == ['__version__ = "201811.123b0"']
|
||||
|
||||
|
||||
def test_v1_rewrite_final():
|
||||
# Patterns written with {release_tag} placeholder preserve
|
||||
# the release tag even if the new version is -final
|
||||
|
||||
old_lines = REWRITE_FIXTURE.splitlines()
|
||||
patterns = ['__version__ = "v{year}{month}.{build_no}-{release_tag}"']
|
||||
pattern = v1patterns.compile_pattern(
|
||||
"v{year}{month}.{build_no}-{release_tag}",
|
||||
'__version__ = "v{year}{month}.{build_no}-{release_tag}"',
|
||||
)
|
||||
new_vinfo = v1version.parse_version_info("v201911.0003")
|
||||
new_lines = v1rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
|
||||
old_lines = REWRITE_FIXTURE.splitlines()
|
||||
new_lines = v1rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "v201911.0003" not in "\n".join(old_lines)
|
||||
|
|
@ -93,14 +136,19 @@ def test_error_bad_path():
|
|||
assert "setup.py" in str(ex)
|
||||
|
||||
|
||||
def test_error_bad_pattern():
|
||||
def test_v1_error_bad_pattern():
|
||||
with util.Project(project="b") as project:
|
||||
ctx = config.init_project_ctx(project.dir)
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg
|
||||
|
||||
patterns = copy.deepcopy(cfg.file_patterns)
|
||||
patterns["setup.py"] = patterns["setup.py"][0] + "invalid"
|
||||
patterns = copy.deepcopy(cfg.file_patterns)
|
||||
original_pattern = patterns["setup.py"][0]
|
||||
invalid_pattern = v1patterns.compile_pattern(
|
||||
original_pattern.version_pattern,
|
||||
original_pattern.raw_pattern + ".invalid",
|
||||
)
|
||||
patterns["setup.py"] = [invalid_pattern]
|
||||
|
||||
try:
|
||||
old_vinfo = v1version.parse_version_info("v201808.0233")
|
||||
|
|
@ -118,45 +166,163 @@ __version__ = "2018.0002-beta"
|
|||
|
||||
|
||||
def test_v1_optional_release():
|
||||
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
||||
pattern = "{year}.{build_no}{release}"
|
||||
patterns = ['__version__ = "{year}.{build_no}{release}"']
|
||||
version_pattern = "{year}.{build_no}{release}"
|
||||
new_vinfo = v1version.parse_version_info("2019.0003", version_pattern)
|
||||
|
||||
new_vinfo = v1version.parse_version_info("2019.0003", pattern)
|
||||
new_lines = v1rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
raw_pattern = '__version__ = "{year}.{build_no}{release}"'
|
||||
pattern = v1patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
|
||||
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
||||
new_lines = v1rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "2019.0003" not in "\n".join(old_lines)
|
||||
new_text = "\n".join(new_lines)
|
||||
assert "2019.0003" in new_text
|
||||
assert "2019.0003" in "\n".join(new_lines)
|
||||
assert '__version__ = "2019.0003"' in "\n".join(new_lines)
|
||||
|
||||
new_vinfo = v1version.parse_version_info("2019.0004-beta", pattern)
|
||||
new_lines = v1rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
new_vinfo = v1version.parse_version_info("2019.0004-beta", version_pattern)
|
||||
new_lines = v1rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
# make sure optional release tag is added back on
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "2019.0004-beta" not in "\n".join(old_lines)
|
||||
assert "2019.0004-beta" in "\n".join(new_lines)
|
||||
assert '__version__ = "2019.0004-beta"' in "\n".join(new_lines)
|
||||
|
||||
|
||||
def test_v2_optional_release():
|
||||
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
||||
pattern = "YYYY.BUILD[-RELEASE]"
|
||||
patterns = ['__version__ = "YYYY.BUILD[-RELEASE]"']
|
||||
version_pattern = "YYYY.BUILD[-RELEASE]"
|
||||
new_vinfo = v2version.parse_version_info("2019.0003", version_pattern)
|
||||
|
||||
new_vinfo = v2version.parse_version_info("2019.0003", pattern)
|
||||
new_lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
raw_pattern = '__version__ = "YYYY.BUILD[-RELEASE]"'
|
||||
pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
|
||||
old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
|
||||
new_lines = v2rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "2019.0003" not in "\n".join(old_lines)
|
||||
new_text = "\n".join(new_lines)
|
||||
assert "2019.0003" in new_text
|
||||
assert '__version__ = "2019.0003"' in new_text
|
||||
assert "2019.0003" in "\n".join(new_lines)
|
||||
assert '__version__ = "2019.0003"' in "\n".join(new_lines)
|
||||
|
||||
new_vinfo = v2version.parse_version_info("2019.0004-beta", pattern)
|
||||
new_lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
|
||||
new_vinfo = v2version.parse_version_info("2019.0004-beta", version_pattern)
|
||||
new_lines = v2rewrite.rewrite_lines([pattern], new_vinfo, old_lines)
|
||||
|
||||
# make sure optional release tag is added back on
|
||||
assert len(new_lines) == len(old_lines)
|
||||
assert "2019.0004-beta" not in "\n".join(old_lines)
|
||||
assert "2019.0004-beta" in "\n".join(new_lines)
|
||||
assert '__version__ = "2019.0004-beta"' in "\n".join(new_lines)
|
||||
|
||||
|
||||
def test_v1_iter_rewritten():
|
||||
version_pattern = "{pycalver}"
|
||||
new_vinfo = v1version.parse_version_info("v201809.0123")
|
||||
|
||||
file_patterns = {
|
||||
"src/pycalver/__init__.py": [
|
||||
v1patterns.compile_pattern(version_pattern, '__version__ = "{pycalver}"'),
|
||||
]
|
||||
}
|
||||
rewritten_datas = v1rewrite.iter_rewritten(file_patterns, new_vinfo)
|
||||
rfd = list(rewritten_datas)[0]
|
||||
expected = [
|
||||
"# This file is part of the pycalver project",
|
||||
"# https://github.com/mbarkhau/pycalver",
|
||||
"#",
|
||||
"# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License",
|
||||
"# SPDX-License-Identifier: MIT",
|
||||
'"""PyCalVer: CalVer for Python Packages."""',
|
||||
'',
|
||||
'__version__ = "v201809.0123"',
|
||||
'',
|
||||
]
|
||||
assert rfd.new_lines == expected
|
||||
|
||||
|
||||
def test_v2_iter_rewritten():
|
||||
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
new_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||
|
||||
file_patterns = {
|
||||
"src/pycalver/__init__.py": [
|
||||
v2patterns.compile_pattern(version_pattern, '__version__ = "vYYYY0M.BUILD[-RELEASE]"'),
|
||||
]
|
||||
}
|
||||
|
||||
rewritten_datas = v2rewrite.iter_rewritten(file_patterns, new_vinfo)
|
||||
rfd = list(rewritten_datas)[0]
|
||||
expected = [
|
||||
"# This file is part of the pycalver project",
|
||||
"# https://github.com/mbarkhau/pycalver",
|
||||
"#",
|
||||
"# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License",
|
||||
"# SPDX-License-Identifier: MIT",
|
||||
'"""PyCalVer: CalVer for Python Packages."""',
|
||||
'',
|
||||
'__version__ = "v201809.0123"',
|
||||
'',
|
||||
]
|
||||
assert rfd.new_lines == expected
|
||||
|
||||
|
||||
def test_v1_diff():
|
||||
version_pattern = "{pycalver}"
|
||||
raw_pattern = '__version__ = "{pycalver}"'
|
||||
pattern = v1patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
file_patterns = {"src/pycalver/__init__.py": [pattern]}
|
||||
|
||||
old_vinfo = v1version.parse_version_info("v201809.0123")
|
||||
new_vinfo = v1version.parse_version_info("v201910.1124")
|
||||
|
||||
diff_str = v1rewrite.diff(old_vinfo, new_vinfo, file_patterns)
|
||||
lines = diff_str.split("\n")
|
||||
|
||||
assert lines[:2] == ["--- src/pycalver/__init__.py", "+++ src/pycalver/__init__.py"]
|
||||
|
||||
assert lines[6].startswith('-__version__ = "v20')
|
||||
assert lines[7].startswith('+__version__ = "v20')
|
||||
|
||||
assert not lines[6].startswith('-__version__ = "v201809.0123"')
|
||||
|
||||
assert lines[7] == '+__version__ = "v201910.1124"'
|
||||
|
||||
raw_pattern = "Copyright (c) 2018-{year}"
|
||||
pattern = v1patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
file_patterns = {'LICENSE': [pattern]}
|
||||
diff_str = v1rewrite.diff(old_vinfo, new_vinfo, file_patterns)
|
||||
|
||||
lines = diff_str.split("\n")
|
||||
assert lines[3].startswith("-MIT License Copyright (c) 2018-20")
|
||||
assert lines[4].startswith("+MIT License Copyright (c) 2018-2019")
|
||||
|
||||
|
||||
def test_v2_diff():
|
||||
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||
raw_pattern = '__version__ = "vYYYY0M.BUILD[-RELEASE]"'
|
||||
pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
file_patterns = {"src/pycalver/__init__.py": [pattern]}
|
||||
|
||||
old_vinfo = v2version.parse_version_info("v201809.0123", version_pattern)
|
||||
new_vinfo = v2version.parse_version_info("v201910.1124", version_pattern)
|
||||
|
||||
diff_str = v2rewrite.diff(old_vinfo, new_vinfo, file_patterns)
|
||||
lines = diff_str.split("\n")
|
||||
|
||||
assert lines[:2] == ["--- src/pycalver/__init__.py", "+++ src/pycalver/__init__.py"]
|
||||
|
||||
assert lines[6].startswith('-__version__ = "v20')
|
||||
assert lines[7].startswith('+__version__ = "v20')
|
||||
|
||||
assert not lines[6].startswith('-__version__ = "v201809.0123"')
|
||||
|
||||
assert lines[7] == '+__version__ = "v201910.1124"'
|
||||
|
||||
raw_pattern = "Copyright (c) 2018-YYYY"
|
||||
pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)
|
||||
file_patterns = {'LICENSE': [pattern]}
|
||||
diff_str = v2rewrite.diff(old_vinfo, new_vinfo, file_patterns)
|
||||
|
||||
lines = diff_str.split("\n")
|
||||
assert lines[3].startswith("-MIT License Copyright (c) 2018-20")
|
||||
assert lines[4].startswith("+MIT License Copyright (c) 2018-2019")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue