Example #1
0
def test_default():
    iv = Int(default=10)
    v = iv.validate(name='alpha', defined=True, value=2)
    assert v == 2
    v = iv.validate(name='alpha', defined=False, value=None)
    assert v == 10
    v = iv.validate(name='alpha', defined=True, value=3)
    assert v == 3
Example #2
0
def test_default_min():
    iv = Int(default=10, min=3)
    with pytest.raises(MinValueError):
        v = iv.validate(name='alpha', defined=True, value=2)
    v = iv.validate(name='alpha', defined=True, value=3)
    assert v == 3
    v = iv.validate(name='alpha', defined=False, value=None)
    assert v == 10
def test_basic():
    iv = Int()
    v = iv.validate(name='alpha', defined=True, value=2)
    assert v == 2
    v = iv.validate(name='alpha', defined=True, value=-2000)
    assert v == -2000
    with pytest.raises(MissingRequiredOptionError):
        v = iv.validate(name='alpha', defined=False, value=None)
Example #4
0
def test_default_min():
    iv = Int(default=10, min=3)
    with pytest.raises(MinValueError):
        v = iv.validate(name='alpha', defined=True, value=2)
    v = iv.validate(name='alpha', defined=True, value=3)
    assert v == 3
    v = iv.validate(name='alpha', defined=False, value=None)
    assert v == 10
Example #5
0
def test_default():
    iv = Int(default=10)
    v = iv.validate(name='alpha', defined=True, value=2)
    assert v == 2
    v = iv.validate(name='alpha', defined=False, value=None)
    assert v == 10
    v = iv.validate(name='alpha', defined=True, value=3)
    assert v == 3
Example #6
0
def test_basic():
    iv = Int()
    v = iv.validate(name='alpha', defined=True, value=2)
    assert v == 2
    v = iv.validate(name='alpha', defined=True, value=-2000)
    assert v == -2000
    with pytest.raises(InvalidTypeError):
        v = iv.validate(name='alpha', defined=True, value=2.0)
    with pytest.raises(MissingRequiredOptionError):
        v = iv.validate(name='alpha', defined=False, value=None)
def test_non_int_value(non_int_value):
    iv = Int()
    with pytest.raises(InvalidTypeError):
        v = iv.validate(name='alpha', defined=True, value=non_int_value)
Example #8
0
def test_bad_max_type():
    with pytest.raises(MaxValueError):
        iv = Int(default=101, max=100)
Example #9
0
def test_bad_min_type():
    with pytest.raises(MinValueError):
        iv = Int(default=2, min=3)
Example #10
0
def test_bad_default_max():
    with pytest.raises(InvalidTypeError):
        iv = Int(max=4.5)
Example #11
0
def test_bad_default_type():
    with pytest.raises(InvalidTypeError):
        iv = Int(default='ten')