Ejemplo n.º 1
0
def test_dump_with_quote():
    x = namedtuple('x', ['foo', 'bar', 'buz'])
    source = [
        x(foo='a "is" good', bar=1, buz=True),
        x(foo='"b"', bar=2, buz=False),
        x(foo='a "b"', bar=42, buz=False),
    ]
    expected_data = [
        'foo,bar,buz\n',
        '"a \\"is\\" good",1,True\n',
        '"\\"b\\"",2,False\n',
        '"a \\"b\\"",42,False\n',
    ]

    actual_data = []
    rx.from_(source).pipe(csv.dump(), ).subscribe(on_next=actual_data.append)

    assert actual_data == expected_data
Ejemplo n.º 2
0
def test_dump_no_header():
    x = namedtuple('x', ['foo', 'bar', 'buz'])
    source = [
        x(foo='a', bar=1, buz=True),
        x(foo='b', bar=2, buz=False),
        x(foo='ab', bar=42, buz=False),
    ]
    expected_data = [
        '"a",1,True\n',
        '"b",2,False\n',
        '"ab",42,False\n',
    ]

    actual_data = []
    rx.from_(source).pipe(
        csv.dump(header=False), ).subscribe(on_next=actual_data.append)

    assert actual_data == expected_data
Ejemplo n.º 3
0
def test_dump_pipe_separator():
    x = namedtuple('x', ['foo', 'bar', 'buz'])
    source = [
        x(foo='a', bar=1, buz=True),
        x(foo='b', bar=2, buz=False),
        x(foo='ab', bar=42, buz=False),
    ]
    expected_data = [
        'foo|bar|buz\n',
        '"a"|1|True\n',
        '"b"|2|False\n',
        '"ab"|42|False\n',
    ]

    actual_data = []
    rx.from_(source).pipe(
        csv.dump(separator='|'), ).subscribe(on_next=actual_data.append)

    assert actual_data == expected_data
Ejemplo n.º 4
0
def test_dump():
    x = namedtuple('x', ['foo', 'bar', 'buz'])
    source = [
        x(foo='a', bar=1, buz=True),
        x(foo='b', bar=2, buz=False),
        x(foo='ab', bar=42, buz=False),
        x(foo='cl', bar=None, buz=False),
        x(foo='cl', bar=[1, '2', "3"], buz=False),
    ]
    expected_data = [
        'foo,bar,buz\n',
        '"a",1,True\n',
        '"b",2,False\n',
        '"ab",42,False\n',
        '"cl",,False\n',
        '"cl","[1, \'2\', \'3\']",False\n',
    ]

    actual_data = []
    rx.from_(source).pipe(csv.dump(), ).subscribe(on_next=actual_data.append)

    assert actual_data == expected_data