mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
fix tests
This commit is contained in:
parent
fd1b7bd05f
commit
2eb9b516b8
3 changed files with 47 additions and 29 deletions
|
|
@ -180,7 +180,7 @@ def test(
|
||||||
|
|
||||||
|
|
||||||
def _grep_text(pattern: patterns.Pattern, text: str, color: bool) -> typ.Iterable[str]:
|
def _grep_text(pattern: patterns.Pattern, text: str, color: bool) -> typ.Iterable[str]:
|
||||||
all_lines = text.splitlines()
|
all_lines = text.splitlines()
|
||||||
for match in pattern.regexp.finditer(text):
|
for match in pattern.regexp.finditer(text):
|
||||||
match_start, match_end = match.span()
|
match_start, match_end = match.span()
|
||||||
|
|
||||||
|
|
@ -210,10 +210,7 @@ def _grep_text(pattern: patterns.Pattern, text: str, color: bool) -> typ.Iterabl
|
||||||
else:
|
else:
|
||||||
lines[1] = matched_line
|
lines[1] = matched_line
|
||||||
|
|
||||||
prefixed_lines = [
|
prefixed_lines = [f"{lines_offset + i:>4}: {line}" for i, line in enumerate(lines)]
|
||||||
f"{lines_offset + i:>4}: {line}"
|
|
||||||
for i, line in enumerate(lines)
|
|
||||||
]
|
|
||||||
yield "\n".join(prefixed_lines)
|
yield "\n".join(prefixed_lines)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -417,7 +417,7 @@ def parse(ctx: ProjectContext, cfg_missing_ok: bool = False) -> MaybeConfig:
|
||||||
|
|
||||||
|
|
||||||
def init(
|
def init(
|
||||||
project_path: typ.Union[str, pl.Path, None] = ".",
|
project_path : typ.Union[str, pl.Path, None] = ".",
|
||||||
cfg_missing_ok: bool = False,
|
cfg_missing_ok: bool = False,
|
||||||
) -> typ.Tuple[ProjectContext, MaybeConfig]:
|
) -> typ.Tuple[ProjectContext, MaybeConfig]:
|
||||||
ctx = init_project_ctx(project_path)
|
ctx = init_project_ctx(project_path)
|
||||||
|
|
|
||||||
|
|
@ -252,22 +252,10 @@ def test_novcs_nocfg_init(runner, caplog):
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
assert not os.path.exists("pycalver.toml")
|
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
|
# non dry mode
|
||||||
result = runner.invoke(cli, ['init', "-vv"])
|
result = runner.invoke(cli, ['init', "-vv"])
|
||||||
assert result.exit_code == 0
|
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")
|
assert os.path.exists("pycalver.toml")
|
||||||
with pl.Path("pycalver.toml").open(mode="r", encoding="utf-8") as fobj:
|
with pl.Path("pycalver.toml").open(mode="r", encoding="utf-8") as fobj:
|
||||||
cfg_content = fobj.read()
|
cfg_content = fobj.read()
|
||||||
|
|
@ -285,8 +273,8 @@ def test_novcs_nocfg_init(runner, caplog):
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
|
|
||||||
# check logging
|
# check logging
|
||||||
assert len(caplog.records) == 3
|
assert len(caplog.records) == 1
|
||||||
log = caplog.records[2]
|
log = caplog.records[0]
|
||||||
assert log.levelname == 'ERROR'
|
assert log.levelname == 'ERROR'
|
||||||
assert "Configuration already initialized" in log.message
|
assert "Configuration already initialized" in log.message
|
||||||
|
|
||||||
|
|
@ -747,19 +735,52 @@ def test_git_commit_message(runner, caplog):
|
||||||
def test_grep(runner):
|
def test_grep(runner):
|
||||||
_add_project_files("README.md")
|
_add_project_files("README.md")
|
||||||
|
|
||||||
result = runner.invoke(cli, ['grep', r"vYYYY0M.BUILD[-RELEASE]", "README.md"])
|
#
|
||||||
assert result.exit_code == 0
|
|
||||||
assert "Found 1 match for pattern" in result.output
|
|
||||||
|
|
||||||
search_re = r"^\s+2:\s+Hello World v201701\.1002-alpha !"
|
search_re = r"^\s+2:\s+Hello World v201701\.1002-alpha !"
|
||||||
assert re.search(search_re, result.output, flags=re.MULTILINE)
|
|
||||||
|
|
||||||
result = runner.invoke(cli, ['grep', r"\[aka. YYYY0M.BLD[PYTAGNUM] \!\]", "README.md"])
|
result1 = runner.invoke(cli, ['grep', r"vYYYY0M.BUILD[-RELEASE]", "README.md"])
|
||||||
assert result.exit_code == 0
|
assert result1.exit_code == 0
|
||||||
assert "Found 1 match for pattern" in result.output
|
assert "README.md" in result1.output
|
||||||
|
assert re.search(search_re, result1.output, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
result2 = runner.invoke(
|
||||||
|
cli,
|
||||||
|
[
|
||||||
|
'grep',
|
||||||
|
"--version-pattern",
|
||||||
|
r"vYYYY0M.BUILD[-RELEASE]",
|
||||||
|
"{version}",
|
||||||
|
"README.md",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result2.exit_code == 0
|
||||||
|
assert "README.md" in result2.output
|
||||||
|
assert re.search(search_re, result2.output, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
assert result1.output == result2.output
|
||||||
|
|
||||||
search_re = r"^\s+3:\s+\[aka\. 201701\.1002a0 \!\]"
|
search_re = r"^\s+3:\s+\[aka\. 201701\.1002a0 \!\]"
|
||||||
assert re.search(search_re, result.output, flags=re.MULTILINE)
|
|
||||||
|
result3 = runner.invoke(cli, ['grep', r"\[aka. YYYY0M.BLD[PYTAGNUM] \!\]", "README.md"])
|
||||||
|
assert result3.exit_code == 0
|
||||||
|
assert "README.md" in result3.output
|
||||||
|
assert re.search(search_re, result3.output, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
result4 = runner.invoke(
|
||||||
|
cli,
|
||||||
|
[
|
||||||
|
'grep',
|
||||||
|
"--version-pattern",
|
||||||
|
r"vYYYY0M.BUILD[-RELEASE]",
|
||||||
|
r"\[aka. {pep440_version} \!\]",
|
||||||
|
"README.md",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert result4.exit_code == 0
|
||||||
|
assert "README.md" in result4.output
|
||||||
|
assert re.search(search_re, result4.output, flags=re.MULTILINE)
|
||||||
|
|
||||||
|
assert result3.output == result4.output
|
||||||
|
|
||||||
|
|
||||||
SETUP_CFG_MULTIMATCH_FILE_PATTERNS_FIXTURE = r"""
|
SETUP_CFG_MULTIMATCH_FILE_PATTERNS_FIXTURE = r"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue