mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
update tests
This commit is contained in:
parent
3234fb97f9
commit
0095f974da
7 changed files with 1391 additions and 32 deletions
3
test/fixtures/project_a/README.md
vendored
Normal file
3
test/fixtures/project_a/README.md
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# PyCalVer README Fixture
|
||||||
|
|
||||||
|
Current Version: v201612.0123-alpha
|
||||||
10
test/fixtures/project_a/pycalver.toml
vendored
Normal file
10
test/fixtures/project_a/pycalver.toml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[pycalver]
|
||||||
|
current_version = "{initial_version}"
|
||||||
|
commit = true
|
||||||
|
tag = true
|
||||||
|
|
||||||
|
[pycalver.file_patterns]
|
||||||
|
"README.md" = [
|
||||||
|
"{version}",
|
||||||
|
"{pep440_version}",
|
||||||
|
]
|
||||||
0
test/fixtures/project_a/setup.py
vendored
Normal file
0
test/fixtures/project_a/setup.py
vendored
Normal file
1200
test/test_config.html
Normal file
1200
test/test_config.html
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -2,45 +2,127 @@ import io
|
||||||
|
|
||||||
from pycalver import config
|
from pycalver import config
|
||||||
|
|
||||||
|
from . import util as test_util
|
||||||
|
|
||||||
def test_parse_default_config():
|
|
||||||
|
PYCALVER_TOML_FIXTURE = """
|
||||||
|
[pycalver]
|
||||||
|
current_version = "v201808.0123-dev"
|
||||||
|
commit = true
|
||||||
|
tag = true
|
||||||
|
push = true
|
||||||
|
|
||||||
|
[pycalver.file_patterns]
|
||||||
|
"setup.py" = [
|
||||||
|
"{version}",
|
||||||
|
"{pep440_version}",
|
||||||
|
]
|
||||||
|
"pycalver.toml" = [
|
||||||
|
'current_version = "{version}"',
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
SETUP_CFG_FIXTURE = """
|
||||||
|
[pycalver]
|
||||||
|
current_version = "v201808.0456-dev"
|
||||||
|
commit = True
|
||||||
|
tag = True
|
||||||
|
push = True
|
||||||
|
|
||||||
|
[pycalver:file_patterns]
|
||||||
|
setup.py =
|
||||||
|
{version}
|
||||||
|
{pep440_version}
|
||||||
|
setup.cfg =
|
||||||
|
current_version = "{version}"
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def mk_buf(text):
|
||||||
buf = io.StringIO()
|
buf = io.StringIO()
|
||||||
for line in config.default_config_lines():
|
buf.write(text)
|
||||||
buf.write(line + "\n")
|
|
||||||
|
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
cfg = config._parse_buffer(buf)
|
return buf
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_toml():
|
||||||
|
buf = mk_buf(PYCALVER_TOML_FIXTURE)
|
||||||
|
|
||||||
|
raw_cfg = config._parse_toml(buf)
|
||||||
|
cfg = config._parse_config(raw_cfg)
|
||||||
|
|
||||||
|
assert cfg.current_version == "v201808.0123-dev"
|
||||||
|
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["pycalver.toml"] == ['current_version = "{version}"']
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_cfg():
|
||||||
|
buf = mk_buf(SETUP_CFG_FIXTURE)
|
||||||
|
|
||||||
|
raw_cfg = config._parse_cfg(buf)
|
||||||
|
cfg = config._parse_config(raw_cfg)
|
||||||
|
|
||||||
|
assert cfg.current_version == "v201808.0456-dev"
|
||||||
|
assert cfg.commit is True
|
||||||
|
assert cfg.tag is True
|
||||||
|
assert cfg.push is True
|
||||||
|
|
||||||
|
assert "setup.cfg" in cfg.file_patterns
|
||||||
|
assert cfg.file_patterns["setup.py" ] == ["{version}", "{pep440_version}"]
|
||||||
|
assert cfg.file_patterns["setup.cfg"] == ['current_version = "{version}"']
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_default_toml():
|
||||||
|
project_path = test_util.FIXTURES_DIR / "project_a"
|
||||||
|
config_path = test_util.FIXTURES_DIR / "project_a" / "pycalver.toml"
|
||||||
|
|
||||||
|
ctx = config.ProjectContext(project_path, config_path, "toml", None)
|
||||||
|
buf = mk_buf(config.default_config(ctx))
|
||||||
|
|
||||||
|
raw_cfg = config._parse_toml(buf)
|
||||||
|
cfg = config._parse_config(raw_cfg)
|
||||||
|
|
||||||
assert cfg
|
assert cfg
|
||||||
assert cfg.current_version.endswith(".0001-dev")
|
assert cfg.current_version.endswith(".0001-dev")
|
||||||
assert cfg.tag
|
assert cfg.commit is True
|
||||||
assert cfg.commit
|
assert cfg.tag is True
|
||||||
|
assert cfg.push is True
|
||||||
|
|
||||||
# NOTE (mb 2018-11-10): These refer to the actual files
|
|
||||||
# of the pycalver project. A different project would
|
|
||||||
# have README.rst for example. To fully test this
|
|
||||||
# we might create temporary projects.
|
|
||||||
assert "setup.py" in cfg.file_patterns
|
assert "setup.py" in cfg.file_patterns
|
||||||
assert "setup.cfg" in cfg.file_patterns
|
|
||||||
assert "README.md" in cfg.file_patterns
|
assert "README.md" in cfg.file_patterns
|
||||||
|
assert "pycalver.toml" in cfg.file_patterns
|
||||||
|
|
||||||
|
|
||||||
def test_parse(tmpdir):
|
def test_parse_default_cfg():
|
||||||
|
project_path = test_util.FIXTURES_DIR / "project_a"
|
||||||
|
config_path = test_util.FIXTURES_DIR / "project_a" / "setup.cfg"
|
||||||
|
|
||||||
|
ctx = config.ProjectContext(project_path, config_path, "cfg", None)
|
||||||
|
buf = mk_buf(config.default_config(ctx))
|
||||||
|
|
||||||
|
raw_cfg = config._parse_cfg(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 "setup.cfg" in cfg.file_patterns
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_cfg_file(tmpdir):
|
||||||
setup_path = tmpdir.mkdir("minimal").join("setup.cfg")
|
setup_path = tmpdir.mkdir("minimal").join("setup.cfg")
|
||||||
setup_path.write(
|
setup_path.write(SETUP_CFG_FIXTURE)
|
||||||
"\n".join(
|
|
||||||
(
|
|
||||||
"[pycalver]",
|
|
||||||
"current_version = v201808.0001-dev",
|
|
||||||
"commit = False",
|
|
||||||
"tag = False",
|
|
||||||
"",
|
|
||||||
"[pycalver:file:setup.cfg]",
|
|
||||||
"patterns = ",
|
|
||||||
" current_version = {version}",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
cfg = config.parse(str(setup_path))
|
cfg = config.parse(str(setup_path))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ def test_re_pattern_parts():
|
||||||
|
|
||||||
def test_parse_version_info():
|
def test_parse_version_info():
|
||||||
version_str = "v201712.0001-alpha"
|
version_str = "v201712.0001-alpha"
|
||||||
version_nfo = parse.VersionInfo.parse(version_str)
|
version_nfo = parse.parse_version_info(version_str)
|
||||||
|
|
||||||
assert version_nfo.pep440_version == "201712.1a0"
|
assert version_nfo.pep440_version == "201712.1a0"
|
||||||
assert version_nfo.version == "v201712.0001-alpha"
|
assert version_nfo.version == "v201712.0001-alpha"
|
||||||
|
|
@ -86,7 +86,7 @@ def test_parse_version_info():
|
||||||
assert version_nfo.release == "-alpha"
|
assert version_nfo.release == "-alpha"
|
||||||
|
|
||||||
version_str = "v201712.0001"
|
version_str = "v201712.0001"
|
||||||
version_nfo = parse.VersionInfo.parse(version_str)
|
version_nfo = parse.parse_version_info(version_str)
|
||||||
|
|
||||||
assert version_nfo.pep440_version == "201712.1"
|
assert version_nfo.pep440_version == "201712.1"
|
||||||
assert version_nfo.version == "v201712.0001"
|
assert version_nfo.version == "v201712.0001"
|
||||||
|
|
@ -111,7 +111,7 @@ def test_default_parse_patterns():
|
||||||
lines = SETUP_PY_FIXTURE.splitlines()
|
lines = SETUP_PY_FIXTURE.splitlines()
|
||||||
patterns = ["{version}", "{pep440_version}"]
|
patterns = ["{version}", "{pep440_version}"]
|
||||||
|
|
||||||
matches = list(parse.PatternMatch.iter_matches(lines, patterns))
|
matches = list(parse.iter_matches(lines, patterns))
|
||||||
assert len(matches) == 2
|
assert len(matches) == 2
|
||||||
|
|
||||||
assert matches[0].lineno == 3
|
assert matches[0].lineno == 3
|
||||||
|
|
@ -129,7 +129,7 @@ def test_explicit_parse_patterns():
|
||||||
|
|
||||||
patterns = ["__version__ = '{version}'", "version='{pep440_version}'"]
|
patterns = ["__version__ = '{version}'", "version='{pep440_version}'"]
|
||||||
|
|
||||||
matches = list(parse.PatternMatch.iter_matches(lines, patterns))
|
matches = list(parse.iter_matches(lines, patterns))
|
||||||
assert len(matches) == 2
|
assert len(matches) == 2
|
||||||
|
|
||||||
assert matches[0].lineno == 3
|
assert matches[0].lineno == 3
|
||||||
|
|
@ -156,7 +156,7 @@ def test_badge_parse_patterns():
|
||||||
|
|
||||||
patterns = ["badge/CalVer-{calver}{build}-{release}-blue.svg", ":alt: CalVer {version}"]
|
patterns = ["badge/CalVer-{calver}{build}-{release}-blue.svg", ":alt: CalVer {version}"]
|
||||||
|
|
||||||
matches = list(parse.PatternMatch.iter_matches(lines, patterns))
|
matches = list(parse.iter_matches(lines, patterns))
|
||||||
assert len(matches) == 2
|
assert len(matches) == 2
|
||||||
|
|
||||||
assert matches[0].lineno == 3
|
assert matches[0].lineno == 3
|
||||||
|
|
|
||||||
64
test/util.py
Normal file
64
test/util.py
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import shlex
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import pathlib2 as pl
|
||||||
|
import subprocess as sp
|
||||||
|
|
||||||
|
|
||||||
|
class Shell:
|
||||||
|
def __init__(self, cwd):
|
||||||
|
self.cwd = cwd
|
||||||
|
|
||||||
|
def __call__(self, cmd):
|
||||||
|
if isinstance(cmd, str):
|
||||||
|
cmd_parts = shlex.split(cmd)
|
||||||
|
else:
|
||||||
|
cmd_parts = cmd
|
||||||
|
output = sp.check_output(cmd_parts, cwd=self.cwd)
|
||||||
|
return output.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
_MODULE_PATH = pl.Path(__file__)
|
||||||
|
FIXTURES_DIR = _MODULE_PATH.parent / "fixtures"
|
||||||
|
|
||||||
|
|
||||||
|
class Project:
|
||||||
|
def __init__(self, project_prefix="a"):
|
||||||
|
if not project_prefix.endswith("_"):
|
||||||
|
project_prefix += "_"
|
||||||
|
|
||||||
|
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
|
||||||
|
self.tmpdir = tmpdir
|
||||||
|
|
||||||
|
_project_dir = tmpdir / "pycalver_project"
|
||||||
|
_project_dir.mkdir()
|
||||||
|
|
||||||
|
for fpath in FIXTURES_DIR.glob(project_prefix + "*"):
|
||||||
|
fname = fpath.name[len(project_prefix) :]
|
||||||
|
shutil.copy(fpath, _project_dir / fname)
|
||||||
|
|
||||||
|
self.dir = _project_dir
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *exc):
|
||||||
|
shutil.rmtree(str(self.tmpdir))
|
||||||
|
return False
|
||||||
|
|
||||||
|
def sh(self, cmd):
|
||||||
|
shell = Shell(str(self.dir))
|
||||||
|
return shell(cmd)
|
||||||
|
|
||||||
|
def git_init(self):
|
||||||
|
self.sh("git init")
|
||||||
|
self.sh("git add pycalver.toml")
|
||||||
|
self.sh("git add README.md")
|
||||||
|
self.sh("git commit -m 'initial commit'")
|
||||||
|
|
||||||
|
def hg_init(self):
|
||||||
|
self.sh = Shell(str(self.dir))
|
||||||
|
self.sh("hg init")
|
||||||
|
self.sh("hg add pycalver.toml")
|
||||||
|
self.sh("hg add README.md")
|
||||||
|
self.sh("hg commit -m 'initial commit'")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue