bumpver/test/test_version.py

143 lines
4.2 KiB
Python
Raw Normal View History

2018-09-03 22:23:51 +02:00
import random
2018-09-02 21:48:12 +02:00
import datetime as dt
2018-09-03 22:23:51 +02:00
2018-09-03 09:19:27 +02:00
from pycalver import version
2018-09-02 21:48:12 +02:00
2018-09-03 09:19:27 +02:00
def test_current_calver():
v = version.current_calver()
assert len(v) == 7
assert v.startswith("v")
assert v[1:].isdigit()
2018-09-02 21:48:12 +02:00
2018-09-03 22:23:51 +02:00
def test_bump_beta():
2018-11-06 21:45:33 +01:00
calver = version.current_calver()
2018-09-03 22:23:51 +02:00
cur_version = calver + ".0001-beta"
2018-11-06 21:45:33 +01:00
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")
2018-09-03 22:23:51 +02:00
def test_bump_final():
2018-11-06 21:45:33 +01:00
calver = version.current_calver()
2018-09-03 22:23:51 +02:00
cur_version = calver + ".0001"
2018-11-06 21:45:33 +01:00
assert cur_version < version.incr(cur_version)
assert version.incr(cur_version).endswith(".0002")
2018-11-06 21:45:33 +01:00
assert version.incr(cur_version, release="alpha").endswith("-alpha")
assert version.incr(cur_version, release="final").endswith(".0002")
pre_version = cur_version + "-beta"
assert version.incr(pre_version, release="final").endswith(".0002")
2018-09-03 22:23:51 +02:00
def test_bump_future():
2018-11-06 21:45:33 +01:00
future_date = dt.datetime.today() + dt.timedelta(days=300)
2018-09-03 22:23:51 +02:00
future_calver = future_date.strftime("v%Y%m")
2018-11-06 21:45:33 +01:00
cur_version = future_calver + ".0001"
assert cur_version < version.incr(cur_version)
2018-09-03 22:23:51 +02:00
2018-11-06 21:45:33 +01:00
def test_bump_random(monkeypatch):
cur_date = dt.date.today()
2018-09-03 22:23:51 +02:00
cur_version = cur_date.strftime("v%Y%m") + ".0001-dev"
def _mock_current_calver():
return cur_date.strftime("v%Y%m")
2018-11-06 21:45:33 +01:00
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
2018-12-09 14:49:13 +01:00
def test_parse_version_info():
version_str = "v201712.0001-alpha"
version_nfo = version.parse_version_info(version_str)
assert version_nfo.pep440_version == "201712.1a0"
assert version_nfo.version == "v201712.0001-alpha"
assert version_nfo.calver == "v201712"
assert version_nfo.year == "2017"
assert version_nfo.month == "12"
assert version_nfo.build == ".0001"
assert version_nfo.release == "-alpha"
assert version_nfo.build_no == "0001"
assert version_nfo.release_tag == "alpha"
2018-12-09 14:49:13 +01:00
version_str = "v201712.0001"
version_nfo = version.parse_version_info(version_str)
assert version_nfo.pep440_version == "201712.1"
assert version_nfo.version == "v201712.0001"
assert version_nfo.calver == "v201712"
assert version_nfo.year == "2017"
assert version_nfo.month == "12"
assert version_nfo.build == ".0001"
assert version_nfo.release == "-final"
assert version_nfo.build_no == "0001"
assert version_nfo.release_tag == "final"
2018-12-09 14:49:13 +01:00
def test_readme_pycalver1():
version_str = "v201712.0001-alpha"
version_info = version.PYCALVER_RE.match(version_str).groupdict()
assert version_info == {
'version' : "v201712.0001-alpha",
'calver' : "v201712",
'year' : "2017",
'month' : "12",
'build' : ".0001",
'build_no' : "0001",
'release' : "-alpha",
'release_tag': "alpha",
2018-12-09 14:49:13 +01:00
}
def test_readme_pycalver2():
version_str = "v201712.0033"
version_info = version.PYCALVER_RE.match(version_str).groupdict()
assert version_info == {
'version' : "v201712.0033",
'calver' : "v201712",
'year' : "2017",
'month' : "12",
'build' : ".0033",
'build_no' : "0033",
'release' : None,
'release_tag': None,
2018-12-09 14:49:13 +01:00
}
def test_parse_error_empty():
try:
version.parse_version_info("")
assert False
except ValueError as err:
pass
def test_parse_error_noprefix():
try:
version.parse_version_info("201809.0002")
assert False
except ValueError as err:
pass
def test_parse_error_nopadding():
try:
version.parse_version_info("v201809.2b0")
assert False
except ValueError as err:
pass