2020-07-19 14:38:57 +00:00
|
|
|
# pylint:disable=redefined-outer-name ; pytest fixtures
|
|
|
|
|
# pylint:disable=protected-access ; allowed for test code
|
|
|
|
|
|
2018-12-21 19:23:34 +01:00
|
|
|
import os
|
2018-12-21 19:51:58 +01:00
|
|
|
import time
|
2018-12-21 19:23:34 +01:00
|
|
|
import shutil
|
|
|
|
|
import subprocess as sp
|
|
|
|
|
|
|
|
|
|
import pytest
|
2020-05-25 07:46:30 +00:00
|
|
|
import pathlib2 as pl
|
2018-12-21 19:23:34 +01:00
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
2020-05-25 07:46:30 +00:00
|
|
|
import pycalver.cli as cli
|
2018-12-21 19:23:34 +01:00
|
|
|
import pycalver.config as config
|
2019-01-06 14:38:20 +01:00
|
|
|
import pycalver.patterns as patterns
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
SETUP_CFG_FIXTURE = """
|
|
|
|
|
[metadata]
|
|
|
|
|
license_file = LICENSE
|
|
|
|
|
|
|
|
|
|
[bdist_wheel]
|
|
|
|
|
universal = 1
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PYCALVER_TOML_FIXTURE = """
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
PYPROJECT_TOML_FIXTURE = """
|
|
|
|
|
[build-system]
|
|
|
|
|
requires = ["setuptools", "wheel"]
|
|
|
|
|
"""
|
|
|
|
|
|
2018-12-21 20:03:40 +01:00
|
|
|
ENV = {
|
|
|
|
|
'GIT_AUTHOR_NAME' : "pycalver_tester",
|
|
|
|
|
'GIT_COMMITTER_NAME' : "pycalver_tester",
|
2018-12-21 20:34:42 +01:00
|
|
|
'GIT_AUTHOR_EMAIL' : "pycalver_tester@nowhere.com",
|
|
|
|
|
'GIT_COMMITTER_EMAIL': "pycalver_tester@nowhere.com",
|
2018-12-21 20:03:40 +01:00
|
|
|
'HGUSER' : "pycalver_tester",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
def shell(*cmd):
|
2018-12-21 20:03:40 +01:00
|
|
|
return sp.check_output(cmd, env=ENV)
|
|
|
|
|
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def runner(tmpdir):
|
2018-12-21 20:03:40 +01:00
|
|
|
runner = CliRunner(env=ENV)
|
2018-12-21 19:23:34 +01:00
|
|
|
orig_cwd = os.getcwd()
|
|
|
|
|
|
|
|
|
|
_debug = 0
|
|
|
|
|
if _debug:
|
|
|
|
|
tmpdir = pl.Path("..") / "tmp_test_pycalver_project"
|
|
|
|
|
if tmpdir.exists():
|
2018-12-21 19:51:58 +01:00
|
|
|
time.sleep(0.2)
|
2018-12-21 19:23:34 +01:00
|
|
|
shutil.rmtree(str(tmpdir))
|
|
|
|
|
tmpdir.mkdir()
|
|
|
|
|
|
|
|
|
|
os.chdir(str(tmpdir))
|
|
|
|
|
|
|
|
|
|
yield runner
|
|
|
|
|
|
|
|
|
|
os.chdir(orig_cwd)
|
|
|
|
|
|
|
|
|
|
if not _debug:
|
|
|
|
|
shutil.rmtree(str(tmpdir))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_help(runner):
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['--help', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert "PyCalVer" in result.output
|
|
|
|
|
assert "bump " in result.output
|
2018-12-21 23:48:02 +01:00
|
|
|
assert "test " in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
assert "init " in result.output
|
|
|
|
|
assert "show " in result.output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_version(runner):
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['--version', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert " version v20" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
match = patterns.PYCALVER_RE.search(result.output)
|
2018-12-21 19:23:34 +01:00
|
|
|
assert match
|
|
|
|
|
|
|
|
|
|
|
2019-01-06 14:38:20 +01:00
|
|
|
def test_incr_default(runner):
|
2018-12-21 19:23:34 +01:00
|
|
|
old_version = "v201701.0999-alpha"
|
|
|
|
|
initial_version = config._initial_version()
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", old_version])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
new_version = initial_version.replace(".0001-alpha", ".11000-alpha")
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"Version: {new_version}\n" in result.output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_incr_semver(runner):
|
|
|
|
|
semver_pattern = "{MAJOR}.{MINOR}.{PATCH}"
|
|
|
|
|
old_version = "0.1.0"
|
|
|
|
|
new_version = "0.1.1"
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", "--patch", old_version, "{semver}"])
|
2019-01-06 14:38:20 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Version: {new_version}\n" in result.output
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", "--patch", old_version, semver_pattern])
|
2019-01-06 14:38:20 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Version: {new_version}\n" in result.output
|
|
|
|
|
|
|
|
|
|
old_version = "0.1.1"
|
|
|
|
|
new_version = "0.2.0"
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", "--minor", old_version, semver_pattern])
|
2019-01-06 14:38:20 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Version: {new_version}\n" in result.output
|
|
|
|
|
|
|
|
|
|
old_version = "0.1.1"
|
|
|
|
|
new_version = "1.0.0"
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", "--major", old_version, semver_pattern])
|
2019-01-06 14:38:20 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Version: {new_version}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
2019-01-07 17:30:02 +01:00
|
|
|
def test_incr_semver_invalid(runner, caplog):
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', "-vv", "--patch", "0.1.1"])
|
2019-01-07 17:30:02 +01:00
|
|
|
assert result.exit_code == 1
|
|
|
|
|
assert len(caplog.records) > 0
|
|
|
|
|
log_record = caplog.records[0]
|
|
|
|
|
assert "Invalid version string" in log_record.message
|
|
|
|
|
assert "for pattern '{pycalver}'" in log_record.message
|
|
|
|
|
|
|
|
|
|
|
2018-12-21 19:23:34 +01:00
|
|
|
def test_incr_to_beta(runner):
|
|
|
|
|
old_version = "v201701.0999-alpha"
|
|
|
|
|
initial_version = config._initial_version()
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--release", "beta"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
new_version = initial_version.replace(".0001-alpha", ".11000-beta")
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"Version: {new_version}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_incr_to_final(runner):
|
|
|
|
|
old_version = "v201701.0999-alpha"
|
|
|
|
|
initial_version = config._initial_version()
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--release", "final"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
new_version = initial_version.replace(".0001-alpha", ".11000")
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"Version: {new_version}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
2019-01-07 17:30:02 +01:00
|
|
|
def test_incr_invalid(runner):
|
2018-12-21 19:23:34 +01:00
|
|
|
old_version = "v201701.0999-alpha"
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['test', old_version, "-vv", "--release", "alfa"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _add_project_files(*files):
|
|
|
|
|
if "README.md" in files:
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("README.md").open(mode="wt", encoding="utf-8") as fobj:
|
|
|
|
|
fobj.write(
|
2019-02-22 22:47:44 +01:00
|
|
|
"""
|
2019-02-22 11:11:54 +01:00
|
|
|
Hello World v201701.0002-alpha !
|
|
|
|
|
aka. 201701.2a0 !
|
2019-02-22 22:47:44 +01:00
|
|
|
"""
|
|
|
|
|
)
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
if "setup.cfg" in files:
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("setup.cfg").open(mode="wt", encoding="utf-8") as fobj:
|
|
|
|
|
fobj.write(SETUP_CFG_FIXTURE)
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
if "pycalver.toml" in files:
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("pycalver.toml").open(mode="wt", encoding="utf-8") as fobj:
|
|
|
|
|
fobj.write(PYCALVER_TOML_FIXTURE)
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
if "pyproject.toml" in files:
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("pyproject.toml").open(mode="wt", encoding="utf-8") as fobj:
|
|
|
|
|
fobj.write(PYPROJECT_TOML_FIXTURE)
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_nocfg(runner, caplog):
|
|
|
|
|
_add_project_files("README.md")
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 1
|
|
|
|
|
assert any(
|
|
|
|
|
bool("Could not parse configuration. Perhaps try 'pycalver init'." in r.message)
|
|
|
|
|
for r in caplog.records
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2019-07-09 10:05:57 +02:00
|
|
|
def test_novcs_nocfg_init(runner, caplog):
|
2018-12-21 19:23:34 +01:00
|
|
|
_add_project_files("README.md")
|
2019-01-07 17:30:02 +01:00
|
|
|
# dry mode test
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv", "--dry"])
|
2019-01-07 17:30:02 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert not os.path.exists("pycalver.toml")
|
|
|
|
|
|
|
|
|
|
# check logging
|
|
|
|
|
assert len(caplog.records) == 1
|
|
|
|
|
log = caplog.records[0]
|
|
|
|
|
assert log.levelname == 'WARNING'
|
|
|
|
|
assert "File not found" in log.message
|
|
|
|
|
|
|
|
|
|
# non dry mode
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2019-01-07 17:30:02 +01:00
|
|
|
# check logging
|
|
|
|
|
assert len(caplog.records) == 2
|
|
|
|
|
log = caplog.records[1]
|
|
|
|
|
assert log.levelname == 'WARNING'
|
|
|
|
|
assert "File not found" in log.message
|
|
|
|
|
|
|
|
|
|
assert os.path.exists("pycalver.toml")
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("pycalver.toml").open(mode="r", encoding="utf-8") as fobj:
|
|
|
|
|
cfg_content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
|
|
|
|
|
assert base_str in cfg_content
|
|
|
|
|
assert config.DEFAULT_TOML_README_MD_STR in cfg_content
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {config._initial_version()}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2019-01-07 17:30:02 +01:00
|
|
|
assert result.exit_code == 1
|
|
|
|
|
|
|
|
|
|
# check logging
|
|
|
|
|
assert len(caplog.records) == 3
|
|
|
|
|
log = caplog.records[2]
|
|
|
|
|
assert log.levelname == 'ERROR'
|
|
|
|
|
assert "Configuration already initialized" in log.message
|
|
|
|
|
|
2018-12-21 19:23:34 +01:00
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
def test_novcs_setupcfg_init(runner):
|
2018-12-21 19:23:34 +01:00
|
|
|
_add_project_files("README.md", "setup.cfg")
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("setup.cfg").open(mode="r", encoding="utf-8") as fobj:
|
|
|
|
|
cfg_content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
base_str = config.DEFAULT_CONFIGPARSER_BASE_TMPL.format(
|
|
|
|
|
initial_version=config._initial_version()
|
|
|
|
|
)
|
|
|
|
|
assert base_str in cfg_content
|
|
|
|
|
assert config.DEFAULT_CONFIGPARSER_README_MD_STR in cfg_content
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {config._initial_version()}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_novcs_pyproject_init(runner):
|
|
|
|
|
_add_project_files("README.md", "pyproject.toml")
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("pyproject.toml").open(mode="r", encoding="utf-8") as fobj:
|
|
|
|
|
cfg_content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
|
|
|
|
|
assert base_str in cfg_content
|
|
|
|
|
assert config.DEFAULT_TOML_README_MD_STR in cfg_content
|
|
|
|
|
|
2019-03-28 23:22:15 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show'])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {config._initial_version()}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
def _vcs_init(vcs, files=("README.md",)):
|
2019-03-24 18:46:39 +01:00
|
|
|
assert vcs in ("git", "hg")
|
2018-12-21 19:23:34 +01:00
|
|
|
assert not pl.Path(f".{vcs}").exists()
|
2020-07-19 14:38:57 +00:00
|
|
|
shell(f"{vcs}", "init")
|
2018-12-21 19:23:34 +01:00
|
|
|
assert pl.Path(f".{vcs}").is_dir()
|
|
|
|
|
|
2019-07-09 10:07:26 +02:00
|
|
|
for filename in files:
|
2020-07-19 14:38:57 +00:00
|
|
|
shell(f"{vcs}", "add", filename)
|
2019-07-09 10:07:26 +02:00
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
shell(f"{vcs}", "commit", "-m", "initial commit")
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_git_init(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("git")
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2019-03-28 23:22:15 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show'])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {config._initial_version()}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hg_init(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("hg")
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2019-03-28 23:22:15 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show'])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {config._initial_version()}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_git_tag_eval(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("git")
|
|
|
|
|
|
|
|
|
|
# This will set a version that is older than the version tag
|
|
|
|
|
# we set in the vcs, which should take precedence.
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
initial_version = config._initial_version()
|
|
|
|
|
tag_version = initial_version.replace(".0001-alpha", ".0123-beta")
|
|
|
|
|
tag_version_pep440 = tag_version[1:7] + ".123b0"
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("git", "tag", "--annotate", tag_version, "--message", f"bump version to {tag_version}")
|
2018-12-21 19:23:34 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {tag_version}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {tag_version_pep440}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hg_tag_eval(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("hg")
|
|
|
|
|
|
|
|
|
|
# This will set a version that is older than the version tag
|
|
|
|
|
# we set in the vcs, which should take precedence.
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
initial_version = config._initial_version()
|
|
|
|
|
tag_version = initial_version.replace(".0001-alpha", ".0123-beta")
|
|
|
|
|
tag_version_pep440 = tag_version[1:7] + ".123b0"
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("hg", "tag", tag_version, "--message", f"bump version to {tag_version}")
|
2018-12-21 19:23:34 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['show', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert f"Current Version: {tag_version}\n" in result.output
|
2019-01-06 14:38:20 +01:00
|
|
|
assert f"PEP440 : {tag_version_pep440}\n" in result.output
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_novcs_bump(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
calver = config._initial_version()[:7]
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("README.md").open() as fobj:
|
|
|
|
|
content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
assert calver + ".0002-alpha !\n" in content
|
2019-02-22 22:44:40 +01:00
|
|
|
assert calver[1:] + ".2a0 !\n" in content
|
2018-12-21 19:23:34 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump', "-vv", "--release", "beta"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("README.md").open() as fobj:
|
|
|
|
|
content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
assert calver + ".0003-beta !\n" in content
|
2019-02-22 22:44:40 +01:00
|
|
|
assert calver[1:] + ".3b0 !\n" in content
|
2018-12-21 19:23:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_git_bump(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("git")
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("git", "add", "pycalver.toml")
|
|
|
|
|
shell("git", "commit", "-m", "initial commit")
|
2019-03-24 18:46:39 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
2018-12-21 19:23:34 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
calver = config._initial_version()[:7]
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("README.md").open() as fobj:
|
|
|
|
|
content = fobj.read()
|
2018-12-21 19:23:34 +01:00
|
|
|
assert calver + ".0002-alpha !\n" in content
|
2018-12-21 19:51:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hg_bump(runner):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
_vcs_init("hg")
|
|
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2018-12-21 19:51:58 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("hg", "add", "pycalver.toml")
|
|
|
|
|
shell("hg", "commit", "-m", "initial commit")
|
2019-03-24 18:46:39 +01:00
|
|
|
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump', "-vv"])
|
2018-12-21 19:51:58 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
calver = config._initial_version()[:7]
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("README.md").open() as fobj:
|
|
|
|
|
content = fobj.read()
|
2018-12-21 19:51:58 +01:00
|
|
|
assert calver + ".0002-alpha !\n" in content
|
2019-03-24 18:46:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_git_bump(runner, caplog):
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("git", "init")
|
|
|
|
|
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
|
|
|
|
fobj.write("")
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2019-03-24 18:46:39 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("setup.cfg").open(mode="r") as fobj:
|
|
|
|
|
default_cfg_data = fobj.read()
|
2019-03-24 18:46:39 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2019-03-28 23:22:15 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump'])
|
2019-03-24 18:46:39 +01:00
|
|
|
|
|
|
|
|
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):
|
2020-07-19 14:38:57 +00:00
|
|
|
shell("hg", "init")
|
|
|
|
|
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
|
|
|
|
fobj.write("")
|
2019-03-29 02:22:14 +01:00
|
|
|
result = runner.invoke(cli.cli, ['init', "-vv"])
|
2019-03-24 18:46:39 +01:00
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
with pl.Path("setup.cfg").open(mode="r") as fobj:
|
|
|
|
|
default_cfg_text = fobj.read()
|
2019-03-24 18:46:39 +01:00
|
|
|
|
2019-07-09 10:07:26 +02:00
|
|
|
assert "[pycalver]\n" in default_cfg_text
|
|
|
|
|
assert "\ncurrent_version = " in default_cfg_text
|
|
|
|
|
assert "\n[pycalver:file_patterns]\n" in default_cfg_text
|
|
|
|
|
assert "\nsetup.cfg =\n" in default_cfg_text
|
2019-03-24 18:46:39 +01:00
|
|
|
|
2019-03-28 23:22:15 +01:00
|
|
|
result = runner.invoke(cli.cli, ['bump'])
|
2019-03-24 18:46:39 +01:00
|
|
|
|
|
|
|
|
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)
|
2019-07-09 10:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
SETUP_CFG_SEMVER_FIXTURE = """
|
|
|
|
|
[metadata]
|
|
|
|
|
license_file = LICENSE
|
|
|
|
|
|
|
|
|
|
[bdist_wheel]
|
|
|
|
|
universal = 1
|
|
|
|
|
|
|
|
|
|
[pycalver]
|
|
|
|
|
current_version = "0.1.0"
|
|
|
|
|
version_pattern = "{semver}"
|
|
|
|
|
|
|
|
|
|
[pycalver:file_patterns]
|
|
|
|
|
setup.cfg =
|
|
|
|
|
current_version = "{version}"
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bump_semver_warning(runner, caplog):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
|
|
|
|
|
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
|
|
|
|
fobj.write(SETUP_CFG_SEMVER_FIXTURE)
|
|
|
|
|
|
|
|
|
|
_vcs_init("hg", files=["README.md", "setup.cfg"])
|
|
|
|
|
|
|
|
|
|
result = runner.invoke(cli.cli, ['bump', "-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"])
|
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bump_semver_diff(runner, caplog):
|
|
|
|
|
_add_project_files("README.md")
|
|
|
|
|
|
|
|
|
|
with pl.Path("setup.cfg").open(mode="w") as fobj:
|
|
|
|
|
fobj.write(SETUP_CFG_SEMVER_FIXTURE)
|
|
|
|
|
|
|
|
|
|
_vcs_init("hg", files=["README.md", "setup.cfg"])
|
|
|
|
|
|
|
|
|
|
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])
|
|
|
|
|
assert result.exit_code == 0
|
|
|
|
|
assert len(caplog.records) == 0
|
|
|
|
|
|
|
|
|
|
out_lines = set(result.output.splitlines())
|
|
|
|
|
|
|
|
|
|
assert "+++ setup.cfg" in out_lines
|
|
|
|
|
assert "-current_version = \"0.1.0\"" in out_lines
|
|
|
|
|
assert f"+current_version = \"{expected}\"" in out_lines
|