Exemplo n.º 1
0
def test_load_ignore_error():
    parser = csv.create_line_parser(
        dtype=[
            ("foo", "int"),
            ("bar", "str"),
            ("buzz", "bool"),
        ],
        ignore_error=True,
    )

    actual_data = []
    error = None

    def on_error(e):
        nonlocal error
        error = e

    source = rx.from_([
        "a,the,True",
        "42,the,True",
        "07",
    ])
    source.pipe(csv.load(parser)).subscribe(
        on_next=actual_data.append,
        on_error=on_error,
    )

    assert error is None
    assert len(actual_data) == 1
    assert actual_data[0] == (42, 'the', True)
Exemplo n.º 2
0
def test_load_quoted():
    parser = csv.create_line_parser(dtype=[
        ("foo", "int"),
        ("bar", "str"),
    ])

    actual_data = process(
        rx.from_([
            '1,"the, quick"',
            '2,"\\"brown fox\\""',
            '3,"a\"$#ܟ<a;.b^F ^M^E^Aa^Bov^D^\"[^BƆm^A^Q^]#lx"',
            '4,""',
            '5,"\\"a\\",b"',
            '6,",ab"',
            '7,","',
        ]), [csv.load(parser)])

    assert len(actual_data) == 7
    assert actual_data[0] == (1, 'the, quick')
    assert actual_data[1] == (2, '"brown fox"')
    assert actual_data[2] == (3, 'a"$#ܟ<a;.b^F ^M^E^Aa^Bov^D^"[^BƆm^A^Q^]#lx')
    assert actual_data[3] == (4, '')
    assert actual_data[4] == (5, '"a",b')
    assert actual_data[5] == (6, ',ab')
    assert actual_data[6] == (7, ',')
Exemplo n.º 3
0
def test_load():
    parser = csv.create_line_parser(dtype=[
        ("foo", "int"),
        ("bar", "str"),
        ("buzz", "bool"),
    ])

    actual_data = process(
        rx.from_([
            "42,the,True",
            "07,quick,False",
            "08,,False",
        ]), [csv.load(parser)])

    assert len(actual_data) == 3
    assert actual_data[0] == (42, 'the', True)
    assert actual_data[1] == (7, 'quick', False)
    assert actual_data[2] == (8, '', False)