1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
import pytest
from bumpversion.functions import NumericFunction, ValuesFunction
# NumericFunction
def test_numeric_init_wo_first_value():
func = NumericFunction()
assert func.first_value == '0'
def test_numeric_init_w_first_value():
func = NumericFunction(first_value='5')
assert func.first_value == '5'
def test_numeric_init_non_numeric_first_value():
with pytest.raises(ValueError):
func = NumericFunction(first_value='a')
def test_numeric_bump_simple_number():
func = NumericFunction()
assert func.bump('0') == '1'
def test_numeric_bump_prefix_and_suffix():
func = NumericFunction()
assert func.bump('v0b') == 'v1b'
# ValuesFunction
def test_values_init():
func = ValuesFunction([0, 1, 2])
assert func.optional_value == 0
assert func.first_value == 0
def test_values_init_w_correct_optional_value():
func = ValuesFunction([0, 1, 2], optional_value=1)
assert func.optional_value == 1
assert func.first_value == 0
def test_values_init_w_correct_first_value():
func = ValuesFunction([0, 1, 2], first_value=1)
assert func.optional_value == 0
assert func.first_value == 1
def test_values_init_w_correct_optional_and_first_value():
func = ValuesFunction([0, 1, 2], optional_value=0, first_value=1)
assert func.optional_value == 0
assert func.first_value == 1
def test_values_init_w_empty_values():
with pytest.raises(ValueError):
func = ValuesFunction([])
def test_values_init_w_incorrect_optional_value():
with pytest.raises(ValueError):
func = ValuesFunction([0, 1, 2], optional_value=3)
def test_values_init_w_incorrect_first_value():
with pytest.raises(ValueError):
func = ValuesFunction([0, 1, 2], first_value=3)
def test_values_bump():
func = ValuesFunction([0, 5, 10])
assert func.bump(0) == 5
def test_values_bump():
func = ValuesFunction([0, 5, 10])
with pytest.raises(ValueError):
func.bump(10)
|