more coverage

This commit is contained in:
Manuel Barkhau 2019-01-07 17:30:02 +01:00
parent 4598286f12
commit df492a20d6
10 changed files with 128 additions and 27 deletions

View file

@ -128,6 +128,15 @@ def test_incr_semver(runner):
assert f"Version: {new_version}\n" in result.output
def test_incr_semver_invalid(runner, caplog):
result = runner.invoke(pycalver.cli, ['test', "--verbose", "--patch", "0.1.1"])
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
def test_incr_to_beta(runner):
old_version = "v201701.0999-alpha"
initial_version = config._initial_version()
@ -148,7 +157,7 @@ def test_incr_to_final(runner):
assert f"Version: {new_version}\n" in result.output
def test_incr_invalid(runner, caplog):
def test_incr_invalid(runner):
old_version = "v201701.0999-alpha"
result = runner.invoke(pycalver.cli, ['test', old_version, "--verbose", "--release", "alfa"])
@ -183,11 +192,35 @@ def test_nocfg(runner, caplog):
)
def test_novcs_nocfg_init(runner):
def test_novcs_nocfg_init(runner, caplog, capsys):
_add_project_files("README.md")
# dry mode test
result = runner.invoke(pycalver.cli, ['init', "--verbose", "--dry"])
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
# print("moep")
# captured = capsys.readouterr()
# assert not captured.err
# assert "Would have written to pycalver.toml:" in captured.out
# non dry mode
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
assert result.exit_code == 0
# 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")
with io.open("pycalver.toml", mode="r", encoding="utf-8") as fh:
cfg_content = fh.read()
@ -200,6 +233,15 @@ def test_novcs_nocfg_init(runner):
assert f"Current Version: {config._initial_version()}\n" in result.output
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
result = runner.invoke(pycalver.cli, ['init', "--verbose"])
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
def test_novcs_setupcfg_init(runner):
_add_project_files("README.md", "setup.cfg")

View file

@ -5,7 +5,7 @@ from pycalver import config
from . import util
PYCALVER_TOML_FIXTURE = """
PYCALVER_TOML_FIXTURE_1 = """
[pycalver]
current_version = "v201808.0123-alpha"
commit = true
@ -23,6 +23,22 @@ push = true
"""
PYCALVER_TOML_FIXTURE_2 = """
[pycalver]
current_version = "1.2.3"
version_pattern = "{semver}"
[pycalver.file_patterns]
"README.md" = [
"{version}",
"{pep440_version}",
]
"pycalver.toml" = [
'current_version = "{version}"',
]
"""
SETUP_CFG_FIXTURE = """
[pycalver]
current_version = "v201808.0456-beta"
@ -46,13 +62,14 @@ def mk_buf(text):
return buf
def test_parse_toml():
buf = mk_buf(PYCALVER_TOML_FIXTURE)
def test_parse_toml_1():
buf = mk_buf(PYCALVER_TOML_FIXTURE_1)
raw_cfg = config._parse_toml(buf)
cfg = config._parse_config(raw_cfg)
assert cfg.current_version == "v201808.0123-alpha"
assert cfg.version_pattern == "{pycalver}"
assert cfg.commit is True
assert cfg.tag is True
assert cfg.push is True
@ -62,6 +79,23 @@ def test_parse_toml():
assert cfg.file_patterns["pycalver.toml"] == ['current_version = "{pycalver}"']
def test_parse_toml_2():
buf = mk_buf(PYCALVER_TOML_FIXTURE_2)
raw_cfg = config._parse_toml(buf)
cfg = config._parse_config(raw_cfg)
assert cfg.current_version == "1.2.3"
assert cfg.version_pattern == "{semver}"
assert cfg.commit is False
assert cfg.tag is False
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}"']
def test_parse_cfg():
buf = mk_buf(SETUP_CFG_FIXTURE)
@ -154,7 +188,7 @@ def test_parse_project_cfg():
def test_parse_toml_file(tmpdir):
project_path = tmpdir.mkdir("minimal")
setup_cfg = project_path.join("pycalver.toml")
setup_cfg.write(PYCALVER_TOML_FIXTURE)
setup_cfg.write(PYCALVER_TOML_FIXTURE_1)
ctx = config.init_project_ctx(project_path)
assert ctx == config.ProjectContext(project_path, setup_cfg, 'toml', None)