Beispiel #1
0
def test_max_split():
    field = ListField(
        [TextField(), TextField()],
        delimiters=[','],
        max_split=1,
    )
    assert field.parse('1,2,3') == ['1', '2,3']
def test_str_replace():
    field = TextField(
        none='x',
        str_replace={'-': ''},
        type=str,
    )
    assert field.parse('---') is None
    assert field.parse('a-b') == 'ab'
    assert field.parse('-x-') is None
Beispiel #3
0
def test_strip_column():
    field1 = ArrayField(
        TextField(),
        delimiters=[','],
    )
    assert field1.parse('a, b') == ['a', 'b']

    field2 = ArrayField(
        TextField(),
        delimiters=[','],
        strip_columns=False,
    )
    assert field2.parse('a, b') == ['a', ' b']
Beispiel #4
0
def test_array_field():
    field = ArrayField(
        TextField(),
        delimiters=[','],
    )
    assert field.parse('a') == ['a']
    assert field.parse('a,b') == ['a', 'b']
Beispiel #5
0
def test_from_right():
    field = ListField(
        [IntegerField(), TextField()],
        delimiters=['-'],
        from_right=True,
        max_split=1,
    )
    assert field.parse('x-1') == [1, 'x']
    assert field.parse('x-b-1') == [1, 'x-b']
def test_type_name():
    assert IntegerField().type_name == 'IntegerField'
    assert ArrayField(
        IntegerField(),
        delimiters=[','],
    ).type_name == 'ArrayField[IntegerField]'
    assert ListField(
        [IntegerField(), TextField()],
        delimiters=[','],
    ).type_name == 'ListField[IntegerField, TextField]'
def test_text_field():
    field = TextField()
    assert field.parse('abc') == 'abc'
Beispiel #8
0
def test_multiple_delimiters():
    field = ArrayField(
        TextField(),
        delimiters=[',', ';'],
    )
    assert field.parse('a,b;c') == ['a', 'b', 'c']