mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 06:20:08 +01:00
fix tests
This commit is contained in:
parent
0e1a6271a3
commit
946cdaa5ba
13 changed files with 199 additions and 1333 deletions
8
test/fixtures/project_a/pycalver.toml
vendored
8
test/fixtures/project_a/pycalver.toml
vendored
|
|
@ -1,10 +1,16 @@
|
|||
[pycalver]
|
||||
current_version = "{initial_version}"
|
||||
current_version = "v201710.0123-alpha"
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
|
||||
[pycalver.file_patterns]
|
||||
"pycalver.toml" = [
|
||||
'current_version = "{version}"',
|
||||
]
|
||||
|
||||
"README.md" = [
|
||||
"{version}",
|
||||
"{pep440_version}",
|
||||
]
|
||||
|
||||
|
|
|
|||
13
test/fixtures/project_b/setup.cfg
vendored
Normal file
13
test/fixtures/project_b/setup.cfg
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[pycalver]
|
||||
current_version = v201307.0456-beta
|
||||
commit = True
|
||||
tag = True
|
||||
push = True
|
||||
|
||||
[pycalver:file_patterns]
|
||||
setup.cfg =
|
||||
current_version = {version}
|
||||
setup.py =
|
||||
version="{pep440_version}"
|
||||
README.rst =
|
||||
img.shields.io/badge/PyCalVer-{calver}{build}--{release}-blue
|
||||
3
test/fixtures/project_b/setup.py
vendored
Normal file
3
test/fixtures/project_b/setup.py
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import setuptools
|
||||
|
||||
setuptools.setup(name="mylib", license="MIT", version="201307.456b0", keywords="awesome library")
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -2,18 +2,18 @@ import io
|
|||
|
||||
from pycalver import config
|
||||
|
||||
from . import util as test_util
|
||||
from . import util
|
||||
|
||||
|
||||
PYCALVER_TOML_FIXTURE = """
|
||||
[pycalver]
|
||||
current_version = "v201808.0123-dev"
|
||||
current_version = "v201808.0123-alpha"
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
|
||||
[pycalver.file_patterns]
|
||||
"setup.py" = [
|
||||
"README.md" = [
|
||||
"{version}",
|
||||
"{pep440_version}",
|
||||
]
|
||||
|
|
@ -25,7 +25,7 @@ push = true
|
|||
|
||||
SETUP_CFG_FIXTURE = """
|
||||
[pycalver]
|
||||
current_version = "v201808.0456-dev"
|
||||
current_version = "v201808.0456-beta"
|
||||
commit = True
|
||||
tag = True
|
||||
push = True
|
||||
|
|
@ -52,13 +52,13 @@ def test_parse_toml():
|
|||
raw_cfg = config._parse_toml(buf)
|
||||
cfg = config._parse_config(raw_cfg)
|
||||
|
||||
assert cfg.current_version == "v201808.0123-dev"
|
||||
assert cfg.current_version == "v201808.0123-alpha"
|
||||
assert cfg.commit is True
|
||||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert "pycalver.toml" in cfg.file_patterns
|
||||
assert cfg.file_patterns["setup.py" ] == ["{version}", "{pep440_version}"]
|
||||
assert cfg.file_patterns["README.md" ] == ["{version}", "{pep440_version}"]
|
||||
assert cfg.file_patterns["pycalver.toml"] == ['current_version = "{version}"']
|
||||
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ def test_parse_cfg():
|
|||
raw_cfg = config._parse_cfg(buf)
|
||||
cfg = config._parse_config(raw_cfg)
|
||||
|
||||
assert cfg.current_version == "v201808.0456-dev"
|
||||
assert cfg.current_version == "v201808.0456-beta"
|
||||
assert cfg.commit is True
|
||||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
|
@ -79,76 +79,144 @@ def test_parse_cfg():
|
|||
|
||||
|
||||
def test_parse_default_toml():
|
||||
project_path = test_util.FIXTURES_DIR / "project_a"
|
||||
config_path = test_util.FIXTURES_DIR / "project_a" / "pycalver.toml"
|
||||
project_path = util.FIXTURES_DIR / "project_a"
|
||||
|
||||
ctx = config.ProjectContext(project_path, config_path, "toml", None)
|
||||
buf = mk_buf(config.default_config(ctx))
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
default_toml = config.default_config(ctx)
|
||||
|
||||
buf = mk_buf(default_toml)
|
||||
raw_cfg = config._parse_toml(buf)
|
||||
cfg = config._parse_config(raw_cfg)
|
||||
|
||||
assert cfg
|
||||
assert cfg.current_version.endswith(".0001-dev")
|
||||
assert cfg.commit is True
|
||||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert "setup.py" in cfg.file_patterns
|
||||
assert "README.md" in cfg.file_patterns
|
||||
assert "pycalver.toml" in cfg.file_patterns
|
||||
|
||||
|
||||
def test_parse_default_cfg():
|
||||
project_path = test_util.FIXTURES_DIR / "project_a"
|
||||
config_path = test_util.FIXTURES_DIR / "project_a" / "setup.cfg"
|
||||
project_path = util.FIXTURES_DIR / "project_b"
|
||||
|
||||
ctx = config.ProjectContext(project_path, config_path, "cfg", None)
|
||||
buf = mk_buf(config.default_config(ctx))
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
default_cfg = config.default_config(ctx)
|
||||
|
||||
buf = mk_buf(default_cfg)
|
||||
raw_cfg = config._parse_cfg(buf)
|
||||
cfg = config._parse_config(raw_cfg)
|
||||
|
||||
assert cfg
|
||||
assert cfg.current_version.endswith(".0001-dev")
|
||||
|
||||
|
||||
def test_parse_project_toml():
|
||||
project_path = util.FIXTURES_DIR / "project_a"
|
||||
config_path = util.FIXTURES_DIR / "project_a" / "pycalver.toml"
|
||||
|
||||
with config_path.open() as fh:
|
||||
config_data = fh.read()
|
||||
|
||||
assert "v201710.0123-alpha" in config_data
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, "toml", None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
assert cfg
|
||||
|
||||
assert cfg.current_version == "v201710.0123-alpha"
|
||||
assert cfg.commit is True
|
||||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert "setup.py" in cfg.file_patterns
|
||||
assert "README.md" in cfg.file_patterns
|
||||
assert "setup.cfg" in cfg.file_patterns
|
||||
assert set(cfg.file_patterns.keys()) == {"pycalver.toml", "README.md"}
|
||||
|
||||
|
||||
def test_parse_project_cfg():
|
||||
project_path = util.FIXTURES_DIR / "project_b"
|
||||
config_path = util.FIXTURES_DIR / "project_b" / "setup.cfg"
|
||||
|
||||
with config_path.open() as fh:
|
||||
config_data = fh.read()
|
||||
|
||||
assert "v201307.0456-beta" in config_data
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, config_path, 'cfg', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
assert cfg
|
||||
assert cfg.current_version == "v201307.0456-beta"
|
||||
assert cfg.commit is True
|
||||
assert cfg.tag is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert set(cfg.file_patterns.keys()) == {"setup.py", "README.rst", "setup.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)
|
||||
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, 'toml', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
assert cfg
|
||||
assert cfg.current_version == "v201808.0123-alpha"
|
||||
assert cfg.tag is True
|
||||
assert cfg.commit is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert cfg.file_patterns == {
|
||||
"README.md" : ["{version}", "{pep440_version}"],
|
||||
"pycalver.toml": ['current_version = "{version}"'],
|
||||
}
|
||||
|
||||
|
||||
def test_parse_cfg_file(tmpdir):
|
||||
setup_path = tmpdir.mkdir("minimal").join("setup.cfg")
|
||||
setup_path.write(SETUP_CFG_FIXTURE)
|
||||
project_path = tmpdir.mkdir("minimal")
|
||||
setup_cfg = project_path.join("setup.cfg")
|
||||
setup_cfg.write(SETUP_CFG_FIXTURE)
|
||||
|
||||
cfg = config.parse(str(setup_path))
|
||||
ctx = config.init_project_ctx(project_path)
|
||||
assert ctx == config.ProjectContext(project_path, setup_cfg, 'cfg', None)
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
|
||||
assert cfg
|
||||
assert cfg.current_version == "v201808.0001-dev"
|
||||
assert not cfg.tag
|
||||
assert not cfg.commit
|
||||
assert cfg.current_version == "v201808.0456-beta"
|
||||
assert cfg.tag is True
|
||||
assert cfg.commit is True
|
||||
assert cfg.push is True
|
||||
|
||||
assert cfg.file_patterns == {"setup.cfg": ["current_version = {version}"]}
|
||||
assert cfg.file_patterns == {
|
||||
"setup.py" : ["{version}", "{pep440_version}"],
|
||||
"setup.cfg": ['current_version = "{version}"'],
|
||||
}
|
||||
|
||||
|
||||
def test_parse_config_missing(tmpdir):
|
||||
cfg = config.parse("does_not_exist/setup.cfg")
|
||||
ctx = config.init_project_ctx("does_not_exist/setup.cfg")
|
||||
assert ctx
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg is None
|
||||
|
||||
setup_path = tmpdir.mkdir("fail").join("setup.cfg")
|
||||
ctx = config.init_project_ctx(setup_path)
|
||||
assert ctx
|
||||
|
||||
cfg = config.parse(str(setup_path))
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg is None
|
||||
|
||||
|
||||
def test_parse_empty_config(tmpdir):
|
||||
setup_path = tmpdir.mkdir("fail").join("setup.cfg")
|
||||
setup_path.write("")
|
||||
ctx = config.init_project_ctx(setup_path)
|
||||
assert ctx
|
||||
|
||||
cfg = config.parse(str(setup_path))
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg is None
|
||||
|
||||
|
||||
|
|
@ -164,7 +232,10 @@ def test_parse_missing_version(tmpdir):
|
|||
)
|
||||
)
|
||||
|
||||
cfg = config.parse(str(setup_path))
|
||||
ctx = config.init_project_ctx(setup_path)
|
||||
assert ctx
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg is None
|
||||
|
||||
|
||||
|
|
@ -172,5 +243,8 @@ 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")))
|
||||
|
||||
cfg = config.parse(str(setup_path))
|
||||
ctx = config.init_project_ctx(setup_path)
|
||||
assert ctx
|
||||
|
||||
cfg = config.parse(ctx)
|
||||
assert cfg is None
|
||||
|
|
|
|||
|
|
@ -169,21 +169,25 @@ def test_badge_parse_patterns():
|
|||
assert matches[1].match == ":alt: CalVer v201809.0002-beta"
|
||||
|
||||
|
||||
def test_parse_error():
|
||||
def test_parse_error_empty():
|
||||
try:
|
||||
parse.VersionInfo.parse("")
|
||||
parse.parse_version_info("")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
||||
|
||||
def test_parse_error_noprefix():
|
||||
try:
|
||||
parse.VersionInfo.parse("201809.0002")
|
||||
parse.parse_version_info("201809.0002")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
||||
|
||||
def test_parse_error_nopadding():
|
||||
try:
|
||||
parse.VersionInfo.parse("v201809.2b0")
|
||||
parse.parse_version_info("v201809.2b0")
|
||||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue