當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.drop方法代碼示例

本文整理匯總了Python中spendb.model.Dataset.drop方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.drop方法的具體用法?Python Dataset.drop怎麽用?Python Dataset.drop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在spendb.model.Dataset的用法示例。


在下文中一共展示了Dataset.drop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DatasetLoadTestCase

# 需要導入模塊: from spendb.model import Dataset [as 別名]
# 或者: from spendb.model.Dataset import drop [as 別名]
class DatasetLoadTestCase(unittest.TestCase):
    def setUp(self):
        make_test_app()
        self.ds = Dataset(SIMPLE_MODEL)
        self.engine = core.db.engine
        self.ds.generate()
        self.reader = csv.DictReader(StringIO(TEST_DATA))

    def tearDown(self):
        tear_down_test_app()

    def test_load_all(self):
        self.ds.load_all(self.reader)
        resn = self.engine.execute(self.ds.table.select()).fetchall()
        assert len(resn) == 6, resn
        row0 = resn[0]
        assert row0["time"] == "2010", row0.items()
        assert row0["amount"] == 200, row0.items()
        assert row0["field"] == "foo", row0.items()

    def test_flush(self):
        self.ds.load_all(self.reader)
        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_entity" in tn, tn
        assert "test_funny" in tn, tn
        self.ds.drop()
        tn = self.engine.table_names()
        assert "test_entry" not in tn, tn
        assert "test_entity" not in tn, tn
        assert "test_funny" not in tn, tn

    def test_aggregate_simple(self):
        self.ds.load_all(self.reader)
        res = self.ds.aggregate()
        assert res["summary"]["num_entries"] == 6, res
        assert res["summary"]["amount"] == 2690.0, res

    def test_aggregate_basic_cut(self):
        self.ds.load_all(self.reader)
        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):
        self.ds.load_all(self.reader)
        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):
        self.ds.load_all(self.reader)
        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):
        self.ds.load_all(self.reader)
        res = self.ds.aggregate(drilldowns=["function", "field"])
        # pprint(res)
        assert res["summary"]["num_entries"] == 6, res
        assert res["summary"]["amount"] == 2690, res
        assert len(res["drilldown"]) == 5, res["drilldown"]

    def test_materialize_table(self):
        self.ds.load_all(self.reader)
        itr = self.ds.materialize()
        tbl = list(itr)
        assert len(tbl) == 6, tbl
        row = tbl[0]
        assert isinstance(row["field"], unicode), row
        assert isinstance(row["function"], dict), row
        assert isinstance(row["to"], dict), row
開發者ID:pudo-attic,項目名稱:spendb.prototype,代碼行數:83,代碼來源:test_dataset.py


注:本文中的spendb.model.Dataset.drop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。