Best Python code snippet using slash
test_error_object.py
Source:test_error_object.py
...11def test_error_exception_str_repr(error):12 assert "NotImplementedError" in str(error)13 assert "NotImplementedError" in repr(error)14def test_detailed_exception(error):15 assert error.get_detailed_str()16 assert 'NotImplementedError' in error.get_detailed_str()17def test_error_filename(error):18 assert error.filename == without_pyc(os.path.abspath(__file__))19def test_error_func_name(error):20 assert error.func_name == "func_3"21def test_code_string(error):22 assert error.cause.code_line == " raise NotImplementedError()"23 assert error.cause.code_string == """def func_3():24 local_func_3 = global_func_325 raise NotImplementedError()\n"""26def test_error_exc_info(error):27 assert error.exc_info is not None28 assert isinstance(error.exc_info, tuple)29 assert error.exc_info[0] is NotImplementedError30 assert isinstance(error.exc_info[1], NotImplementedError)31 assert isinstance(error.exc_info[2], types.TracebackType)32def test_error_forget_exc_info(error):33 error.forget_exc_info()34 assert error.exc_info is None35def test_error_exc_info_forgotten_by_default(suite, suite_test):36 suite_test.when_run.error()37 res = suite.run()[suite_test]38 [err] = res.get_errors()39 assert err.exc_info is None40def test_error_frame_objects(error):41 assert error.traceback.frames42 for f in error.traceback.frames:43 assert isinstance(f.python_frame, types.FrameType)44def test_error_frame_objects_forgotten_by_default(suite, suite_test):45 suite_test.when_run.error()46 res = suite.run()[suite_test]47 [err] = res.get_errors()48 assert err.traceback.frames49 for frame in err.traceback.frames:50 assert frame.python_frame is None51@pytest.mark.usefixtures('disable_vintage_deprecations')52def test_frame_locals(error):53 assert error.traceback.frames[-3].locals == {54 "local_func_1": {55 "value": "'global_func_1'"56 }}57def test_to_list(error):58 serialized = error.traceback.to_list()59 assert serialized[-3]['locals'] == {60 "local_func_1": {61 "value": "'global_func_1'"62 }}63 # Just make sure that it's serializable64 json.dumps(serialized)65@pytest.mark.usefixtures('disable_vintage_deprecations')66def test_frame_locals_no_assertion_markers(assertion_error):67 for var_name, _ in assertion_error.cause.locals.items():68 assert "@" not in var_name69@pytest.mark.usefixtures('disable_vintage_deprecations')70def test_frame_globals(error):71 assert error.traceback.frames[-3].globals == {72 "global_func_1": {73 "value": "'global_func_1'"74 }}75def test_capture_exception_twice_caches_object():76 try:77 try:78 raise RuntimeError()79 except RuntimeError:80 err1 = Error.capture_exception()81 raise82 except RuntimeError:83 err2 = Error.capture_exception()84 assert err1 is err285def test_detailed_traceback(error):86 detailed = error.get_detailed_str()87 assert detailed88def test_error_is_fatal(error):89 assert not error.is_fatal()90def test_error_mark_fatal(error):91 rv = error.mark_fatal()92 assert rv is error93 assert error.is_fatal()94def test_error_frame_correction():95 class CustomException(Exception):96 pass97 def f():98 g()99 def g():100 h()...
evaluate.py
Source:evaluate.py
...10 self.gold = ReaderGetterConf()11 self.pred = ReaderGetterConf()12 self.result_file = "" # file to output details13 self.econf: EvalConf = None14 self.print_details = True # whether print get_detailed_str()15def main(evaluator: str, *args):16 # find evaluator17 conf = MainConf()18 e_res = Evaluator.try_load_and_lookup(evaluator)19 one_conf, one_type = e_res.conf, e_res.T20 conf.econf = one_conf()21 # --22 conf = init_everything(conf, args)23 zlog(f"Ready to evaluate with {evaluator}: {conf.gold} {conf.pred}")24 # --25 gold_insts = list(conf.gold.get_reader())26 pred_insts = list(conf.pred.get_reader())27 evaler: Evaluator = one_type(conf.econf)28 res = evaler.eval(gold_insts, pred_insts)29 if conf.result_file:30 with zopen(conf.result_file, 'a') as fd: # note: here we use append mode31 fd.write(f"# Eval with {args}:\n{res.get_brief_str()}\n{res.get_detailed_str()}\n")32 zlog(f"Eval on {conf.gold} vs. {conf.pred}; RESULT = {res}")33 if conf.print_details:34 zlog(f"#-- details:\n{res.get_detailed_str()}")35# PYTHONPATH=../src/ python3 -m msp2.cli.evaluate <??> gold.input_path:? pred.input_path:?36if __name__ == '__main__':...
base.py
Source:base.py
...19# --20class EvalResult:21 def get_result(self) -> float: raise NotImplementedError()22 def get_brief_str(self) -> str: raise NotImplementedError()23 def get_detailed_str(self) -> str: raise NotImplementedError()24 def get_summary(self) -> dict: raise NotImplementedError()25 def __float__(self): return float(self.get_result())...
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!!