def _print_coverage_summary(self): # FIXME: This need not depend on z3 specifically. try: all_rules = BidderFactory.default_bidder().system.rules except: print "Ignoring coverage summary, failed to find rules." return all_rule_names = set(map(str, all_rules)) # Don't expect to see rules which are marked "requires_planning". non_planned_rules = filter(lambda rule: not rule.requires_planning, all_rules) non_planned_rule_names = set(map(str, non_planned_rules)) called_rule_names = self.results.called_rule_names planned_rule_count = len(all_rule_names) - len(non_planned_rule_names) print "Tested call generation of %s rules of %s total (excluding %s requires_planning rules)." % (len(called_rule_names), len(non_planned_rule_names), planned_rule_count) uncalled_rule_names = non_planned_rule_names - called_rule_names if uncalled_rule_names: print "Never selected call from:" print "\n".join(sorted(uncalled_rule_names)) interpreted_rule_names = self.results.interpreted_rule_names print "\nTested interpretation of %s rules of %s total." % (len(interpreted_rule_names), len(all_rule_names)) uninterpreted_rule_names = all_rule_names - interpreted_rule_names # FIXME: We should print these, but we have too many right now! # if uninterpreted_rule_names: # print "Never interpreted call with:" # print "\n".join(sorted(uninterpreted_rule_names)) never_tested_rule_names = uncalled_rule_names & uninterpreted_rule_names if uninterpreted_rule_names: print "\n%s rules were never used for either bidding or interpretation:" % len(never_tested_rule_names) print "\n".join(sorted(never_tested_rule_names))
def main(self, args): self.configure_logging(True) args = BidderFactory.configure_from_args(args) bidder = BidderFactory.default_bidder() if "-v" in args: args.remove("-v") self.verbose = True if args: for identifier in args: self._bid_board(Board.from_identifier(identifier), bidder) return 0 try: while True: self._bid_board(Board.random(), bidder) except KeyboardInterrupt: print print "User interrupted." return 0
def _run_test(test): # FIXME: There is no need to lookup the bidder every time. bidder = BidderFactory.default_bidder() result = TestResult() result.test = test # FIXME: OutputCapture captures logging channels as well which is probably a waste. output = outputcapture.OutputCapture() stdout, stderr = output.capture_output() try: call_selection = bidder.call_selection_for(test.hand, test.call_history) if call_selection: result.call = call_selection.call result.rule_name = str(call_selection.rule) result.fill_last_three_rule_names(call_selection) if result.last_three_rule_names and result.last_three_rule_names[-2] is None: print "WARNING: Failed to interpret partner's last bid: %s" % test.call_history.copy_with_partial_history(-2) except Exception: result.exc_str = ''.join(traceback.format_exception(*sys.exc_info())) output.restore_output() result.save_captured_logs(stdout, stderr) return result