def test_drop(): with tmpfile('.bson') as fn: bs = BSON(fn) append(bs, dat) assert os.path.exists(fn) drop(bs) assert not os.path.exists(fn)
def test_read_gzip(): with tmpfile('.bson.gz') as fn: f = gzip.open(fn, 'wb') for item in dat: f.write(bson.BSON.encode(item)) f.close() b = BSON(fn) assert convert(list, b) == dat
def test_missing_to_csv(): data = [dict(a=1, b=2), dict(a=2, c=4)] with tmpfile('.bson') as fn: bs = BSON(fn) bs = odo(data, bs) with tmpfile('.csv') as csvf: csv = odo(bs, csvf) with open(csv.path, 'rt') as f: result = f.read() expected = 'a,b,c\n1,2.0,\n2,,4.0\n' assert result == expected
def test_convert_bson_list(): with bson_file(dat) as fn: b = BSON(fn) assert convert(list, b) == dat
def test_append_bson(): with tmpfile('.bson') as fn: b = BSON(fn) append(b, dat) assert convert(list, b) == dat
def test_discover_bson(): with bson_file(dat) as fn: b = BSON(fn) assert discover(b) == discover(dat)
def test_write_gzip(): with tmpfile('.bson.gz') as fn: b = BSON(fn) append(b, dat) assert convert(list, b) == dat