Exemple #1
0
    def __set_turnover(self):
        """ Takes the description of a play from self with a turnover in it and
        sets the "turnover" dictionary for the play.

        returns:
            A turnover list with the following fields:
                "turnovers": [{ "type": "fumble", "by": "home", "recovered":
                "away" }, ...]
        """
        turnovers = []
        turnover = {}

        for turn_string in split_turnovers(self.current_play_info["description"]):
            t = deepcopy(turnover)
            # Set the name of the penalty
            t["type"] = get_turnover_type(turn_string)
            # Set the teams
            (com, rec) = get_turnover_teams(
                    turn_string,
                    self.home_players,
                    self.away_players
                    )
            if com:
                t["by"] = com
            if rec:
                t["recovered"] = rec

            # Fill in the full dictionary
            turnovers.append(t)

        return turnovers
Exemple #2
0
 def test_get_turnover_teams(self):
     self.__set_turnover_consts()
     # Successful
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[0][0],
             ("Josiah Barlet", "Leo McGarry"),
             ("Matt Santos", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[1][0],
             ("Tom Petty", "Roy Orbison"),
             ("Bob Dylan", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[2][0],
             ("Clyde Barrow", "Bonnie Parker"),
             ("Frank Harmer", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[3][0],
             ("Ugarte", "Rick Blaine"),
             ("Captain Louis Renault", "Major Strasser"),
         ), ("home", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[4][0],
             ("James Moriarty", ),
             ("Sherlock Holmes", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[5][0],
             ("Robert De Niro", "Jean Reno", "Sean Bean"),
             ("Stellan Skarsgård", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[5][1],
             ("Robert De Niro", "Jean Reno", "Sean Bean"),
             ("Stellan Skarsgård", ),
         ), ("away", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[6][0],
             ("J.R. Oppenheimer", "R. P. Feynman"),
             ("E. Fermi", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[7][0],
             ("Men Without Hats", ),
             ("Ivan Doroschuk", ),
         ), ("home", False))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[8][0],
             ("C. J. Browne", "D. P. Lindley"),
             ('', ),
         ), ("home", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[9][0],
             ("W. White", "J. Pinkman"),
             ("S. White", ),
         ), ("away", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[10][0],
             ("J. McNulty", "B. Russell"),
             ("D'Angelo Barksdale", ),
         ), ("home", "away"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[10][1],
             ("J. McNulty", "B. Russell"),
             ("D'Angelo Barksdale", ),
         ), ("home", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[11][0],
             ("Jean-Luc Picard", "G. La Forge", "Data"),
             ("Lore", ),
         ), ("home", "home"))
     self.assertEqual(
         get_turnover_teams(
             self.turnover_splits[12][0],
             ("Irène Joliot-Curie", ),
             ("Frédéric Joliot-Curie", ),
         ), ("away", False))
 def test_get_turnover_teams(self):
     self.__set_turnover_consts()
     # Successful
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[0][0],
                 ("Josiah Barlet", "Leo McGarry"),
                 ("Matt Santos",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[1][0],
                 ("Tom Petty", "Roy Orbison"),
                 ("Bob Dylan",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[2][0],
                 ("Clyde Barrow", "Bonnie Parker"),
                 ("Frank Harmer",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[3][0],
                 ("Ugarte", "Rick Blaine"),
                 ("Captain Louis Renault", "Major Strasser"),
                 ),
             ("home", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[4][0],
                 ("James Moriarty",),
                 ("Sherlock Holmes",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[5][0],
                 ("Robert De Niro", "Jean Reno", "Sean Bean"),
                 ("Stellan Skarsgård",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[5][1],
                 ("Robert De Niro", "Jean Reno", "Sean Bean"),
                 ("Stellan Skarsgård",),
                 ),
             ("away", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[6][0],
                 ("J.R. Oppenheimer", "R. P. Feynman"),
                 ("E. Fermi",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[7][0],
                 ("Men Without Hats",),
                 ("Ivan Doroschuk",),
                 ),
             ("home", False)
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[8][0],
                 ("C. J. Browne", "D. P. Lindley"),
                 ('',),
                 ),
             ("home", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[9][0],
                 ("W. White", "J. Pinkman"),
                 ("S. White",),
                 ),
             ("away", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[10][0],
                 ("J. McNulty", "B. Russell"),
                 ("D'Angelo Barksdale",),
                 ),
             ("home", "away")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[10][1],
                 ("J. McNulty", "B. Russell"),
                 ("D'Angelo Barksdale",),
                 ),
             ("home", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[11][0],
                 ("Jean-Luc Picard", "G. La Forge", "Data"),
                 ("Lore",),
                 ),
             ("home", "home")
             )
     self.assertEqual(
             get_turnover_teams(
                 self.turnover_splits[12][0],
                 ("Irène Joliot-Curie",),
                 ("Frédéric Joliot-Curie",),
                 ),
             ("away", False)
             )