misc linter updates

This commit is contained in:
Manuel Barkhau 2020-07-19 14:38:57 +00:00
parent f1e17562b8
commit 0439ddf7d5
14 changed files with 158 additions and 131 deletions

View file

@ -1,3 +1,6 @@
# pylint:disable=redefined-outer-name ; pytest fixtures
# pylint:disable=protected-access ; allowed for test code
import os
import time
import shutil
@ -36,7 +39,7 @@ ENV = {
}
def sh(*cmd):
def shell(*cmd):
return sp.check_output(cmd, env=ENV)
@ -157,8 +160,8 @@ def test_incr_invalid(runner):
def _add_project_files(*files):
if "README.md" in files:
with pl.Path("README.md").open(mode="wt", encoding="utf-8") as fh:
fh.write(
with pl.Path("README.md").open(mode="wt", encoding="utf-8") as fobj:
fobj.write(
"""
Hello World v201701.0002-alpha !
aka. 201701.2a0 !
@ -166,16 +169,16 @@ def _add_project_files(*files):
)
if "setup.cfg" in files:
with pl.Path("setup.cfg").open(mode="wt", encoding="utf-8") as fh:
fh.write(SETUP_CFG_FIXTURE)
with pl.Path("setup.cfg").open(mode="wt", encoding="utf-8") as fobj:
fobj.write(SETUP_CFG_FIXTURE)
if "pycalver.toml" in files:
with pl.Path("pycalver.toml").open(mode="wt", encoding="utf-8") as fh:
fh.write(PYCALVER_TOML_FIXTURE)
with pl.Path("pycalver.toml").open(mode="wt", encoding="utf-8") as fobj:
fobj.write(PYCALVER_TOML_FIXTURE)
if "pyproject.toml" in files:
with pl.Path("pyproject.toml").open(mode="wt", encoding="utf-8") as fh:
fh.write(PYPROJECT_TOML_FIXTURE)
with pl.Path("pyproject.toml").open(mode="wt", encoding="utf-8") as fobj:
fobj.write(PYPROJECT_TOML_FIXTURE)
def test_nocfg(runner, caplog):
@ -212,8 +215,8 @@ def test_novcs_nocfg_init(runner, caplog):
assert "File not found" in log.message
assert os.path.exists("pycalver.toml")
with pl.Path("pycalver.toml").open(mode="r", encoding="utf-8") as fh:
cfg_content = fh.read()
with pl.Path("pycalver.toml").open(mode="r", encoding="utf-8") as fobj:
cfg_content = fobj.read()
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
assert base_str in cfg_content
@ -234,13 +237,13 @@ def test_novcs_nocfg_init(runner, caplog):
assert "Configuration already initialized" in log.message
def test_novcs_setupcfg_init(runner, caplog):
def test_novcs_setupcfg_init(runner):
_add_project_files("README.md", "setup.cfg")
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
with pl.Path("setup.cfg").open(mode="r", encoding="utf-8") as fh:
cfg_content = fh.read()
with pl.Path("setup.cfg").open(mode="r", encoding="utf-8") as fobj:
cfg_content = fobj.read()
base_str = config.DEFAULT_CONFIGPARSER_BASE_TMPL.format(
initial_version=config._initial_version()
@ -259,8 +262,8 @@ def test_novcs_pyproject_init(runner):
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
with pl.Path("pyproject.toml").open(mode="r", encoding="utf-8") as fh:
cfg_content = fh.read()
with pl.Path("pyproject.toml").open(mode="r", encoding="utf-8") as fobj:
cfg_content = fobj.read()
base_str = config.DEFAULT_TOML_BASE_TMPL.format(initial_version=config._initial_version())
assert base_str in cfg_content
@ -272,16 +275,16 @@ def test_novcs_pyproject_init(runner):
assert f"PEP440 : {config._initial_version_pep440()}\n" in result.output
def _vcs_init(vcs, files=["README.md"]):
def _vcs_init(vcs, files=("README.md",)):
assert vcs in ("git", "hg")
assert not pl.Path(f".{vcs}").exists()
sh(f"{vcs}", "init")
shell(f"{vcs}", "init")
assert pl.Path(f".{vcs}").is_dir()
for filename in files:
sh(f"{vcs}", "add", filename)
shell(f"{vcs}", "add", filename)
sh(f"{vcs}", "commit", "-m", "initial commit")
shell(f"{vcs}", "commit", "-m", "initial commit")
def test_git_init(runner):
@ -322,7 +325,7 @@ def test_git_tag_eval(runner):
tag_version = initial_version.replace(".0001-alpha", ".0123-beta")
tag_version_pep440 = tag_version[1:7] + ".123b0"
sh("git", "tag", "--annotate", tag_version, "--message", f"bump version to {tag_version}")
shell("git", "tag", "--annotate", tag_version, "--message", f"bump version to {tag_version}")
result = runner.invoke(cli.cli, ['show', "-vv"])
assert result.exit_code == 0
@ -342,7 +345,7 @@ def test_hg_tag_eval(runner):
tag_version = initial_version.replace(".0001-alpha", ".0123-beta")
tag_version_pep440 = tag_version[1:7] + ".123b0"
sh("hg", "tag", tag_version, "--message", f"bump version to {tag_version}")
shell("hg", "tag", tag_version, "--message", f"bump version to {tag_version}")
result = runner.invoke(cli.cli, ['show', "-vv"])
assert result.exit_code == 0
@ -361,16 +364,16 @@ def test_novcs_bump(runner):
calver = config._initial_version()[:7]
with pl.Path("README.md").open() as fh:
content = fh.read()
with pl.Path("README.md").open() as fobj:
content = fobj.read()
assert calver + ".0002-alpha !\n" in content
assert calver[1:] + ".2a0 !\n" in content
result = runner.invoke(cli.cli, ['bump', "-vv", "--release", "beta"])
assert result.exit_code == 0
with pl.Path("README.md").open() as fh:
content = fh.read()
with pl.Path("README.md").open() as fobj:
content = fobj.read()
assert calver + ".0003-beta !\n" in content
assert calver[1:] + ".3b0 !\n" in content
@ -382,16 +385,16 @@ def test_git_bump(runner):
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
sh("git", "add", "pycalver.toml")
sh("git", "commit", "-m", "initial commit")
shell("git", "add", "pycalver.toml")
shell("git", "commit", "-m", "initial commit")
result = runner.invoke(cli.cli, ['bump', "-vv"])
assert result.exit_code == 0
calver = config._initial_version()[:7]
with pl.Path("README.md").open() as fh:
content = fh.read()
with pl.Path("README.md").open() as fobj:
content = fobj.read()
assert calver + ".0002-alpha !\n" in content
@ -402,28 +405,28 @@ def test_hg_bump(runner):
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
sh("hg", "add", "pycalver.toml")
sh("hg", "commit", "-m", "initial commit")
shell("hg", "add", "pycalver.toml")
shell("hg", "commit", "-m", "initial commit")
result = runner.invoke(cli.cli, ['bump', "-vv"])
assert result.exit_code == 0
calver = config._initial_version()[:7]
with pl.Path("README.md").open() as fh:
content = fh.read()
with pl.Path("README.md").open() as fobj:
content = fobj.read()
assert calver + ".0002-alpha !\n" in content
def test_empty_git_bump(runner, caplog):
sh("git", "init")
with pl.Path("setup.cfg").open(mode="w") as fh:
fh.write("")
shell("git", "init")
with pl.Path("setup.cfg").open(mode="w") as fobj:
fobj.write("")
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
with pl.Path("setup.cfg").open(mode="r") as fh:
default_cfg_data = fh.read()
with pl.Path("setup.cfg").open(mode="r") as fobj:
default_cfg_data = fobj.read()
assert "[pycalver]\n" in default_cfg_data
assert "\ncurrent_version = " in default_cfg_data
@ -437,14 +440,14 @@ def test_empty_git_bump(runner, caplog):
def test_empty_hg_bump(runner, caplog):
sh("hg", "init")
with pl.Path("setup.cfg").open(mode="w") as fh:
fh.write("")
shell("hg", "init")
with pl.Path("setup.cfg").open(mode="w") as fobj:
fobj.write("")
result = runner.invoke(cli.cli, ['init', "-vv"])
assert result.exit_code == 0
with pl.Path("setup.cfg").open(mode="r") as fh:
default_cfg_text = fh.read()
with pl.Path("setup.cfg").open(mode="r") as fobj:
default_cfg_text = fobj.read()
assert "[pycalver]\n" in default_cfg_text
assert "\ncurrent_version = " in default_cfg_text

View file

@ -1,3 +1,6 @@
# pylint:disable=redefined-outer-name ; pytest fixtures
# pylint:disable=protected-access ; allowed for test code
import io
from pycalver import config
@ -141,8 +144,8 @@ 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()
with config_path.open() as fobj:
config_data = fobj.read()
assert "v201710.0123-alpha" in config_data
@ -165,8 +168,8 @@ 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()
with config_path.open() as fobj:
config_data = fobj.read()
assert "v201307.0456-beta" in config_data
@ -211,7 +214,7 @@ def test_parse_toml_file(tmpdir):
}
def test_parse_default_pattern(tmpdir):
def test_parse_default_pattern():
project_path = util.FIXTURES_DIR / "project_c"
config_path = util.FIXTURES_DIR / "project_c" / "pyproject.toml"

View file

@ -1,3 +1,5 @@
# pylint:disable=protected-access ; allowed for test code
import random
from pycalver import lex_id
@ -18,7 +20,7 @@ def test_next_id_overflow():
def test_next_id_random():
for i in range(1000):
for _ in range(1000):
prev_id = str(random.randint(1, 100 * 1000))
try:
next_id = lex_id.next_id(prev_id)

View file

@ -1,3 +1,5 @@
# pylint:disable=protected-access ; allowed for test code
import copy
from pycalver import config

View file

@ -1,3 +1,5 @@
# pylint:disable=protected-access ; allowed for test code
import random
import datetime as dt
@ -42,7 +44,7 @@ def test_bump_random(monkeypatch):
monkeypatch.setattr(version, 'TODAY', cur_date)
for i in range(1000):
for _ in range(1000):
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
new_version = version.incr(
cur_version, release=random.choice([None, "alpha", "beta", "rc", "final", "post"])

View file

@ -36,8 +36,9 @@ FIXTURE_PATH_PARTS = [
class Project:
def __init__(self, project=None):
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
self.tmpdir = tmpdir
tmpdir = pl.Path(tempfile.mkdtemp(prefix="pytest_"))
self.tmpdir = tmpdir
self.prev_cwd = os.getcwd()
self.dir = tmpdir / "pycalver_project"
self.dir.mkdir()
@ -58,7 +59,6 @@ class Project:
shutil.copy(str(fixture_fpath), str(project_fpath))
def __enter__(self):
self.prev_cwd = os.getcwd()
os.chdir(str(self.dir))
return self
@ -67,7 +67,7 @@ class Project:
os.chdir(self.prev_cwd)
return False
def sh(self, cmd):
def shell(self, cmd):
shell = Shell(str(self.dir))
return shell(cmd)
@ -76,17 +76,17 @@ class Project:
for path_parts in FIXTURE_PATH_PARTS:
maybe_file_path = self.dir.joinpath(*path_parts)
if maybe_file_path.exists():
self.sh(f"{cmd} add {str(maybe_file_path)}")
self.shell(f"{cmd} add {str(maybe_file_path)}")
added_file_paths.append(maybe_file_path)
assert len(added_file_paths) >= 2
def git_init(self):
self.sh("git init")
self.shell("git init")
self._vcs_addall(cmd="git")
self.sh("git commit -m 'initial commit'")
self.shell("git commit -m 'initial commit'")
def hg_init(self):
self.sh("hg init")
self.shell("hg init")
self._vcs_addall(cmd="hg")
self.sh("hg commit -m 'initial commit'")
self.shell("hg commit -m 'initial commit'")