more coverage

This commit is contained in:
Manuel Barkhau 2019-01-07 17:30:02 +01:00
parent 4598286f12
commit df492a20d6
10 changed files with 128 additions and 27 deletions

View file

@ -24,14 +24,14 @@ from . import rewrite
_VERBOSE = 0
# try:
# import backtrace
try:
import backtrace
# # To enable pretty tracebacks:
# # echo "export ENABLE_BACKTRACE=1;" >> ~/.bashrc
# backtrace.hook(align=True, strip_path=True, enable_on_envvar_only=True)
# except ImportError:
# pass
# To enable pretty tracebacks:
# echo "export ENABLE_BACKTRACE=1;" >> ~/.bashrc
backtrace.hook(align=True, strip_path=True, enable_on_envvar_only=True)
except ImportError:
pass
click.disable_unicode_literals_warning = True
@ -183,10 +183,10 @@ def init(verbose: int = 0, dry: bool = False) -> None:
sys.exit(1)
if dry:
print("Exiting because of '--dry'. Would have written to setup.cfg:")
print("Exiting because of '--dry'. Would have written to {ctx.config_filepath}:")
cfg_lines = config.default_config(ctx)
print("\n " + "\n ".join(cfg_lines))
return
sys.exit(0)
config.write_content(ctx)

View file

@ -222,8 +222,8 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
version_pattern = raw_cfg.get('version_pattern', "{pycalver}")
version_pattern = raw_cfg['version_pattern'] = version_pattern.strip("'\" ")
# NOTE (mb 2019-01-05): trigger ValueError if version_pattern
# and current_version don't work together.
# NOTE (mb 2019-01-05): Provoke ValueError if version_pattern
# and current_version are not compatible.
version.parse_version_info(version_str, version_pattern)
pep440_version = version.to_pep440(version_str)
@ -245,7 +245,15 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
file_patterns = _normalize_file_patterns(raw_cfg)
cfg = Config(version_str, version_pattern, pep440_version, tag, commit, push, file_patterns)
cfg = Config(
current_version=version_str,
version_pattern=version_pattern,
pep440_version=pep440_version,
commit=commit,
tag=tag,
push=push,
file_patterns=file_patterns,
)
log.debug(_debug_str(cfg))
return cfg
@ -263,7 +271,8 @@ def parse(ctx: ProjectContext) -> MaybeConfig:
elif ctx.config_format == 'cfg':
raw_cfg = _parse_cfg(fh)
else:
return None
err_msg = "Invalid config_format='{ctx.config_format}'"
raise RuntimeError(err_msg)
return _parse_config(raw_cfg)
except ValueError as ex:

View file

@ -109,6 +109,8 @@ def iter_rewritten(
... ]
>>>
'''
fh: typ.IO[str]
for filepath, patterns in file_patterns.items():
with io.open(filepath, mode="rt", encoding="utf-8") as fh:
content = fh.read()
@ -151,6 +153,8 @@ def diff(new_version: str, file_patterns: config.PatternsByFilePath) -> str:
full_diff = ""
file_path: str
fh : typ.IO[str]
for file_path, patterns in sorted(file_patterns.items()):
with io.open(file_path, mode="rt", encoding="utf-8") as fh:
content = fh.read()
@ -165,6 +169,7 @@ def diff(new_version: str, file_patterns: config.PatternsByFilePath) -> str:
def rewrite(new_version: str, file_patterns: config.PatternsByFilePath) -> None:
"""Rewrite project files, updating each with the new version."""
fh: typ.IO[str]
for file_data in iter_rewritten(file_patterns, new_version):
new_content = file_data.line_sep.join(file_data.new_lines)

View file

@ -50,6 +50,9 @@ VCS_SUBCOMMANDS_BY_NAME = {
}
Env = typ.Dict[str, str]
class VCS:
"""VCS absraction for git and mercurial."""
@ -60,7 +63,7 @@ class VCS:
else:
self.subcommands = subcommands
def __call__(self, cmd_name: str, env=None, **kwargs: str) -> str:
def __call__(self, cmd_name: str, env: Env = None, **kwargs: str) -> str:
"""Invoke subcommand and return output."""
cmd_tmpl = self.subcommands[cmd_name]
cmd_str = cmd_tmpl.format(**kwargs)
@ -68,7 +71,7 @@ class VCS:
log.info(cmd_str)
else:
log.debug(cmd_str)
output_data = sp.check_output(cmd_str.split(), env=env, stderr=sp.STDOUT)
output_data: bytes = sp.check_output(cmd_str.split(), env=env, stderr=sp.STDOUT)
# TODO (mb 2018-11-15): Detect encoding of output?
_encoding = "utf-8"
@ -141,12 +144,11 @@ class VCS:
tmp_file = tempfile.NamedTemporaryFile("wb", delete=False)
assert " " not in tmp_file.name
fh : typ.IO[bytes]
with tmp_file as fh:
fh.write(message_data)
env = os.environ.copy()
# TODO (mb 2018-09-04): check that this works on py27,
# might need to be bytes there, idk.
env: Env = os.environ.copy()
env['HGENCODING'] = "utf-8"
self('commit', env=env, path=tmp_file.name)
os.unlink(tmp_file.name)

View file

@ -430,7 +430,12 @@ def incr(
'old_version' is assumed to be a string that matches 'pattern'
"""
old_ver_nfo = parse_version_info(old_version, pattern)
try:
old_ver_nfo = parse_version_info(old_version, pattern)
except ValueError as ex:
log.error(str(ex))
return None
cur_ver_nfo = old_ver_nfo
cur_cal_nfo = cal_info()