Beispiel #1
0
def test_encoding():
    stdin = '\n'
    val = runb(stdin, 'bsv')
    bsv = b''
    assert bsv == val
    assert stdin == run(stdin, 'bsv | csv')

    stdin = """
    a
    """
    val = runb(rm_whitespace(stdin), 'bsv')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 6
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 0),  # uint16 max, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        b'a\0'
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = """
    a,bb,ccc
    """
    val = runb(rm_whitespace(stdin), 'bsv')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 17
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 2),  # uint16 max, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        struct.pack('H', 2),  # uint16 sizes, see load.h
        struct.pack('H', 3),  # uint16 sizes, see load.h
        b'a\0bb\0ccc\0',
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = '\n'
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')
Beispiel #2
0
 def test_props_python_write(arg):
     buffers, csv = arg
     csv[:1024 * 1024 *
         5]  # slice to buffer size which is max python write supports
     bytes_io = io.BytesIO()
     data = [row.split(b',') for row in csv.encode('utf-8').split(b'\n')]
     bsv.dump(bytes_io, data)
     assert expected(csv) == runb(bytes_io.getvalue(),
                                  'csv').decode('utf-8').rstrip()
Beispiel #3
0
def test_example1():
    csv = ',\n'
    val = runb(csv, 'bsv')
    bsv = b''.join([
        struct.pack(
            'i', 8
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        struct.pack('H', 1),  # uint16 max, see load.h
        struct.pack('H', 0),  # uint16 sizes, see load.h
        struct.pack('H', 0),  # uint16 sizes, see load.h
        b'\0\0',
    ])
    assert bsv == val
    assert csv == run(csv, 'bsv | csv')
Beispiel #4
0
def test_encoding():
    stdin = '\n'
    val = runb(stdin, 'bsv')
    bsv = b''
    assert bsv == val
    assert stdin == run(stdin, 'bsv | csv')

    stdin = """
    a
    """
    val = runb(rm_whitespace(stdin), 'bsv')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 6 + 1
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 0),  # uint16 max, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        b'a\0'
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = """
    a,bb,ccc
    """
    val = runb(rm_whitespace(stdin), 'bsv')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 17 + 3
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 2),  # uint16 max, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        struct.pack('H', 2),  # uint16 sizes, see load.h
        struct.pack('H', 3),  # uint16 sizes, see load.h
        b'a\0bb\0ccc\0',
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = """
    a,12,1.500000
    """
    val = runb(rm_whitespace(stdin), 'bsv')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 28 + 3
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 2),  # uint16 max, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('B', 1),  # uint8 types, see load.h
        struct.pack('B', 2),  # uint8 types, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        struct.pack('H', 8),  # uint16 sizes, see load.h
        struct.pack('H', 8),  # uint16 sizes, see load.h
        b'a\0',
        struct.pack('q', 12) + b'\0',
        struct.pack('d', 1.5) + b'\0',
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = """
    a
    """
    val = run(rm_whitespace(stdin), 'bsv')
    val = bytes(val, 'utf-8')
    bsv = b''.join([
        # chunk header
        struct.pack(
            'i', 6 + 1
        ),  # uint32 num bytes in this chunk, chunks contain 1 or more rows
        # chunk body
        struct.pack('H', 0),  # uint16 max, see load.h
        struct.pack('B', 0),  # uint8 types, see load.h
        struct.pack('H', 1),  # uint16 sizes, see load.h
        b'a\0',
    ])
    assert bsv == val
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')

    stdin = '\n'
    assert rm_whitespace(stdin) + '\n' == run(rm_whitespace(stdin),
                                              'bsv | csv')
Beispiel #5
0
 def test_props_python_read(arg):
     buffers, csv = arg
     assert expected(csv) + '\n' == '\n'.join(','.join(
         v.decode('utf-8') if isinstance(v, bytes) else str(v)
         for v in row) for row in bsv.load(
             io.BytesIO(runb(csv, f'bsv.{buffers}')))) + '\n'