def pytest_runtest_makereport(item, call): """Pytest hook for report preparation. Submit tests' data to a database. """ run_id = item.config.getoption("db_submit") if not run_id: yield return db_url = item.config.getoption("db_url") db_name = item.config.getoption("db_name") db_collection = item.config.getoption("db_collection") instance = item.funcargs["instance"] # alias report = (yield).get_result() if call.when in ["setup", "call"]: if call.when == "call": if not report.passed: instance["db"]["status"] = "failed" instance["db"]["error_msg"] = report.longrepr.reprcrash.message else: instance["db"]["status"] = "passed" instance["db"]["results"] = instance["results"] instance["db"]["raw_results"] = instance["raw_results"] logging.info(f"Upload data to {db_url}/{db_name}.{db_collection}. " f"Data: {instance['db']}") upload_data(instance["db"], db_url, db_name, db_collection)
def pytest_runtest_makereport(item, call): """Pytest hook for report preparation. Submit tests' data to a database. """ run_id = item.config.getoption("db_submit") if not run_id: yield return data = item._request.test_info["db_info"].copy() data["results"] = item._request.test_info["results"].copy() data["raw_results"] = item._request.test_info["raw_results"].copy() data["cpu_info"] = get_cpu_info() data["status"] = "not_finished" data["error_msg"] = "" report = (yield).get_result() if call.when in ["setup", "call"]: if call.when == "call": if not report.passed: data["status"] = "failed" data["error_msg"] = report.longrepr.reprcrash.message else: data["status"] = "passed" db_url = item.config.getoption("db_url") db_collection = item.config.getoption("db_collection") logging.info(f"Upload data to {db_url}/{'timetests'}.{db_collection}. " f"Data: {data}") upload_data(data, db_url, 'timetests', db_collection)
def get_experiment(experiment_id): if request.method == "POST": if request.data: try: loads_value = json.loads(request.data.decode('utf8')) to_upload = {"result": loads_value} utils.upload_data(db, to_upload, experiment_id) doc_ref = db.collection(u'Experiments').document(experiment_id) experiment = doc_ref.get().to_dict() update = {'count': experiment['count'] + 1} doc_ref.update(update) except Exception as e: print(e) else: doc_ref = db.collection(u'Experiments').document(experiment_id) experiment = doc_ref.get().to_dict() try_count = 0 while try_count < 5: try: if experiment: timeline = utils.organize_by_blocks( experiment['timeline'], experiment['count'], bucket, experiment['name']) return render_template( 'experiment_html.html', title='Experiment', timeline=timeline, background_color=experiment['background_color']) except Exception as e: print(e) continue finally: try_count += 1 return render_template('experiment_does_not_exist.html', title='Psychology Experiment')
def upload_data(self, filepath): try: f = open(filepath, 'rb') files = {'datafile': f} except: print u"Can not open file at: ".format(filepath) return False utils.upload_data(files, self.__cookies)
def upload_data(self, filepath): try: f = open(filepath, 'rb') files = {'datafile': f} except: print( u"Can not open file at: ".format(filepath) ) return False utils.upload_data(files, self.__cookies)
def run(self): try: print "Connection from : " + self.ip + ":" + str(self.port) welcome = """ Welcome to e3 storage interface. This is a beta version so bare with us :) Storage costs are as cheap as Rs.1 per byte ;). Note: * The bytes used are calculated after zlib compression. * The storage used by the metadata is also charged """ menu = """ Choose option 1) Upload (Max of 1024 bytes) 2) Download 3) Exit """ self.socket.send(welcome) while True: self.socket.send(menu) option = self.socket.recv(5).strip() if option == "1": self.socket.send("Input data..\n") data = self.socket.recv(1024).strip() self.msg["msg"] = data data = json.dumps(self.msg) cost = utils.upload_data(data) self.socket.send("Cost:" + str(cost) + "\n") elif option == "2": self.socket.send( "Ooops. Download not implemented yet in beta version\n" ) else: self.socket.send("Bye\n") self.socket.close() return except Exception as e: print e return
def run(self): try: print "Connection from : "+self.ip+":"+str(self.port) welcome = """ Welcome to e3 storage interface. This is a beta version so bare with us :) Storage costs are as cheap as Rs.1 per byte ;). Note: * The bytes used are calculated after zlib compression. * The storage used by the metadata is also charged """ menu = """ Choose option 1) Upload (Max of 1024 bytes) 2) Download 3) Exit """ self.socket.send(welcome) while True: self.socket.send(menu) option = self.socket.recv(5).strip() if option == "1": self.socket.send("Input data..\n") data = self.socket.recv(1024).strip() self.msg["msg"] = data data = json.dumps(self.msg) cost = utils.upload_data(data) self.socket.send("Cost:" + str(cost) + "\n") elif option == "2": self.socket.send("Ooops. Download not implemented yet in beta version\n") else: self.socket.send("Bye\n") self.socket.close() return except Exception as e: print e return