Esempio n. 1
0
def test_initialises_field():
    one = Field('one')
    assert one.name == 'one'
    assert one.mapping('some_string') == 'some_string'
    assert one.mapping('10') == '10'
    assert one.mapping(10) == '10'

    two = Field('two', 5)
    assert two.default == 5
    assert two.mapping(10) == 10
    assert two.mapping('10') == 10
    assert two.mapping(None) is None

    three = Field('three', 'default value')
    assert three.default == 'default value'
    assert three.mapping('10') == '10'
    assert three.mapping(10) == '10'
    assert three.mapping(None) is None

    four = Field('four', None, int)
    assert four.default is None
    assert four.mapping('10') == 10
    assert four.mapping(10) == 10
    assert four.mapping(None) is None
Esempio n. 2
0
def test_none_as_default_value_means_str_as_parser_by_default():
    f = Field('name', default=None)
    assert f.mapping('10') == '10'
    assert f.mapping([10]) == '[10]'