2020-09-17 23:38:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from __future__ import division
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
from __future__ import unicode_literals
|
2020-07-19 14:38:57 +00:00
|
|
|
|
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
|
|
|
|
2019-07-25 12:17:52 +02:00
|
|
|
import pytest
|
|
|
|
|
|
2020-10-18 20:47:35 +00:00
|
|
|
from bumpver import version
|
|
|
|
|
from bumpver import v1version
|
|
|
|
|
from bumpver import v2version
|
|
|
|
|
from bumpver import v1patterns
|
|
|
|
|
from bumpver import v2patterns
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2020-09-17 23:38:58 +00:00
|
|
|
# pylint:disable=protected-access ; allowed for test code
|
|
|
|
|
|
2018-09-02 21:48:12 +02:00
|
|
|
|
2018-09-03 22:23:51 +02:00
|
|
|
def test_bump_beta():
|
2019-01-06 14:38:20 +01:00
|
|
|
cur_version = "v201712.0001-beta"
|
2020-09-17 16:24:21 +00:00
|
|
|
assert cur_version < v1version.incr(cur_version)
|
|
|
|
|
assert v1version.incr(cur_version).endswith("-beta")
|
2020-10-03 23:44:09 +00:00
|
|
|
assert v1version.incr(cur_version, tag="alpha").endswith("-alpha")
|
|
|
|
|
assert v1version.incr(cur_version, tag="final").endswith("0002")
|
2018-09-03 22:23:51 +02:00
|
|
|
|
|
|
|
|
|
2020-11-16 22:08:54 +00:00
|
|
|
def test_bump_final_v1():
|
2019-01-06 14:38:20 +01:00
|
|
|
cur_version = "v201712.0001"
|
2020-09-17 16:24:21 +00:00
|
|
|
assert cur_version < v1version.incr(cur_version)
|
|
|
|
|
assert v1version.incr(cur_version).endswith(".0002")
|
2020-10-03 23:44:09 +00:00
|
|
|
assert v1version.incr(cur_version, tag="alpha").endswith("-alpha")
|
2018-12-22 09:49:27 +01:00
|
|
|
|
2020-10-03 23:44:09 +00:00
|
|
|
assert v1version.incr(cur_version, tag="final").endswith(".0002")
|
2018-12-22 09:49:27 +01:00
|
|
|
|
|
|
|
|
pre_version = cur_version + "-beta"
|
2020-10-03 23:44:09 +00:00
|
|
|
assert v1version.incr(pre_version, tag="final").endswith(".0002")
|
2018-09-03 22:23:51 +02:00
|
|
|
|
|
|
|
|
|
2020-11-16 22:08:54 +00:00
|
|
|
def test_bump_final_v2():
|
|
|
|
|
print()
|
|
|
|
|
raw_pattern = "vMAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
|
|
|
cur_version = "v0.1.4b1"
|
|
|
|
|
assert v2version.incr(cur_version, raw_pattern, major=True ) == "v1.0.0b0"
|
|
|
|
|
assert v2version.incr(cur_version, raw_pattern, minor=True ) == "v0.2.0b0"
|
|
|
|
|
assert v2version.incr(cur_version, raw_pattern, patch=True ) == "v0.1.5b0"
|
|
|
|
|
assert v2version.incr(cur_version, raw_pattern, tag_num=True) == "v0.1.4b2"
|
|
|
|
|
assert v2version.incr(cur_version, raw_pattern, patch=True, tag="final") == "v0.1.5"
|
|
|
|
|
|
|
|
|
|
|
2018-09-03 22:23:51 +02:00
|
|
|
def test_bump_future():
|
2019-01-06 14:38:20 +01:00
|
|
|
"""Test that versions don't go back in time."""
|
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"
|
2020-09-17 16:24:21 +00:00
|
|
|
new_version = v1version.incr(cur_version)
|
2019-01-06 14:38:20 +01:00
|
|
|
assert cur_version < new_version
|
2018-09-03 22:23:51 +02:00
|
|
|
|
|
|
|
|
|
2018-11-06 21:45:33 +01:00
|
|
|
def test_bump_random(monkeypatch):
|
2019-01-06 14:38:20 +01:00
|
|
|
cur_date = dt.date(2016, 1, 1) + dt.timedelta(days=random.randint(1, 2000))
|
2018-09-03 22:23:51 +02:00
|
|
|
cur_version = cur_date.strftime("v%Y%m") + ".0001-dev"
|
|
|
|
|
|
2020-09-19 22:35:48 +00:00
|
|
|
monkeypatch.setattr(version, 'TODAY', cur_date)
|
2018-11-06 21:45:33 +01:00
|
|
|
|
2020-07-19 14:38:57 +00:00
|
|
|
for _ in range(1000):
|
2018-11-06 21:45:33 +01:00
|
|
|
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
|
2020-09-17 16:24:21 +00:00
|
|
|
new_version = v1version.incr(
|
2020-10-03 23:44:09 +00:00
|
|
|
cur_version, tag=random.choice([None, "alpha", "beta", "rc", "final", "post"])
|
2018-11-06 21:45:33 +01:00
|
|
|
)
|
|
|
|
|
assert cur_version < new_version
|
|
|
|
|
cur_version = new_version
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
|
2021-01-17 19:05:30 +01:00
|
|
|
def test_bump_tag_num():
|
|
|
|
|
raw_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
|
|
|
cur_version = "0.1.1b0"
|
2021-01-17 19:45:53 +01:00
|
|
|
assert v2version.incr(cur_version, raw_pattern, tag_num=True) == "0.1.1b1"
|
2021-01-17 19:05:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_bump_tag_num_without_tag():
|
|
|
|
|
raw_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]"
|
|
|
|
|
cur_version = "0.1.1"
|
2021-01-17 19:45:53 +01:00
|
|
|
assert v2version.incr(cur_version, raw_pattern, tag_num=True) is None
|
2021-01-17 19:05:30 +01:00
|
|
|
|
|
|
|
|
|
2018-12-09 14:49:13 +01:00
|
|
|
def test_parse_version_info():
|
2019-07-25 12:17:52 +02:00
|
|
|
version_str = "v201712.0001-alpha"
|
2020-09-17 16:24:21 +00:00
|
|
|
version_info = v1version.parse_version_info(version_str)
|
2018-12-09 14:49:13 +01:00
|
|
|
|
2019-07-25 12:17:52 +02:00
|
|
|
# assert version_info.pep440_version == "201712.1a0"
|
|
|
|
|
# assert version_info.version == "v201712.0001-alpha"
|
|
|
|
|
assert version_info.year == 2017
|
|
|
|
|
assert version_info.month == 12
|
|
|
|
|
assert version_info.bid == "0001"
|
|
|
|
|
assert version_info.tag == "alpha"
|
2018-12-09 14:49:13 +01:00
|
|
|
|
2019-07-25 12:17:52 +02:00
|
|
|
version_str = "v201712.0001"
|
2020-09-17 16:24:21 +00:00
|
|
|
version_info = v1version.parse_version_info(version_str)
|
2018-12-09 14:49:13 +01:00
|
|
|
|
2019-07-25 12:17:52 +02:00
|
|
|
# assert version_info.pep440_version == "201712.1"
|
|
|
|
|
# assert version_info.version == "v201712.0001"
|
|
|
|
|
assert version_info.year == 2017
|
|
|
|
|
assert version_info.month == 12
|
|
|
|
|
assert version_info.bid == "0001"
|
|
|
|
|
assert version_info.tag == "final"
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_pycalver1():
|
|
|
|
|
version_str = "v201712.0001-alpha"
|
2020-09-17 16:24:21 +00:00
|
|
|
version_info = v1patterns.PYCALVER_RE.match(version_str).groupdict()
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
assert version_info == {
|
2019-01-06 14:38:20 +01:00
|
|
|
'pycalver' : "v201712.0001-alpha",
|
|
|
|
|
'vYYYYMM' : "v201712",
|
2018-12-22 00:15:01 +01:00
|
|
|
'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"
|
2020-09-17 16:24:21 +00:00
|
|
|
version_info = v1patterns.PYCALVER_RE.match(version_str).groupdict()
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
assert version_info == {
|
2019-01-06 14:38:20 +01:00
|
|
|
'pycalver' : "v201712.0033",
|
|
|
|
|
'vYYYYMM' : "v201712",
|
2018-12-22 00:15:01 +01:00
|
|
|
'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:
|
2020-09-17 16:24:21 +00:00
|
|
|
v1version.parse_version_info("")
|
2018-12-09 14:49:13 +01:00
|
|
|
assert False
|
2020-09-19 22:35:48 +00:00
|
|
|
except version.PatternError as err:
|
2019-07-25 12:17:52 +02:00
|
|
|
assert "Invalid version string" in str(err)
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_error_noprefix():
|
|
|
|
|
try:
|
2020-09-17 16:24:21 +00:00
|
|
|
v1version.parse_version_info("201809.0002")
|
2018-12-09 14:49:13 +01:00
|
|
|
assert False
|
2020-09-19 22:35:48 +00:00
|
|
|
except version.PatternError as err:
|
2019-07-25 12:17:52 +02:00
|
|
|
assert "Invalid version string" in str(err)
|
2018-12-09 14:49:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_error_nopadding():
|
|
|
|
|
try:
|
2020-09-17 16:24:21 +00:00
|
|
|
v1version.parse_version_info("v201809.2b0")
|
2018-12-09 14:49:13 +01:00
|
|
|
assert False
|
2020-09-19 22:35:48 +00:00
|
|
|
except version.PatternError as err:
|
2019-07-25 12:17:52 +02:00
|
|
|
assert "Invalid version string" in str(err)
|
2019-01-06 14:38:20 +01:00
|
|
|
|
|
|
|
|
|
2020-09-17 16:24:21 +00:00
|
|
|
def test_part_field_mapping_v1():
|
2020-09-17 23:40:55 +00:00
|
|
|
a_names = set(v1patterns.PATTERN_PART_FIELDS.keys())
|
2020-09-17 16:24:21 +00:00
|
|
|
b_names = set(v1patterns.PART_PATTERNS.keys())
|
|
|
|
|
c_names = set(v1patterns.COMPOSITE_PART_PATTERNS.keys())
|
2019-01-06 14:38:20 +01:00
|
|
|
|
2020-09-08 20:59:52 +00:00
|
|
|
a_extra_names = a_names - b_names
|
|
|
|
|
assert not any(a_extra_names), sorted(a_extra_names)
|
|
|
|
|
b_extra_names = b_names - (a_names | c_names)
|
|
|
|
|
assert not any(b_extra_names), sorted(b_extra_names)
|
2019-01-06 14:38:20 +01:00
|
|
|
|
2020-09-17 23:40:55 +00:00
|
|
|
a_fields = set(v1patterns.PATTERN_PART_FIELDS.values())
|
2020-09-19 22:35:48 +00:00
|
|
|
b_fields = set(version.V1VersionInfo._fields)
|
2019-01-06 14:38:20 +01:00
|
|
|
|
2020-09-08 20:59:52 +00:00
|
|
|
a_extra_fields = a_fields - b_fields
|
|
|
|
|
b_extra_fields = b_fields - a_fields
|
|
|
|
|
assert not any(a_extra_fields), sorted(a_extra_fields)
|
|
|
|
|
assert not any(b_extra_fields), sorted(b_extra_fields)
|
2019-07-25 12:17:52 +02:00
|
|
|
|
|
|
|
|
|
2020-10-02 22:44:13 +00:00
|
|
|
def v1vnfo(**field_values):
|
2020-09-17 16:24:21 +00:00
|
|
|
return v1version._parse_field_values(field_values)
|
2019-07-25 12:17:52 +02:00
|
|
|
|
|
|
|
|
|
2020-10-02 22:44:13 +00:00
|
|
|
def v2vnfo(**field_values):
|
2020-10-09 22:23:17 +00:00
|
|
|
return v2version.parse_field_values_to_vinfo(field_values)
|
2020-10-02 22:44:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
PARSE_V1_VERSION_TEST_CASES = [
|
|
|
|
|
["{year}.{month}.{dom}" , "2017.06.07", v1vnfo(year="2017", month="06", dom="07")],
|
|
|
|
|
["{year}.{month}.{dom_short}" , "2017.06.7" , v1vnfo(year="2017", month="06", dom="7" )],
|
|
|
|
|
["{year}.{month}.{dom_short}" , "2017.06.7" , v1vnfo(year="2017", month="06", dom="7" )],
|
|
|
|
|
["{year}.{month_short}.{dom_short}", "2017.6.7" , v1vnfo(year="2017", month="6" , dom="7" )],
|
2019-07-25 12:17:52 +02:00
|
|
|
["{year}.{month}.{dom}" , "2017.6.07" , None],
|
|
|
|
|
["{year}.{month}.{dom}" , "2017.06.7" , None],
|
|
|
|
|
["{year}.{month_short}.{dom}" , "2017.06.7" , None],
|
|
|
|
|
["{year}.{month}.{dom_short}" , "2017.6.07" , None],
|
2020-10-02 22:44:13 +00:00
|
|
|
["{year}.{month_short}.{MINOR}" , "2017.6.7" , v1vnfo(year="2017", month="6" , minor="7" )],
|
|
|
|
|
["{year}.{month}.{MINOR}" , "2017.06.7" , v1vnfo(year="2017", month="06", minor="7" )],
|
|
|
|
|
["{year}.{month}.{MINOR}" , "2017.06.07", v1vnfo(year="2017", month="06", minor="07")],
|
2019-07-25 12:17:52 +02:00
|
|
|
["{year}.{month}.{MINOR}" , "2017.6.7" , None],
|
2020-10-02 22:44:13 +00:00
|
|
|
["YYYY.0M.0D" , "2017.06.07", v2vnfo(year_y="2017", month="06", dom="07")],
|
|
|
|
|
["YYYY.MM.DD" , "2017.6.7" , v2vnfo(year_y="2017", month="6" , dom="7" )],
|
|
|
|
|
["YYYY.MM.MD" , "2017.06.07", None],
|
|
|
|
|
["YYYY.0M.0D" , "2017.6.7" , None],
|
2019-07-25 12:17:52 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2020-10-02 22:44:13 +00:00
|
|
|
@pytest.mark.parametrize("pattern_str, line, expected_vinfo", PARSE_V1_VERSION_TEST_CASES)
|
2020-09-18 13:19:01 +00:00
|
|
|
def test_v1_parse_versions(pattern_str, line, expected_vinfo):
|
2020-10-02 22:44:13 +00:00
|
|
|
if "{" in pattern_str:
|
|
|
|
|
pattern = v1patterns.compile_pattern(pattern_str)
|
|
|
|
|
version_match = pattern.regexp.search(line)
|
|
|
|
|
else:
|
|
|
|
|
pattern = v2patterns.compile_pattern(pattern_str)
|
|
|
|
|
version_match = pattern.regexp.search(line)
|
2019-07-25 12:17:52 +02:00
|
|
|
|
|
|
|
|
if expected_vinfo is None:
|
|
|
|
|
assert version_match is None
|
2020-10-02 22:44:13 +00:00
|
|
|
else:
|
|
|
|
|
assert version_match is not None
|
2019-07-25 12:17:52 +02:00
|
|
|
|
2020-10-02 22:44:13 +00:00
|
|
|
version_str = version_match.group(0)
|
2019-07-25 12:17:52 +02:00
|
|
|
|
2020-10-02 22:44:13 +00:00
|
|
|
if "{" in pattern_str:
|
|
|
|
|
version_info = v1version.parse_version_info(version_str, pattern_str)
|
|
|
|
|
assert version_info == expected_vinfo
|
|
|
|
|
else:
|
|
|
|
|
version_info = v2version.parse_version_info(version_str, pattern_str)
|
|
|
|
|
assert version_info == expected_vinfo
|
2020-09-18 13:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_v2_parse_versions():
|
2020-10-14 22:17:18 +00:00
|
|
|
_vnfo = v2version.parse_version_info("v201712.0033", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
|
2020-09-18 13:19:01 +00:00
|
|
|
fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
|
2020-10-09 22:23:17 +00:00
|
|
|
assert _vnfo == v2version.parse_field_values_to_vinfo(fvals)
|
2020-09-18 13:19:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_v2_format_version():
|
2020-10-14 22:17:18 +00:00
|
|
|
version_pattern = "vYYYY0M.BUILD[-TAG[NUM]]"
|
2020-09-24 11:16:02 +00:00
|
|
|
in_version = "v200701.0033-beta"
|
2020-09-18 13:19:01 +00:00
|
|
|
|
2020-09-19 22:35:48 +00:00
|
|
|
vinfo = v2version.parse_version_info(in_version, raw_pattern=version_pattern)
|
|
|
|
|
out_version = v2version.format_version(vinfo, raw_pattern=version_pattern)
|
2020-09-18 13:19:01 +00:00
|
|
|
assert in_version == out_version
|
|
|
|
|
|
2020-10-14 22:17:18 +00:00
|
|
|
result = v2version.format_version(vinfo, raw_pattern="v0Y.BUILD[-TAG]")
|
2020-09-18 13:19:01 +00:00
|
|
|
assert result == "v07.0033-beta"
|
|
|
|
|
|
2020-10-14 22:17:18 +00:00
|
|
|
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD[-TAG]")
|
2020-09-18 13:19:01 +00:00
|
|
|
assert result == "v7.33-beta"
|
2020-09-18 16:52:28 +00:00
|
|
|
|
2020-10-14 22:17:18 +00:00
|
|
|
result = v2version.format_version(vinfo, raw_pattern="vYY.BLD-TAG")
|
2020-09-18 16:52:28 +00:00
|
|
|
assert result == "v7.33-beta"
|
|
|
|
|
|
2020-10-14 22:17:18 +00:00
|
|
|
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BUILD[-TAG]"')
|
2020-09-18 16:52:28 +00:00
|
|
|
assert result == '__version__ = "2007.0033-beta"'
|
|
|
|
|
|
2020-09-19 22:35:48 +00:00
|
|
|
result = v2version.format_version(vinfo, raw_pattern='__version__ = "YYYY.BLD"')
|
2020-09-18 16:52:28 +00:00
|
|
|
assert result == '__version__ = "2007.33"'
|
2020-10-04 12:10:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
WEEK_PATTERN_TEXT_CASES = [
|
|
|
|
|
("YYYYWW.PATCH", True),
|
|
|
|
|
("YYYYUU.PATCH", True),
|
|
|
|
|
("GGGGVV.PATCH", True),
|
|
|
|
|
("YYWW.PATCH" , True),
|
|
|
|
|
("YYUU.PATCH" , True),
|
|
|
|
|
("GGVV.PATCH" , True),
|
|
|
|
|
("0YWW.PATCH" , True),
|
|
|
|
|
("0YUU.PATCH" , True),
|
|
|
|
|
("0GVV.PATCH" , True),
|
|
|
|
|
("0Y0W.PATCH" , True),
|
|
|
|
|
("0Y0U.PATCH" , True),
|
|
|
|
|
("0G0V.PATCH" , True),
|
|
|
|
|
("GGGGWW.PATCH", False),
|
|
|
|
|
("GGGGUU.PATCH", False),
|
|
|
|
|
("YYYYVV.PATCH", False),
|
|
|
|
|
("GGWW.PATCH" , False),
|
|
|
|
|
("GGUU.PATCH" , False),
|
|
|
|
|
("YYVV.PATCH" , False),
|
|
|
|
|
("0GWW.PATCH" , False),
|
|
|
|
|
("0GUU.PATCH" , False),
|
|
|
|
|
("0YVV.PATCH" , False),
|
|
|
|
|
("0G0W.PATCH" , False),
|
|
|
|
|
("0G0U.PATCH" , False),
|
|
|
|
|
("0Y0V.PATCH" , False),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("pattern, expected", WEEK_PATTERN_TEXT_CASES)
|
|
|
|
|
def test_is_valid_week_pattern(pattern, expected):
|
|
|
|
|
assert v2version.is_valid_week_pattern(pattern) == expected
|