mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
Add more flexible parsing and formating
This commit is contained in:
parent
32447b03d4
commit
9eda61d95b
13 changed files with 932 additions and 359 deletions
|
|
@ -2,18 +2,11 @@ import random
|
|||
import datetime as dt
|
||||
|
||||
from pycalver import version
|
||||
|
||||
|
||||
def test_current_calver():
|
||||
v = version.current_calver()
|
||||
assert len(v) == 7
|
||||
assert v.startswith("v")
|
||||
assert v[1:].isdigit()
|
||||
from pycalver import patterns
|
||||
|
||||
|
||||
def test_bump_beta():
|
||||
calver = version.current_calver()
|
||||
cur_version = calver + ".0001-beta"
|
||||
cur_version = "v201712.0001-beta"
|
||||
assert cur_version < version.incr(cur_version)
|
||||
assert version.incr(cur_version).endswith("-beta")
|
||||
assert version.incr(cur_version, release="alpha").endswith("-alpha")
|
||||
|
|
@ -21,8 +14,7 @@ def test_bump_beta():
|
|||
|
||||
|
||||
def test_bump_final():
|
||||
calver = version.current_calver()
|
||||
cur_version = calver + ".0001"
|
||||
cur_version = "v201712.0001"
|
||||
assert cur_version < version.incr(cur_version)
|
||||
assert version.incr(cur_version).endswith(".0002")
|
||||
assert version.incr(cur_version, release="alpha").endswith("-alpha")
|
||||
|
|
@ -34,20 +26,19 @@ def test_bump_final():
|
|||
|
||||
|
||||
def test_bump_future():
|
||||
"""Test that versions don't go back in time."""
|
||||
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.incr(cur_version)
|
||||
new_version = version.incr(cur_version)
|
||||
assert cur_version < new_version
|
||||
|
||||
|
||||
def test_bump_random(monkeypatch):
|
||||
cur_date = dt.date.today()
|
||||
cur_date = dt.date(2016, 1, 1) + dt.timedelta(days=random.randint(1, 2000))
|
||||
cur_version = cur_date.strftime("v%Y%m") + ".0001-dev"
|
||||
|
||||
def _mock_current_calver():
|
||||
return cur_date.strftime("v%Y%m")
|
||||
|
||||
monkeypatch.setattr(version, 'current_calver', _mock_current_calver)
|
||||
monkeypatch.setattr(version, 'TODAY', cur_date)
|
||||
|
||||
for i in range(1000):
|
||||
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
|
||||
|
|
@ -62,37 +53,31 @@ 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"
|
||||
# assert version_nfo.pep440_version == "201712.1a0"
|
||||
# assert version_nfo.version == "v201712.0001-alpha"
|
||||
assert version_nfo.year == 2017
|
||||
assert version_nfo.month == 12
|
||||
assert version_nfo.bid == "0001"
|
||||
assert version_nfo.tag == "alpha"
|
||||
|
||||
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"
|
||||
# assert version_nfo.pep440_version == "201712.1"
|
||||
# assert version_nfo.version == "v201712.0001"
|
||||
assert version_nfo.year == 2017
|
||||
assert version_nfo.month == 12
|
||||
assert version_nfo.bid == "0001"
|
||||
assert version_nfo.tag == "final"
|
||||
|
||||
|
||||
def test_readme_pycalver1():
|
||||
version_str = "v201712.0001-alpha"
|
||||
version_info = version.PYCALVER_RE.match(version_str).groupdict()
|
||||
version_info = patterns.PYCALVER_RE.match(version_str).groupdict()
|
||||
|
||||
assert version_info == {
|
||||
'version' : "v201712.0001-alpha",
|
||||
'calver' : "v201712",
|
||||
'pycalver' : "v201712.0001-alpha",
|
||||
'vYYYYMM' : "v201712",
|
||||
'year' : "2017",
|
||||
'month' : "12",
|
||||
'build' : ".0001",
|
||||
|
|
@ -104,11 +89,11 @@ def test_readme_pycalver1():
|
|||
|
||||
def test_readme_pycalver2():
|
||||
version_str = "v201712.0033"
|
||||
version_info = version.PYCALVER_RE.match(version_str).groupdict()
|
||||
version_info = patterns.PYCALVER_RE.match(version_str).groupdict()
|
||||
|
||||
assert version_info == {
|
||||
'version' : "v201712.0033",
|
||||
'calver' : "v201712",
|
||||
'pycalver' : "v201712.0033",
|
||||
'vYYYYMM' : "v201712",
|
||||
'year' : "2017",
|
||||
'month' : "12",
|
||||
'build' : ".0033",
|
||||
|
|
@ -140,3 +125,19 @@ def test_parse_error_nopadding():
|
|||
assert False
|
||||
except ValueError as err:
|
||||
pass
|
||||
|
||||
|
||||
def test_part_field_mapping():
|
||||
a_names = set(version.PATTERN_PART_FIELDS.keys())
|
||||
b_names = set(patterns.PART_PATTERNS.keys())
|
||||
c_names = set(patterns.COMPOSITE_PART_PATTERNS.keys())
|
||||
|
||||
extra_names = a_names - b_names
|
||||
assert not any(extra_names)
|
||||
missing_names = b_names - a_names
|
||||
assert missing_names == c_names
|
||||
|
||||
a_fields = set(version.PATTERN_PART_FIELDS.values())
|
||||
b_fields = set(version.VersionInfo._fields)
|
||||
|
||||
assert a_fields == b_fields
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue