formatting updates

This commit is contained in:
Manuel Barkhau 2018-11-06 21:45:33 +01:00
parent 3385f2d675
commit 1129de0beb
11 changed files with 153 additions and 128 deletions

View file

@ -23,16 +23,20 @@ def test_parse_default_config():
def test_parse(tmpdir):
setup_path = tmpdir.mkdir("minimal").join("setup.cfg")
setup_path.write("\n".join((
"[pycalver]",
"current_version = v201808.0001-dev",
"commit = False",
"tag = False",
"",
"[pycalver:file:setup.cfg]",
"patterns = ",
" current_version = {version}",
)))
setup_path.write(
"\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))
@ -64,11 +68,15 @@ def test_parse_empty_config(tmpdir):
def test_parse_missing_version(tmpdir):
setup_path = tmpdir.mkdir("fail").join("setup.cfg")
setup_path.write("\n".join((
"[pycalver]",
# f"current_version = v201808.0001-dev",
"commit = False",
)))
setup_path.write(
"\n".join(
(
"[pycalver]",
# f"current_version = v201808.0001-dev",
"commit = False",
)
)
)
cfg = config.parse(str(setup_path))
assert cfg is None
@ -76,11 +84,7 @@ def test_parse_missing_version(tmpdir):
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",
)))
setup_path.write("\n".join(("[pycalver]", "current_version = 0.1.0", "commit = False")))
cfg = config.parse(str(setup_path))
assert cfg is None

View file

@ -18,7 +18,7 @@ def test_next_id_overflow():
def test_next_id_random():
for i in range(1000):
prev_id = str(random.randint(1, 100000))
prev_id = str(random.randint(1, 100_000))
try:
next_id = lex_id.next_id(prev_id)
assert prev_id < next_id
@ -27,10 +27,10 @@ def test_next_id_random():
def test_ord_val():
assert lex_id.ord_val("1") == 1
assert lex_id.ord_val("01") == 1
assert lex_id.ord_val("02") == 2
assert lex_id.ord_val("09") == 9
assert lex_id.ord_val("1" ) == 1
assert lex_id.ord_val("01" ) == 1
assert lex_id.ord_val("02" ) == 2
assert lex_id.ord_val("09" ) == 9
assert lex_id.ord_val("110") == 10
@ -39,13 +39,13 @@ def test_main(capsys):
captured = capsys.readouterr()
assert len(captured.err) == 0
lines = iter(captured.out.splitlines())
lines = iter(captured.out.splitlines())
header = next(lines)
assert "lexical" in header
assert "numerical" in header
ids = []
ids = []
ord_vals = []
for line in lines:
@ -60,5 +60,5 @@ def test_main(capsys):
ord_vals.append(int(_ord_val.strip()))
assert len(ids) > 0
assert sorted(ids) == ids
assert sorted(ids ) == ids
assert sorted(ord_vals) == ord_vals

View file

@ -3,13 +3,13 @@ from pycalver import rewrite
def test_rewrite_lines():
old_lines = [
'# This file is part of the pycalver project',
'# https://github.com/mbarkhau/pycalver',
'#',
'# (C) 2018 Manuel Barkhau (@mbarkhau)',
'# SPDX-License-Identifier: MIT',
"# This file is part of the pycalver project",
"# https://github.com/mbarkhau/pycalver",
"#",
"# (C) 2018 Manuel Barkhau (@mbarkhau)",
"# SPDX-License-Identifier: MIT",
'',
'import os',
"import os",
'',
'__version__ = "v201809.0002-beta"',
'DEBUG = os.environ.get("PYDEBUG", "0") == "1"',

View file

@ -12,46 +12,43 @@ def test_current_calver():
def test_bump_beta():
calver = version.current_calver()
calver = version.current_calver()
cur_version = calver + ".0001-beta"
assert cur_version < version.bump(cur_version)
assert version.bump(cur_version).endswith("-beta")
assert version.bump(cur_version, release="alpha").endswith("-alpha")
assert version.bump(cur_version, release="final").endswith("0002")
assert cur_version < version.incr(cur_version)
assert version.incr(cur_version).endswith("-beta")
assert version.incr(cur_version, release="alpha").endswith("-alpha")
assert version.incr(cur_version, release="final").endswith("0002")
def test_bump_final():
calver = version.current_calver()
calver = version.current_calver()
cur_version = calver + ".0001"
assert cur_version < version.bump(cur_version)
assert version.bump(cur_version, release="alpha").endswith("-alpha")
assert version.bump(cur_version, release="final").endswith("0002")
assert version.bump(cur_version).endswith("0002")
assert cur_version < version.incr(cur_version)
assert version.incr(cur_version, release="alpha").endswith("-alpha")
assert version.incr(cur_version, release="final").endswith("0002")
assert version.incr(cur_version).endswith("0002")
def test_bump_future():
future_date = dt.datetime.today() + dt.timedelta(days=300)
future_date = dt.datetime.today() + dt.timedelta(days=300)
future_calver = future_date.strftime("v%Y%m")
cur_version = future_calver + ".0001"
assert cur_version < version.bump(cur_version)
cur_version = future_calver + ".0001"
assert cur_version < version.incr(cur_version)
def test_bump_random():
cur_date = dt.date.today()
def test_bump_random(monkeypatch):
cur_date = dt.date.today()
cur_version = cur_date.strftime("v%Y%m") + ".0001-dev"
def _mock_current_calver():
return cur_date.strftime("v%Y%m")
_orig_current_calver = version.current_calver
version.current_calver = _mock_current_calver
try:
for i in range(1000):
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
new_version = version.bump(cur_version, release=random.choice([
None, "alpha", "beta", "rc", "final"
]))
assert cur_version < new_version
cur_version = new_version
finally:
version.current_calver = _orig_current_calver
monkeypatch.setattr(version, 'current_calver', _mock_current_calver)
for i 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'])
)
assert cur_version < new_version
cur_version = new_version