def parser_helper(self, name, code): s = preprocess(code) logger.info(f"\n*********\nCONSTRUCTING TREE OF {name}:\n*********\n") t = None try: t = construct_node(s, LABEL_DOCUMENT) except (UnmatchedTactic, UnmatchedToken) as e: logger.info(f"EXCEPTION! {e.__class__.__name__}: {str(e)[:20]}") raise e try: with open(f'pickled/{name}', 'rb') as f: pickled = pickle.load(f) except FileNotFoundError: with open(f'pickled/{name}', 'wb') as f: pickle.dump(t, f) with open(f'pickled/{name}', 'rb') as f: pickled = pickle.load(f) diff = deepdiff.DeepDiff(t, pickled) try: self.assertEqual(diff, {}) logger.info(f"\n*********\nTREE OF {name}:\n*********\n") logger.info("\n"+utils.pretty2str(t)) except AssertionError as e: logger.info( f"\n*********\nPARSER OUTPUT FOR TESTCASE: {name}\n*********\n") logger.info("\n"+utils.pretty2str(t)) logger.info( f"\n*********\nEXPECTED FOR TESTCASE: {name}\n*********\n") logger.info("\n"+utils.pretty2str(pickled)) logger.info("\nDIFF:") logger.info(diff) raise e
def collect_arity_from_str(s: str, arity_db: dict) -> dict: print(f"Creating document from string....") s = re.findall(r"[^\s]+?:\n[\s\S]+?(?=\n[^\s]+?:\n|$)", s) s = "".join([f"Lemma {a}." for a in s]) s = proof_reader.preprocess(s) print(f"Constructing syntax tree...") t = proof_reader.construct_node(s, LABEL_DOCUMENT) utils.pretty_log(t, proof_reader.logger) print(f"Number of assertion nodes:{len(t.children)}.") print(f"Collecting arity...") arity_db = proof_reader.collect_arity(t, arity_db) print( f"Number of entries so far (assertions with forall):{len(arity_db)}.") return arity_db
def arity_helper(self, name, code, arity, expected_warnings): s = preprocess(code) logger.info(f"\n*********\nCONSTRUCTING TREE OF {name}:\n*********\n") t = None try: t = construct_node(s, LABEL_DOCUMENT) except (UnmatchedToken, UnmatchedTactic) as e: logger.info(f"EXCEPTION! {e.__class__.__name__}: {str(e)[:20]}") raise e logger.info(f"\n*********\nTREE OF {name}:\n*********\n") logger.info("\n"+utils.pretty2str(t)) warnings, _ = check_arity(t, arity) logger.info( f"Parity check warnings: {warnings}") self.assertEqual(warnings, expected_warnings)
def unpermitted_tactic_helper(self, name, code, expected_tactic, expected_remaining): s = preprocess(code) try: logger.info( f"\n*********\nCONSTRUCTING TREE OF {name}:\n*********\n") t = construct_node(s, LABEL_DOCUMENT) except UnmatchedToken as e: logger.info(f"EXCEPTION! {e.__class__.__name__}: {str(e)[:20]}") except UnmatchedTactic as e: logger.info(f"EXCEPTION! {e.__class__.__name__}: {str(e)[:20]}") if e.tactic != expected_tactic or \ e.remaining != expected_remaining: print(f"\ntactic captured:{e.tactic}") print(f"\nremaining string:{e.remaining}") raise e
def run_performance_test(code, name): logger.log(PERF, f"Performance test for {name}.\n") overall_timer = Timer() overall_timer.start("overall") timer = Timer() timer.start("preprocess") s = preprocess(code) timer.stop() timer.start("construct_node") t = construct_node(s, LABEL_DOCUMENT) timer.stop() timer.start("check_arity") warnings, _ = check_arity(t, arity_db) timer.stop() overall_timer.stop()