本文整理汇总了Python中model.Session.bulk_insert_mappings方法的典型用法代码示例。如果您正苦于以下问题:Python Session.bulk_insert_mappings方法的具体用法?Python Session.bulk_insert_mappings怎么用?Python Session.bulk_insert_mappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Session
的用法示例。
在下文中一共展示了Session.bulk_insert_mappings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LogHandlerTests
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import bulk_insert_mappings [as 别名]
class LogHandlerTests(reader.LogHandler):
def __init__(self):
self.session = Session()
self.tests = {(item.test, item.subtest) for item in self.session.query(Test)}
self.new_tests = []
def _insert_test(self, test, subtest):
if (test, subtest) not in self.tests:
test_obj = {"test": test,
"subtest": subtest}
self.new_tests.append(test_obj)
self.tests.add((test, subtest))
def test_status(self, data):
test = self._insert_test(data["test"], data["subtest"])
def test_end(self, data):
self._insert_test(data["test"], None)
sys.stdout.write("-")
sys.stdout.flush()
def suite_end(self, data):
self.session.bulk_insert_mappings(Test, self.new_tests)
self.session.commit()
sys.stdout.write(" committing\n")
示例2: LogHandlerResults
# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import bulk_insert_mappings [as 别名]
class LogHandlerResults(reader.LogHandler):
def __init__(self, run_name):
self.session = Session()
self.run = None
self.status = {item.name: item.id for item in self.session.query(Status)}
self.tests = {(item.test, item.subtest): item.id for item in self.session.query(Test)}
self.results = None
self.run, _ = get_or_create(self.session, Run, name=run_name)
self.new_results = {}
self.update_results = {}
def _insert_result(self, test_id, status_id):
result = {"run_id": self.run.id,
"test_id": test_id,
"status_id": status_id}
result_id = (self.run.id, test_id)
target = self.new_results if test_id not in self.results else self.update_results
target[result_id] = result
def suite_start(self, data):
self.run.info = json.dumps(data["run_info"])
self.results = {item.test_id
for item in self.session.query(Result).filter(Run.id == self.run.id)}
def test_status(self, data):
test_id = self.tests[(data["test"], data["subtest"])]
status_id = self.status[data["status"]]
self._insert_result(test_id, status_id)
def test_end(self, data):
test_id = self.tests[(data["test"], None)]
status_id = self.status[data["status"]]
self._insert_result(test_id, status_id)
sys.stdout.write(".")
sys.stdout.flush()
def suite_end(self, data):
sys.stdout.write(" committing\n")
self.session.bulk_insert_mappings(Result, self.new_results.values())
self.session.bulk_update_mappings(Result, self.update_results.values())
self.session.commit()