update defaults and tests

This commit is contained in:
Manuel Barkhau 2020-10-15 19:54:26 +00:00
parent 5f66a42c17
commit a3499c19a6
17 changed files with 400 additions and 306 deletions

View file

@ -15,7 +15,8 @@ from pycalver2 import config
PYCALVER_TOML_FIXTURE_1 = """
[pycalver]
current_version = "v201808.0123-alpha"
current_version = "v2020.1003-alpha"
version_pattern = "vYYYY.BUILD[-TAG]"
commit = true
tag = true
push = true
@ -35,6 +36,9 @@ PYCALVER_TOML_FIXTURE_2 = """
[pycalver]
current_version = "1.2.3"
version_pattern = "{semver}"
commit = false
tag = false
push = false
[pycalver.file_patterns]
"README.md" = [
@ -46,15 +50,34 @@ version_pattern = "{semver}"
]
"""
CALVER_TOML_FIXTURE_3 = """
[calver]
current_version = "v201808.0123-alpha"
version_pattern = "vYYYY0M.BUILD[-TAG]"
commit = true
tag = true
push = true
[calver.file_patterns]
"README.md" = [
"{version}",
"{pep440_version}",
]
"calver.toml" = [
'current_version = "{version}"',
]
"""
SETUP_CFG_FIXTURE = """
[pycalver]
[calver]
current_version = "v201808.0456-beta"
version_pattern = "vYYYY0M.BUILD[-TAG]"
commit = True
tag = True
push = True
[pycalver:file_patterns]
[calver:file_patterns]
setup.py =
{version}
{pep440_version}
@ -64,7 +87,7 @@ setup.cfg =
NEW_PATTERN_CFG_FIXTURE = """
[pycalver]
[calver]
current_version = "v201808.1456-beta"
version_pattern = "vYYYY0M.BUILD[-TAG]"
commit_message = "bump version to {new_version}"
@ -72,7 +95,7 @@ commit = True
tag = True
push = True
[pycalver:file_patterns]
[calver:file_patterns]
setup.py =
{version}
{pep440_version}
@ -103,17 +126,18 @@ def test_parse_toml_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.current_version == "v2020.1003-alpha"
assert cfg.version_pattern == "vYYYY.BUILD[-TAG]"
assert cfg.commit is True
assert cfg.tag is True
assert cfg.push is True
assert "pycalver.toml" in cfg.file_patterns
files = set(cfg.file_patterns)
assert "pycalver.toml" in files
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}"']
raw_patterns_by_path = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_path["README.md" ] == ["vYYYY.BUILD[-TAG]", "YYYY.BLD[PYTAGNUM]"]
assert raw_patterns_by_path["pycalver.toml"] == ['current_version = "vYYYY.BUILD[-TAG]"']
def test_parse_toml_2():
@ -130,9 +154,29 @@ def test_parse_toml_2():
assert "pycalver.toml" in cfg.file_patterns
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}"']
raw_patterns_by_path = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_path["README.md" ] == ["{semver}", "{semver}"]
assert raw_patterns_by_path["pycalver.toml"] == ['current_version = "{semver}"']
def test_parse_toml_3():
buf = mk_buf(CALVER_TOML_FIXTURE_3)
raw_cfg = config._parse_toml(buf)
cfg = config._parse_config(raw_cfg)
assert cfg.current_version == "v201808.0123-alpha"
assert cfg.version_pattern == "vYYYY0M.BUILD[-TAG]"
assert cfg.commit is True
assert cfg.tag is True
assert cfg.push is True
files = set(cfg.file_patterns)
assert "calver.toml" in files
raw_patterns_by_path = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_path["README.md" ] == ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"]
assert raw_patterns_by_path["calver.toml"] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
def test_parse_v1_cfg():
@ -146,11 +190,12 @@ def test_parse_v1_cfg():
assert cfg.tag is True
assert cfg.push is True
assert "setup.cfg" in cfg.file_patterns
files = set(cfg.file_patterns)
assert "setup.cfg" in files
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}"']
raw_patterns_by_path = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_path["setup.py" ] == ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"]
assert raw_patterns_by_path["setup.cfg"] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
def test_parse_v2_cfg():
@ -164,16 +209,14 @@ def test_parse_v2_cfg():
assert cfg.tag is True
assert cfg.push is True
assert "setup.py" in cfg.file_patterns
assert "setup.cfg" in cfg.file_patterns
files = set(cfg.file_patterns)
assert "setup.py" in files
assert "setup.cfg" in files
raw_patterns_by_filepath = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_filepath["setup.py"] == [
"vYYYY0M.BUILD[-TAG]",
"YYYY0M.BLD[PYTAGNUM]",
]
assert raw_patterns_by_filepath["setup.cfg"] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
assert raw_patterns_by_filepath["src/project/*.py"] == ["Copyright (c) 2018-YYYY"]
raw_patterns_by_path = _parse_raw_patterns_by_filepath(cfg)
assert raw_patterns_by_path["setup.py"] == ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"]
assert raw_patterns_by_path["setup.cfg"] == ['current_version = "vYYYY0M.BUILD[-TAG]"']
assert raw_patterns_by_path["src/project/*.py"] == ["Copyright (c) 2018-YYYY"]
def test_parse_default_toml():
@ -204,8 +247,8 @@ 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"
config_rel_path = "pycalver.toml"
config_path = util.FIXTURES_DIR / "project_a" / "calver.toml"
config_rel_path = "calver.toml"
with config_path.open() as fobj:
config_data = fobj.read()
@ -224,7 +267,8 @@ def test_parse_project_toml():
assert cfg.tag is True
assert cfg.push is True
assert set(cfg.file_patterns.keys()) == {"pycalver.toml", "README.md"}
files = set(cfg.file_patterns.keys())
assert files == {"calver.toml", "README.md"}
def test_parse_project_cfg():
@ -258,25 +302,26 @@ 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_1)
setup_cfg_rel_path = "pycalver.toml"
cfg_file = project_path.join("pycalver.toml")
cfg_file.write(PYCALVER_TOML_FIXTURE_1)
cfg_file_rel_path = "pycalver.toml"
ctx = config.init_project_ctx(project_path)
assert ctx == config.ProjectContext(project_path, setup_cfg, setup_cfg_rel_path, 'toml', None)
assert ctx == config.ProjectContext(project_path, cfg_file, cfg_file_rel_path, 'toml', None)
cfg = config.parse(ctx)
assert cfg
assert cfg.current_version == "v201808.0123-alpha"
assert cfg.current_version == "v2020.1003-alpha"
assert cfg.version_pattern == "vYYYY.BUILD[-TAG]"
assert cfg.tag is True
assert cfg.commit is True
assert cfg.push is True
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}"'],
"README.md" : ["vYYYY.BUILD[-TAG]", "YYYY.BLD[PYTAGNUM]"],
"pycalver.toml": ['current_version = "vYYYY.BUILD[-TAG]"'],
}
@ -294,6 +339,8 @@ def test_parse_default_pattern():
assert cfg
assert cfg.current_version == "v2017q1.54321"
# assert cfg.version_pattern == "vYYYYqQ.BUILD"
assert cfg.version_pattern == "v{year}q{quarter}.{build_no}"
assert cfg.commit is True
assert cfg.tag is True
assert cfg.push is True
@ -317,14 +364,15 @@ def test_parse_cfg_file(tmpdir):
assert cfg
assert cfg.current_version == "v201808.0456-beta"
assert cfg.version_pattern == "vYYYY0M.BUILD[-TAG]"
assert cfg.tag is True
assert cfg.commit is True
assert cfg.push is True
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}"'],
"setup.py" : ["vYYYY0M.BUILD[-TAG]", "YYYY0M.BLD[PYTAGNUM]"],
"setup.cfg": ['current_version = "vYYYY0M.BUILD[-TAG]"'],
}
@ -358,7 +406,7 @@ def test_parse_missing_version(tmpdir):
setup_path.write(
"\n".join(
(
"[pycalver]",
"[calver]",
# f"current_version = v201808.1001-dev",
"commit = False",
)
@ -374,7 +422,7 @@ def test_parse_missing_version(tmpdir):
def test_parse_invalid_version(tmpdir):
setup_path = tmpdir.mkdir("fail").join("setup.cfg")
setup_path.write("\n".join(("[pycalver]", "current_version = 0.1.0", "commit = False")))
setup_path.write("\n".join(("[calver]", "current_version = 0.1.0", "commit = False")))
ctx = config.init_project_ctx(setup_path)
assert ctx