def list_tags(self): log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Tags.', bold=True) log.test_log.message(terminal.separator()) for tag in self.tags(): log.test_log.message(tag, machine_readable=True)
def list_tests(self): log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Cases.', bold=True) log.test_log.message(terminal.separator()) for suite in self.schedule: for test in suite: log.test_log.message(test.uid)
def list_tests(self): log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Cases.', bold=True) log.test_log.message(terminal.separator()) for suite in self.schedule: for test in suite: log.test_log.message(test.uid, machine_readable=True)
def list_tests_with_tags(loader, tags): log.display('Listing tests based on tags.') for tag in tags: log.display(separator()) log.display("Tests marked with tag '%s':" % tag) log.display(separator()) for test in loader.tag_index(tag): log.display(test.uid)
def list_tags(self): #TODO In Gem5 override this with tag types (isa,variant,length) log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Tags.', bold=True) log.test_log.message(terminal.separator()) for tag in self.tags(): log.test_log.message(tag)
def run_schedule(test_schedule, log_handler): ''' Test Phases ----------- * Test Collection * Fixture Parameterization * Global Fixture Setup * Iteratevely run suites: * Suite Fixture Setup * Iteratively run tests: * Test Fixture Setup * Run Test * Test Fixture Teardown * Suite Fixture Teardown * Global Fixture Teardown ''' log_handler.schedule_finalized(test_schedule) # Iterate through all fixtures notifying them of the test schedule. for suite in test_schedule: copied_fixtures = [] for fixture in suite.fixtures: copied_fixtures.append(fixture.schedule_finalized(test_schedule)) suite.fixtures = copied_fixtures for test in suite: copied_fixtures = [] for fixture in test.fixtures: copied_fixtures.append( fixture.schedule_finalized(test_schedule)) test.fixtures = copied_fixtures log.test_log.message(terminal.separator()) log.test_log.message('Running Tests from {} suites'.format( len(test_schedule.suites)), bold=True) log.test_log.message("Results will be stored in {}".format( config.config.result_path)) log.test_log.message(terminal.separator()) # Build global fixtures and exectute scheduled test suites. if config.config.test_threads > 1: library_runner = runner.LibraryParallelRunner(test_schedule) library_runner.set_threads(config.config.test_threads) else: library_runner = runner.LibraryRunner(test_schedule) library_runner.run() failed = log_handler.unsuccessful() log_handler.finish_testing() return 1 if failed else 0
def run_schedule(test_schedule, log_handler): ''' Test Phases ----------- * Test Collection * Fixture Parameterization * Global Fixture Setup * Iteratevely run suites: * Suite Fixture Setup * Iteratively run tests: * Test Fixture Setup * Run Test * Test Fixture Teardown * Suite Fixture Teardown * Global Fixture Teardown ''' log_handler.schedule_finalized(test_schedule) # Iterate through all fixtures notifying them of the test schedule. for suite in test_schedule: copied_fixtures = [] for fixture in suite.fixtures: copied_fixtures.append(fixture.schedule_finalized(test_schedule)) suite.fixtures = copied_fixtures for test in suite: copied_fixtures = [] for fixture in test.fixtures: copied_fixtures.append(fixture.schedule_finalized( test_schedule)) test.fixtures = copied_fixtures log.test_log.message(terminal.separator()) log.test_log.message('Running Tests from {} suites' .format(len(test_schedule.suites)), bold=True) log.test_log.message("Results will be stored in {}".format( config.config.result_path)) log.test_log.message(terminal.separator()) # Build global fixtures and exectute scheduled test suites. if config.config.test_threads > 1: library_runner = runner.LibraryParallelRunner(test_schedule) library_runner.set_threads(config.config.test_threads) else: library_runner = runner.LibraryRunner(test_schedule) library_runner.run() failed = log_handler.unsuccessful() log_handler.finish_testing() return 1 if failed else 0
def do_run(): ''' Test Phases ----------- * Test Collection * Fixture Parameterization * Global Fixture Setup * Iteratevely run suites: * Suite Fixture Setup * Iteratively run tests: * Test Fixture Setup * Run Test * Test Fixture Teardown * Suite Fixture Teardown * Global Fixture Teardown ''' # Initialize early parts of the log. term_handler = handlers.TerminalHandler(stream=config.config.stream, verbosity=config.config.verbose + log.LogLevel.Info) summary_handler = handlers.SummaryHandler() mp_handler = handlers.MultiprocessingHandlerWrapper( summary_handler, term_handler) mp_handler.async_process() log.test_log.log_obj.add_handler(mp_handler) test_schedule = load_tests().schedule # Filter tests based on tags filter_with_config_tags(test_schedule) result_path = config.config.result_path # Create the result handler object. result_handler = handlers.ResultHandler(test_schedule, result_path) mp_handler.add_handler(result_handler) # Iterate through all fixtures notifying them of the test schedule. for fixture in test_schedule.all_fixtures(): fixture.schedule_finalized(test_schedule) log.test_log.message(terminal.separator()) log.test_log.message('Running Tests from {} suites'.format( len(test_schedule.suites)), bold=True) log.test_log.message("Results will be stored in {}".format(result_path)) log.test_log.message(terminal.separator()) # Build global fixtures and exectute scheduled test suites. library_runner = runner.LibraryRunner(test_schedule) library_runner.run()
def generate_print_output(league): players, alternates, teams, team_rating_bounds, alt_rating_bounds, alts_split =\ league['players'], league['alternates'], league['teams'], \ league['team_rating_bounds'], league['alt_rating_bounds'], league['alts_split'] boards = len(teams[0].boards) num_teams = len(teams) terminal.separator() print("Team rating range: ", team_rating_range(teams)) print("Team rating variance: ", team_rating_variance(teams)) print("Total happiness: ", total_happiness(teams)) print(f"Using: {len(players)} players and {len(alternates)} alternates") print(terminal.green(f"Previous Season Alternates")) print(terminal.blue(f"Requested Alternate")) print("TEAMS") terminal.smallheader("Team #") for i in range(boards): n,x = team_rating_bounds[i] terminal.largeheader(f"Board #{i+1} [{n},{x})") terminal.largeheader("Mean rating") print() for team_i in range(num_teams): terminal.smallcol(f"#{team_i+1}") for board_i in range(boards): team = teams[team_i] player = team.boards[board_i] short_name = player.name[:20] player_name = f"{short_name} ({player.rating})" terminal.largecol(player_name, terminal.green if player.previous_season_alt else None) terminal.largecol("{0:.2f}".format(team.getMean())) print() print() print("ALTERNATES") terminal.smallheader(" ") for i in range(boards): n,x = alt_rating_bounds[i] terminal.largeheader(f"Board #{i+1} [{n},{x})") print() for player_i in range(max([len(a) for a in alts_split])): terminal.smallcol(" ") for board_i in range(boards): board = alts_split[board_i] player_name = "" if player_i < len(board): player = board[player_i] short_name = player.name short_name = player.name[:20] player_name = f"{short_name} ({player.rating})" terminal.largecol(player_name, terminal.blue if player.alt else None) print()
def run(self): ''' Run our entire collection of suites. ''' for logger in self.result_loggers: logger.begin_testing() log.info(separator()) log.info("Building all non 'lazy_init' fixtures") failed_builds = self.setup_unbuilt(self.suites.iter_fixtures(), setup_lazy_init=False) if failed_builds: error_str = '' for fixture, error in failed_builds: error_str += 'Failed to build %s\n' % fixture error_str += '%s' % error log.warn('Error(s) while building non lazy_init fixtures.') log.warn(error_str) outcomes = set() for suite in self.suites: outcome = self.run_suite(suite) outcomes.add(outcome) if outcome in Outcome.failfast and config.fail_fast: break for logger in self.result_loggers: logger.end_testing() return self._suite_outcome(outcomes)
def dorun(): ''' Handle the `run` command. ''' loader = load_tests() if config.tags: suites = [] for tag in config.tags: suites.extend(loader.suites_with_tag(tag)) else: suites = loader.suites # Create directory to save junit and internal results in. mkdir_p(config.result_path) with open(joinpath(config.result_path, 'pickle'), 'w') as result_file,\ open(joinpath(config.result_path, 'junit.xml'), 'w') as junit_f: junit_logger = result.JUnitLogger(junit_f, result_file) console_logger = result.ConsoleLogger() loggers = (junit_logger, console_logger) log.display(separator()) log.bold('Running Tests') log.display('') if config.uid: test_item = loader.get_uid(config.uid) results = Runner.run_items(test_item) else: testrunner = Runner(suites, loggers) results = testrunner.run()
def _set_testcase_outcome(self, test_case, outcome, reason=None, **kwargs): log.bold(self.colormap[outcome] + test_case.name + self.reset) self.outcome_count[outcome] += 1 if reason is not None: log.info('') log.info('Reason:') log.info(reason) log.info(terminal.separator('-'))
def load_tests(): ''' Create a TestLoader and load tests for the directory given by the config. ''' testloader = loader_mod.Loader() log.test_log.message(terminal.separator()) log.test_log.message('Loading Tests', bold=True) testloader.load_root(config.config.directory) return testloader
def _display_outcome(self, name, outcome, reason=None): print(self.color.Bold + SummaryHandler.colormap[outcome] + name + ' ' + state.Result.enums[outcome] + SummaryHandler.reset) if reason is not None: log.test_log.info('') log.test_log.info('Reason:') log.test_log.info(reason) log.test_log.info(terminal.separator('-'))
def load_tests(): ''' Create a TestLoader and load tests for the directory given by the config. ''' testloader = TestLoader() log.display(separator()) log.bold('Loading Tests') log.display('') testloader.load_root(config.directory) return testloader
def list_suites(loader): log.display(separator()) log.display('Listing all TestSuites.') log.display(separator()) for suite in loader.suites: log.display(suite.uid)
def make_teams(players, output, boards): # input file is JSON data with the following keys: rating, name, in_slack, account_status, date_created, prefers_alt, friends, avoid, has_20_games. with open(players, 'r') as infile: playerdata = json.load(infile) print("This data was read from file.") # put player data into Player objects players = [] for player in playerdata: if player['has_20_games'] and player['in_slack']: players.append(Player.player_from_json(player)) else: print("{0} skipped".format(player['name'])) players.sort(key=lambda player: player.rating, reverse=True) # Split into those that want to be alternates vs those that do not. alternates = [p for p in players if p.alt] players = [p for p in players if not p.alt] # splits list of Player objects into 6 near equal lists, sectioned by rating players_split = split_into_equal_groups_by_rating(players, boards) team_rating_bounds = get_rating_bounds_of_split(players_split) num_teams = int(math.ceil((len(players_split[0]) * 0.8) / 2.0) * 2) print(f"Targetting {num_teams} teams") # separate latest joining players into alternate lists as required for n, board in enumerate(players_split): board.sort(key=lambda player: (0 if player.previous_season_alt else 1, player.date)) alternates.extend(board[num_teams:]) del board[num_teams:] board.sort(key=lambda player: player.rating, reverse=True) alts_split = split_into_equal_groups_by_rating(alternates, boards) alt_rating_bounds = get_rating_bounds_of_split(alts_split) players = sum(players_split, []) #print len(players) #print num_teams #print alts_split # snake draft players into initial teams and update player and team attributes for board in players_split[1::2]: board.reverse() for n, board in enumerate(players_split): for player in board: player.board = n teams = [] for n in range(num_teams): teams.append(Team(boards)) for n, board in enumerate(players_split): for team, player in enumerate(board): teams[team].changeBoard(n, player) # convert players' friends and avoid from name to references of the friend's/avoid's player object for player in players: if player.friends or player.avoid: player.friends = re.split( "[^-_a-zA-Z0-9]+", player.friends ) # separate friends requests into individual usernames - split on any number of non-(alphanumeric, hyphen or underscore) player.avoid = re.split( "[^-_a-zA-Z0-9]+", player.avoid ) # separate avoid requests into individual usernames - split on any number of non-(alphanumeric, hyphen or underscore) else: player.friends = [] player.avoid = [] for player in players: temp_friends = [] for friend in player.friends: for potentialfriend in players: if friend.lower() == potentialfriend.name.lower( ) and potentialfriend not in temp_friends: # prevent duplicated friend error temp_friends.append(potentialfriend) player.friends = temp_friends temp_avoid = [] for avoid in player.avoid: for potentialavoid in players: if avoid.lower() == potentialavoid.name.lower( ) and potentialavoid not in temp_avoid: # prevent duplicated friend error temp_avoid.append(potentialavoid) player.avoid = temp_avoid #remove friend requests for same board for player in players: for friend in player.friends: if friend.board == player.board: player.friends.remove(friend) updatePref(players, teams) updateSort(players, teams) def swapPlayers(teama, playera, teamb, playerb, board): #swap players between teams - ensure players are same board for input teama.changeBoard(board, playerb) teamb.changeBoard(board, playera) def testSwap(teama, playera, teamb, playerb, board): #try a swap and return the preference change if this swap was made prior_pref = teama.team_pref_score + teamb.team_pref_score swapPlayers(teama, playera, teamb, playerb, board) #swap players forwards updatePref(players, teams) post_pref = teama.team_pref_score + teamb.team_pref_score swapPlayers(teama, playerb, teamb, playera, board) #swap players back updatePref(players, teams) return post_pref - prior_pref #more positive = better swap # take player from least happy team # calculate the overall preference score if player were to swap to each of the preferences' teams or preference swaps into their team. # swap player into the team that makes the best change to overall preference # check if the swap has increased the overall preference rating # if swap made, resort list by preference score and start at the least happy player again # if no improving swaps are available, go to the next player # if end of the list reached with no swaps made: stop p = 0 while p < len(players): player = players[p] #least happy player swaps = [] for friend in player.friends: #test both direction swaps for each friend and whichever is better, add the swap ID and score to temp friends list if friend.board != player.board and friend.team != player.team: #board check is redundant due to earlier removal of same board requests #test swap friend to player team (swap1) swap1_ID = (friend.team, friend, player.team, player.team.getPlayer(friend.board), friend.board) swap1_score = testSwap(*swap1_ID) #test swap player to friend team (swap2) swap2_ID = (player.team, player, friend.team, friend.team.getPlayer(player.board), player.board) swap2_score = testSwap(*swap2_ID) swaps.append( max((swap1_score, swap1_ID), (swap2_score, swap2_ID))) for avoid in player.avoid: #test moving player to be avoided to the best preferred team if player.team == avoid.team: #otherwise irrelevant for swap_team in teams: swap_ID = (avoid.team, avoid, swap_team, swap_team.getPlayer(avoid.board), avoid.board) swap_score = testSwap(*swap_ID) swaps.append((swap_score, swap_ID)) swaps.sort() if swaps and swaps[-1][ 0] > 0: # there is a swap to make and it improves the preference score swapPlayers(*(swaps[-1][1])) print(swaps[-1]) updatePref(players, teams) updateSort(players, teams) p = 0 else: # go to the next player in the list p += 1 for player in players: player.setReqMet() #WIP for upload format for heltour jsonoutput = [] #[{"action":"change-member","team_number":1,"board_number":1,"player":{"name":"lemonworld","is_captain":false,"is_vice_captain":false}}] for t, team in enumerate(teams): for b, board in enumerate(team.boards): pp = { "action": "change-member", "team_number": t + 1, "board_number": b + 1, "player": { "name": board.name, "is_captain": False, "is_vice_captain": False } } jsonoutput.append(pp) for b, board in enumerate(alts_split): print(board) for _, pp in enumerate(board): pp = { "action": "create-alternate", "board_number": b + 1, "player_name": pp.name } jsonoutput.append(pp) if output == "readable": terminal.separator() print( f"Using: {len(players)} players and {len(alternates)} alternates") print(terminal.green(f"Previous Season Alternates")) print(terminal.blue(f"Requested Alternate")) print("TEAMS") terminal.smallheader("Team #") for i in range(boards): n, x = team_rating_bounds[i] terminal.largeheader(f"Board #{i+1} [{n},{x})") print() for team_i in range(num_teams): terminal.smallcol(f"#{team_i+1}") for board_i in range(boards): team = teams[team_i] player = team.boards[board_i] short_name = player.name[:20] player_name = f"{short_name} ({player.rating})" terminal.largecol( player_name, terminal.green if player.previous_season_alt else None) print() print() print("ALTERNATES") terminal.smallheader(" ") for i in range(boards): n, x = alt_rating_bounds[i] terminal.largeheader(f"Board #{i+1} [{n},{x})") print() for player_i in range(max([len(a) for a in alts_split])): terminal.smallcol(" ") for board_i in range(boards): board = alts_split[board_i] player_name = "" if player_i < len(board): player = board[player_i] short_name = player.name short_name = player.name[:20] player_name = f"{short_name} ({player.rating})" terminal.largecol(player_name, terminal.blue if player.alt else None) print() elif output == "json": print(json.dumps(jsonoutput))
def list_tests(loader): log.display(separator()) log.display('Listing all TestCases.') log.display(separator()) for test in loader.tests: log.display(test.uid)
def list_suites(self): log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Suites.', bold=True) log.test_log.message(terminal.separator()) for suite in self.suites(): log.test_log.message(suite.uid)
def list_suites(self): log.test_log.message(terminal.separator()) log.test_log.message('Listing all Test Suites.', bold=True) log.test_log.message(terminal.separator()) for suite in self.suites(): log.test_log.message(suite.uid, machine_readable=True)
def list_fixtures(loader): log.display(separator()) log.display('Listing all Fixtures.') log.display(separator()) for fixture in loader.fixtures: log.display(fixture.name)
def list_tags(loader): log.display(separator()) log.display('Listing all Tags.') log.display(separator()) for tag in loader.tags: log.display(tag)