Example #1
0
def test_resource_existing_carray():
    with tmpfile('.bcolz') as fn:
        r = resource(fn, dshape='var * int32')
        append(r, [1, 2, 3])
        r.flush()
        newr = resource(fn)
        assert isinstance(newr, carray)
Example #2
0
def test_resource_shape():
    with tmpfile('.bcolz') as fn:
        assert resource(fn, dshape='10 * int').shape == (10,)
    with tmpfile('.bcolz') as fn:
        assert resource(fn, dshape='10 * 10 * int').shape == (10, 10)
    with tmpfile('.bcolz') as fn:
        assert resource(fn, dshape='var * 10 * int').shape == (0, 10)
Example #3
0
def test_resource_existing_carray():
    with tmpfile('.bcolz') as fn:
        os.remove(fn)
        r = resource(fn, dshape=discover(y))
        append(r, y)
        r.flush()

        r2 = resource(fn)
        assert eq(r2[:], y)
Example #4
0
def test_resource_carray():
    with tmpfile('.bcolz') as fn:
        r = resource(fn, dshape='var * int32')

        assert isinstance(r, carray)
        assert r.dtype == 'i4'
        assert r.shape == (0,)
Example #5
0
def test_resource_ctable():
    with tmpfile('.bcolz') as fn:
        r = resource(fn,
                     dshape='var * {name: string[5, "ascii"], balance: int32}')

        assert isinstance(r, ctable)
        assert r.dtype == [('name', 'S5'), ('balance', 'i4')]
Example #6
0
def test_drop():
    with tmpfile('.bcolz') as fn:
        r = resource(fn, dshape='var * {name: string[5, "ascii"], balance: int32}')

        assert os.path.exists(fn)
        drop(fn)
        assert not os.path.exists(fn)
Example #7
0
def test_resource_existing_ctable():
    with tmpfile('.bcolz') as fn:
        r = into(fn, y)
        r.flush()

        r2 = resource(fn)
        assert eq(r2[:], y)
Example #8
0
def test_resource_ctable_correctly_infers_length():
    with tmpfile('.bcolz') as fn:
        r = resource(fn, dshape='100 * int32')

        assert isinstance(r, carray)
        assert r.dtype == 'i4'
        assert get_expectedlen(r) == 100
Example #9
0
def test_resource_ctable_correctly_infers_length():
    with tmpfile('.bcolz') as fn:
        r = resource(fn,
                     dshape='100 * {name: string[5, "ascii"], balance: int32}')

        assert isinstance(r, ctable)
        assert r.dtype == [('name', 'S5'), ('balance', 'i4')]
        assert all(get_expectedlen(r[c]) == 100 for c in r.names)
Example #10
0
def test_resource_carray_overrides_expectedlen():
    with tmpfile('.bcolz') as fn:
        r = resource(fn, dshape='100 * int32', expectedlen=200)

        assert isinstance(r, carray)
        assert r.dtype == 'i4'
        assert r.shape == (100,)
        assert get_expectedlen(r) == 200
Example #11
0
def tmpbcolz(*args, **kwargs):
    fn = '.%s.bcolz' % str(uuid.uuid1())
    r = resource(fn, *args, **kwargs)

    try:
        yield r
    finally:
        with ignoring(Exception):
            r.flush()
        if os.path.exists(fn):
            shutil.rmtree(fn)
Example #12
0
def test_resource_existing_carray():
    with tmpbcolz(dshape='var * int32') as r:
        append(r, [1, 2, 3])
        r.flush()
        newr = resource(r.rootdir)
        assert isinstance(newr, carray)