예제 #1
0
def test_empty_validator_on_dict():
    v = Validator()
    assert v(Example()) == True
예제 #2
0
def test_single_int_incorrect_validator_on_dict():
    v = Validator({'a':{'type':'int'}})
    assert v({'a':'v'}) == False
예제 #3
0
def test_single_str_correct_validator_on_dict():
    v = Validator({'a':{'type':'str'}})
    assert v({'a':'abc'}) == True
예제 #4
0
def test_empty_validator():
    v = Validator()
    assert v({}) == True
    assert v({'a':123}) == True
예제 #5
0
def test_single_int_correct_validator_on_class():
    v = Validator({'a':{'type':'int'}})
    assert v(Example()) == True
예제 #6
0
def test_single_int_correct_validator_on_dict():
    v = Validator({'a':{'type':'int'}})
    assert v({'a':2}) == True
예제 #7
0
def test_validate_single_int_with_dict_single_int():
    v = Validator({'a':{'type':'int'}})
    assert v({'a':2}) == True
예제 #8
0
    v = Validator({'a':{'type':'int'}})
    assert v(Example()) == True

def test_single_int_incorrect_validator_on_dict():
    v = Validator({'a':{'type':'int'}})
    assert v({'a':'v'}) == False

def test_single_str_correct_validator_on_dict():
    v = Validator({'a':{'type':'str'}})
    assert v({'a':'abc'}) == True

if __name__ == "__main__":
    # small tests
    
    # test on an empty validator
    t = Validator()
    print(t(Example()))

    # create a validator v with some attributes
    v = Validator({'a':{'type':'int'}, 'b':{'type':'int'}})
    print(v)

    # option 1: pass in as dict
    print("v({'a':3, 'b':4}):", v({'a':3, 'b':4}))
    print("v({'a':3, 'b':'a'}):", v({'a':3, 'b':'a'}))
    
    # using class with attributes pulled with __dict__
    print("v(Example()):", v(Example()))
    print("v(Example(3, 'a')):", v(Example(3, 'a')))

    # Exception cases