def test_bool_config_preserves_raw_str_value_used_to_set_it(): c = Item('a', type=bool, default=False) assert c.value is False assert not c.value assert c.str_value == 'False' assert c.value is False c.value = 'False' assert not c.value assert c.str_value == 'False' assert c.value is False c.value = 'no' assert not c.value assert c.str_value == 'no' assert c.value is False c.value = '0' assert not c.value assert c.str_value == '0' assert c.value is False c.value = '1' assert c.value assert c.str_value == '1' assert c.value is True c.reset() assert not c.value assert c.value is False c.value = 'yes' assert c.str_value == 'yes' assert c.value is True
def test_raw_str_value_is_reset_on_reset(): c = Item('a', type=int, default=25) assert c.str_value == '25' c.value = '23' assert c.str_value == '23' c.reset() assert c.str_value == '25'
def test_item_with_no_value_and_no_default_returns_not_set_as_value(): c = Item('a') assert c.value is not_set c.value = 'hey' assert c.value == 'hey' c.reset() assert c.value is not_set
def test_int_value(): c = Item('a', type=int, default=25) assert c.value == 25 c.value = '23' assert c.value == 23 assert c.value != '23' c.reset() assert c.value == 25
def test_is_default(): c = Item('a') d = Item('a', default=None) e = Item('a', value=None) assert c.is_default assert d.is_default assert not e.is_default c.value = 'ccc' d.value = 'ddd' e.value = 'eee' assert not c.is_default assert not d.is_default assert not e.is_default c.value = None d.value = None e.value = None assert not c.is_default assert d.is_default # this is the case when is_default is NOT the opposite of has_value assert not e.is_default c.reset() d.reset() e.reset() assert c.is_default assert d.is_default assert e.is_default
def test_has_value_returns_true_if_value_or_default_is_set(): c = Item() assert not c.has_value c.value = '5' assert c.has_value c.reset() assert not c.has_value d = Item(default=5) assert d.has_value d.value = 6 assert d.has_value d.reset() assert d.has_value e = Item(value=8) assert e.has_value e.value = 9 assert e.has_value e.reset() assert not e.has_value
def test_required_item_falls_back_to_default_when_there_is_one(): a = Item('a', required=True, default=None) assert a.value is None a.reset() assert a.value is None