def test_set_attr_success(mocked):
    values = (100, 23, -23)
    mocked.return_value = values
    for selector in (max, min):
        for v in values:
            obj = Object()
            _setattr(
                obj, value=v, regex="blah", selector=selector, value_name="test_value"
            )
            assert obj.test_value == v
def test_set_attr_default(mocked):
    values = (100, 23, -23)
    mocked.return_value = values
    obj = Object()
    _setattr(obj, value=None, regex="blah", selector=min, value_name="test_value")
    assert obj.test_value == -23

    obj = Object()
    _setattr(obj, value=None, regex="blah", selector=max, value_name="test_value")
    assert obj.test_value == 100
def test_set_attr_success(mocked):
    allowed = (100, 23, -23)
    not_allowed = ('a', '23', 101)
    mocked.return_value = allowed
    for selector in (max, min, _middle):
        for v in not_allowed:
            with pytest.raises(ValueError):
                obj = Object()
                _setattr(obj, value=v,
                         regex='blah',
                         selector=selector,
                         value_name='test_value')