|
1 | 1 | import pytest
|
2 | 2 | from pytest import param
|
3 |
| - |
4 |
| -from bumpversion.versioning.functions import NumericFunction, ValuesFunction, IndependentFunction |
| 3 | +from freezegun import freeze_time |
| 4 | +from bumpversion.versioning.functions import NumericFunction, ValuesFunction, IndependentFunction, CalVerFunction |
5 | 5 |
|
6 | 6 |
|
7 | 7 | # NumericFunction
|
@@ -145,3 +145,66 @@ def test_bump_with_value_returns_value(self):
|
145 | 145 | def test_bump_with_no_value_returns_initial_value(self):
|
146 | 146 | func = IndependentFunction("1")
|
147 | 147 | assert func.bump() == "1"
|
| 148 | + |
| 149 | + |
| 150 | +class TestCalVerFunction: |
| 151 | + """The calver function manages incrementing and resetting calver version parts.""" |
| 152 | + |
| 153 | + @freeze_time("2020-05-01") |
| 154 | + def test_creation_sets_first_value_and_optional_value(self): |
| 155 | + func = CalVerFunction("{YYYY}.{MM}") |
| 156 | + assert func.optional_value == "There isn't an optional value for CalVer." |
| 157 | + assert func.first_value == "2020.5" |
| 158 | + assert func.calver_format == "{YYYY}.{MM}" |
| 159 | + |
| 160 | + @freeze_time("2020-05-01") |
| 161 | + def test_bump_with_value_ignores_value(self): |
| 162 | + func = CalVerFunction("{YYYY}.{MM}.{DD}") |
| 163 | + assert func.bump("123456") == "2020.5.1" |
| 164 | + |
| 165 | + @pytest.mark.parametrize( |
| 166 | + ["calver", "expected"], |
| 167 | + [ |
| 168 | + param("{YYYY}", "2002", id="{YYYY}"), |
| 169 | + param("{YY}", "2", id="{YY}"), |
| 170 | + param("{0Y}", "02", id="{0Y}"), |
| 171 | + param("{MMM}", "May", id="{MMM}"), |
| 172 | + param("{MM}", "5", id="{MM}"), |
| 173 | + param("{0M}", "05", id="{0M}"), |
| 174 | + param("{DD}", "1", id="{DD}"), |
| 175 | + param("{0D}", "01", id="{0D}"), |
| 176 | + param("{JJJ}", "121", id="{JJJ}"), |
| 177 | + param("{00J}", "121", id="{00J}"), |
| 178 | + param("{Q}", "2", id="{Q}"), |
| 179 | + param("{WW}", "17", id="{WW}"), |
| 180 | + param("{0W}", "17", id="{0W}"), |
| 181 | + param("{UU}", "17", id="{UU}"), |
| 182 | + param("{0U}", "17", id="{0U}"), |
| 183 | + param("{VV}", "18", id="{VV}"), |
| 184 | + param("{0V}", "18", id="{0V}"), |
| 185 | + param("{GGGG}", "2002", id="{GGGG}"), |
| 186 | + param("{GG}", "2", id="{GG}"), |
| 187 | + param("{0G}", "02", id="{0G}"), |
| 188 | + ], |
| 189 | + ) |
| 190 | + @freeze_time("2002-05-01") |
| 191 | + def test_calver_formatting_renders_correctly(self, calver: str, expected: str): |
| 192 | + """Test that the calver is formatted correctly.""" |
| 193 | + func = CalVerFunction(calver) |
| 194 | + assert func.bump() == expected |
| 195 | + |
| 196 | + @pytest.mark.parametrize( |
| 197 | + ["calver", "expected"], |
| 198 | + [ |
| 199 | + param("{YYYY}", "2000", id="{YYYY}"), |
| 200 | + param("{YY}", "0", id="{YY}"), |
| 201 | + param("{0Y}", "00", id="{0Y}"), |
| 202 | + param("{GGGG}", "1999", id="{GGGG}"), |
| 203 | + param("{GG}", "99", id="{GG}"), |
| 204 | + param("{0G}", "99", id="{0G}"), |
| 205 | + ], |
| 206 | + ) |
| 207 | + @freeze_time("2000-01-01") |
| 208 | + def test_century_years_return_zeros(self, calver: str, expected: str): |
| 209 | + func = CalVerFunction(calver) |
| 210 | + assert func.bump() == expected |
0 commit comments