Ejemplo n.º 1
0
def test_default_min_len():
    iv = Str(default="abcd", min_len=3)
    with pytest.raises(MinLengthError):
        v = iv.validate(name='alpha', defined=True, value="x")
    v = iv.validate(name='alpha', defined=True, value="xxx")
    assert v == "xxx"
    v = iv.validate(name='alpha', defined=False, value=None)
    assert v == "abcd"
Ejemplo n.º 2
0
def test_basic():
    sv = Str()
    v = sv.validate(name='alpha', defined=True, value='abc')
    assert v == 'abc'
    v = sv.validate(name='alpha', defined=True, value=' fg ')
    assert v == ' fg '
    v = sv.validate(name='alpha', defined=True, value='2')
    assert v == '2'
    with pytest.raises(MissingRequiredOptionError):
        v = sv.validate(name='alpha', defined=False, value=None)
Ejemplo n.º 3
0
def test_basic():
    sv = Str()
    v = sv.validate(name='alpha', defined=True, value='abc')
    assert v == 'abc'
    v = sv.validate(name='alpha', defined=True, value=' fg ')
    assert v == ' fg '
    v = sv.validate(name='alpha', defined=True, value='2')
    assert v == '2'
    with pytest.raises(InvalidTypeError):
        v = sv.validate(name='alpha', defined=True, value=2.0)
    with pytest.raises(MissingRequiredOptionError):
        v = sv.validate(name='alpha', defined=False, value=None)
Ejemplo n.º 4
0
def test_default():
    sv = Str(default='x.dat')
    v = sv.validate(name='alpha', defined=True, value='a.dat')
    assert v == 'a.dat'
    v = sv.validate(name='alpha', defined=False, value=None)
    assert v == 'x.dat'
Ejemplo n.º 5
0
def test_non_str_value(non_str_value):
    sv = Str()
    with pytest.raises(InvalidTypeError):
        v = sv.validate(name='alpha', defined=True, value=non_str_value)