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)
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)
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)
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,)
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')]
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)
def test_resource_existing_ctable(): with tmpfile('.bcolz') as fn: r = into(fn, y) r.flush() r2 = resource(fn) assert eq(r2[:], y)
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
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)
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
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)
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)