本文整理汇总了Python中openspending.model.dataset.Dataset.flush方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.flush方法的具体用法?Python Dataset.flush怎么用?Python Dataset.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openspending.model.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDatasetLoad
# 需要导入模块: from openspending.model.dataset import Dataset [as 别名]
# 或者: from openspending.model.dataset.Dataset import flush [as 别名]
class TestDatasetLoad(DatabaseTestCase):
def setup(self):
super(TestDatasetLoad, self).setup()
self.ds = Dataset(model_fixture('simple'))
self.ds.generate()
self.engine = db.engine
def test_load_all(self):
load_dataset(self.ds)
resn = self.engine.execute(self.ds.table.select()).fetchall()
assert len(resn) == 6, resn
row0 = resn[0]
assert row0['amount'] == 200, row0.items()
assert row0['field'] == 'foo', row0.items()
def test_flush(self):
load_dataset(self.ds)
resn = self.engine.execute(self.ds.table.select()).fetchall()
assert len(resn) == 6, resn
self.ds.flush()
resn = self.engine.execute(self.ds.table.select()).fetchall()
assert len(resn) == 0, resn
def test_drop(self):
tn = self.engine.table_names()
assert 'test__entry' in tn, tn
assert 'test__to' in tn, tn
assert 'test__function' in tn, tn
self.ds.drop()
tn = self.engine.table_names()
assert 'test__entry' not in tn, tn
assert 'test__to' not in tn, tn
assert 'test__function' not in tn, tn
def test_dataset_count(self):
load_dataset(self.ds)
assert len(self.ds) == 6, len(self.ds)
def test_aggregate_simple(self):
load_dataset(self.ds)
res = self.ds.aggregate()
assert res['summary']['num_entries'] == 6, res
assert res['summary']['amount'] == 2690.0, res
def test_aggregate_basic_cut(self):
load_dataset(self.ds)
res = self.ds.aggregate(cuts=[('field', u'foo')])
assert res['summary']['num_entries'] == 3, res
assert res['summary']['amount'] == 1000, res
def test_aggregate_or_cut(self):
load_dataset(self.ds)
res = self.ds.aggregate(cuts=[('field', u'foo'),
('field', u'bar')])
assert res['summary']['num_entries'] == 4, res
assert res['summary']['amount'] == 1190, res
def test_aggregate_dimensions_drilldown(self):
load_dataset(self.ds)
res = self.ds.aggregate(drilldowns=['function'])
assert res['summary']['num_entries'] == 6, res
assert res['summary']['amount'] == 2690, res
assert len(res['drilldown']) == 2, res['drilldown']
def test_aggregate_two_dimensions_drilldown(self):
load_dataset(self.ds)
res = self.ds.aggregate(drilldowns=['function', 'field'])
assert res['summary']['num_entries'] == 6, res
assert res['summary']['amount'] == 2690, res
assert len(res['drilldown']) == 5, res['drilldown']
def test_aggregate_by_attribute(self):
load_dataset(self.ds)
res = self.ds.aggregate(drilldowns=['function.label'])
assert len(res['drilldown']) == 2, res['drilldown']
def test_aggregate_two_attributes_same_dimension(self):
load_dataset(self.ds)
res = self.ds.aggregate(drilldowns=['function.name', 'function.label'])
assert len(res['drilldown']) == 2, res['drilldown']
def test_materialize_table(self):
load_dataset(self.ds)
itr = self.ds.entries()
tbl = list(itr)
assert len(tbl) == 6, len(tbl)
row = tbl[0]
assert isinstance(row['field'], unicode), row
assert isinstance(row['function'], dict), row
assert isinstance(row['to'], dict), row