Best Python code snippet using avocado_python
test_status_repo.py
Source:test_status_repo.py
...28 def test_handle_task_started(self):29 msg = {"id": "1-foo", "status": "started", "output_dir": "/fake/path"}30 self.status_repo._handle_task_started(msg)31 self.assertEqual(32 self.status_repo.get_all_task_data("1-foo"),33 [{"status": "started", "output_dir": "/fake/path"}],34 )35 def test_handle_task_started_no_output_dir(self):36 msg = {"id": "1-foo", "status": "started"}37 with self.assertRaises(repo.StatusMsgMissingDataError):38 self.status_repo._handle_task_started(msg)39 def test_handle_task_finished_no_result(self):40 msg = {"id": "1-foo", "status": "finished"}41 self.status_repo._handle_task_finished(msg)42 self.assertEqual(43 self.status_repo.get_all_task_data("1-foo"), [{"status": "finished"}]44 )45 self.assertEqual(self.status_repo._by_result.get(None), ["1-foo"])46 def test_handle_task_finished_result(self):47 msg = {"id": "1-foo", "status": "finished", "result": "pass"}48 self.status_repo._handle_task_finished(msg)49 self.assertEqual(50 self.status_repo.get_all_task_data("1-foo"),51 [{"status": "finished", "result": "pass"}],52 )53 self.assertEqual(self.status_repo._by_result.get("pass"), ["1-foo"])54 def test_process_message_running(self):55 msg = {56 "id": "1-foo",57 "status": "running",58 "job_id": "0000000000000000000000000000000000000000",59 }60 self.status_repo.process_message(msg)61 self.assertEqual(62 self.status_repo.get_all_task_data("1-foo"), [{"status": "running"}]63 )64 def test_process_raw_message_task_started(self):65 msg = (66 '{"id": "1-foo", "status": "started", '67 '"output_dir": "/fake/path", '68 '"job_id": "0000000000000000000000000000000000000000"}'69 )70 self.status_repo.process_raw_message(msg)71 self.assertEqual(72 self.status_repo.get_all_task_data("1-foo"),73 [{"status": "started", "output_dir": "/fake/path"}],74 )75 def test_process_raw_message_task_running(self):76 msg = (77 '{"id": "1-foo", "status": "running", '78 '"job_id": "0000000000000000000000000000000000000000"}'79 )80 self.status_repo.process_raw_message(msg)81 self.assertEqual(82 self.status_repo.get_all_task_data("1-foo"), [{"status": "running"}]83 )84 def test_process_messages_running(self):85 msg = {86 "id": "1-foo",87 "status": "running",88 "time": 1597894378.6080744,89 "job_id": "0000000000000000000000000000000000000000",90 }91 self.status_repo.process_message(msg)92 msg = {93 "id": "1-foo",94 "status": "running",95 "time": 1597894378.6103745,96 "job_id": "0000000000000000000000000000000000000000",...
repo.py
Source:repo.py
...67 task_id = message.pop("id")68 if task_id not in self._all_data:69 self._all_data[task_id] = []70 self._all_data[task_id].append(message)71 def get_all_task_data(self, task_id):72 """Returns all data on a given task, by its ID."""73 return self._all_data.get(task_id)74 def get_task_data(self, task_id, index):75 """Returns the data on the index of a given task, by its ID."""76 task_data = self._all_data.get(task_id)77 return task_data[index]78 def get_latest_task_data(self, task_id):79 """Returns the latest data on a given task, by its ID."""80 task_data = self._all_data.get(task_id)81 if task_data is None:82 return None83 return task_data[-1]84 def status_journal_summary_pop(self):85 return heapq.heappop(self._status_journal_summary)86 def _update_status(self, message):87 """Update the latest status of a task (by message)."""88 task_id = message.get("id")89 status = message.get("status")90 time = message.get("time")91 if not all((task_id, status, time)):92 return93 if task_id not in self._status:94 self._status[task_id] = (status, time)95 heapq.heappush(self._status_journal_summary, (time, task_id, status, 0))96 else:97 current_status, _ = self._status[task_id]98 if current_status == "finished":99 LOG.warning(100 "Received a %s message after finished message: %s", status, message101 )102 elif status == "started":103 LOG.warning(104 "Received a started message when the status " "is already %s: %s",105 current_status,106 message,107 )108 else:109 self._status[task_id] = (status, time)110 index = len(self.get_all_task_data(task_id))111 heapq.heappush(self._status_journal_summary, (time, task_id, status, index))112 def process_message(self, message):113 for required_field in ("id", "job_id"):114 if required_field not in message:115 raise StatusMsgMissingDataError(required_field)116 job_id = message.get("job_id")117 if job_id != self.job_id:118 LOG.warning("Received a message destined for a different job: %s", message)119 return120 message.pop("job_id")121 self._update_status(message)122 handlers = {123 "started": self._handle_task_started,124 "finished": self._handle_task_finished,...
rosetta_code_scraper.py
Source:rosetta_code_scraper.py
...48 # print("Language: {}".format(language_formatted))49 # print("Code: {}".format(code_formatted))50 # print("")51 return task_data52def get_all_task_data(languages, task_links):53 with open('coding_data.csv', 'a') as f:54 code_writer = csv.writer(f, delimiter=',')55 all_task_data = []56 for task_link in task_links:57 task_data = get_task_data(task_link, languages)58 for lang in task_data:59 code_writer.writerow(lang)60 all_task_data += task_data61 return all_task_data62def main():63 t0 = time.time()64 languages = ['C', 'C#', 'Common Lisp', 'Clojure',65 'Haskell', 'Java', 'JavaScript', 'OCaml',66 'Perl', 'PHP', 'Python', 'Ruby', 'Scala', 'Scheme', 'Tcl']67 all_task_data = get_all_task_data(languages, get_task_links())68 print(len(all_task_data))69 t1 = time.time()70 total = t1-t071 print(total)72if __name__ in "__main__":...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!