| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,23 +120,27 @@ def test_all_strikes_is_a_perfect_game(self): | |||
| 120 | 120 | ||
| 121 | 121 | def test_rolls_cannot_score_negative_points(self): | |
| 122 | 122 | ||
| 123 | - self.assertRaises(ValueError, self.game.roll, -11) | ||
| 123 | + with self.assertRaisesWithMessage(ValueError): | ||
| 124 | + self.game.roll(-11) | ||
| 124 | 125 | ||
| 125 | 126 | def test_a_roll_cannot_score_more_than_10_points(self): | |
| 126 | 127 | ||
| 127 | - self.assertRaises(ValueError, self.game.roll, 11) | ||
| 128 | + with self.assertRaisesWithMessage(ValueError): | ||
| 129 | + self.game.roll(11) | ||
| 128 | 130 | ||
| 129 | 131 | def test_two_rolls_in_a_frame_cannot_score_more_than_10_points(self): | |
| 130 | 132 | self.game.roll(5) | |
| 131 | 133 | ||
| 132 | - self.assertRaises(ValueError, self.game.roll, 6) | ||
| 134 | + with self.assertRaisesWithMessage(ValueError): | ||
| 135 | + self.game.roll(6) | ||
| 133 | 136 | ||
| 134 | 137 | def test_bonus_after_strike_in_last_frame_cannot_score_more_than_10(self): | |
| 135 | 138 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10] | |
| 136 | 139 | ||
| 137 | 140 | self.roll(rolls) | |
| 138 | 141 | ||
| 139 | - self.assertRaises(ValueError, self.game.roll, 11) | ||
| 142 | + with self.assertRaisesWithMessage(ValueError): | ||
| 143 | + self.game.roll(11) | ||
| 140 | 144 | ||
| 141 | 145 | def test_bonus_aft_last_frame_strk_can_be_more_than_10_if_1_is_strk(self): | |
| 142 | 146 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, | |
@@ -151,42 +155,58 @@ def test_bonus_aft_last_frame_strk_cnt_be_strk_if_first_is_not_strk(self): | |||
| 151 | 155 | ||
| 152 | 156 | self.roll(rolls) | |
| 153 | 157 | ||
| 154 | - self.assertRaises(ValueError, self.game.roll, 10) | ||
| 158 | + with self.assertRaisesWithMessage(ValueError): | ||
| 159 | + self.game.roll(10) | ||
| 155 | 160 | ||
| 156 | 161 | def test_an_incomplete_game_cannot_be_scored(self): | |
| 157 | 162 | rolls = [0, 0] | |
| 158 | 163 | ||
| 159 | 164 | self.roll(rolls) | |
| 160 | 165 | ||
| 161 | - self.assertRaises(IndexError, self.game.score) | ||
| 166 | + with self.assertRaisesWithMessage(IndexError): | ||
| 167 | + self.game.score() | ||
| 162 | 168 | ||
| 163 | 169 | def test_cannot_roll_if_there_are_already_ten_frames(self): | |
| 164 | 170 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | |
| 165 | 171 | ||
| 166 | 172 | self.roll(rolls) | |
| 167 | 173 | ||
| 168 | - self.assertRaises(IndexError, self.game.roll, 0) | ||
| 174 | + with self.assertRaisesWithMessage(IndexError): | ||
| 175 | + self.game.roll(0) | ||
| 169 | 176 | ||
| 170 | 177 | def test_bonus_rolls_for_strike_must_be_rolled_before_score_is_calc(self): | |
| 171 | 178 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10] | |
| 172 | 179 | ||
| 173 | 180 | self.roll(rolls) | |
| 174 | 181 | ||
| 175 | - self.assertRaises(IndexError, self.game.score) | ||
| 182 | + with self.assertRaisesWithMessage(IndexError): | ||
| 183 | + self.game.score() | ||
| 176 | 184 | ||
| 177 | 185 | def test_both_bonuses_for_strike_must_be_rolled_before_score(self): | |
| 178 | 186 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10] | |
| 179 | 187 | ||
| 180 | 188 | self.roll(rolls) | |
| 181 | 189 | ||
| 182 | - self.assertRaises(IndexError, self.game.score) | ||
| 190 | + with self.assertRaisesWithMessage(IndexError): | ||
| 191 | + self.game.score() | ||
| 183 | 192 | ||
| 184 | 193 | def test_bonus_rolls_for_spare_must_be_rolled_before_score_is_calc(self): | |
| 185 | 194 | rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3] | |
| 186 | 195 | ||
| 187 | 196 | self.roll(rolls) | |
| 188 | 197 | ||
| 189 | - self.assertRaises(IndexError, self.game.score) | ||
| 198 | + with self.assertRaisesWithMessage(IndexError): | ||
| 199 | + self.game.score() | ||
| 200 | + | ||
| 201 | + # Utility functions | ||
| 202 | + def setUp(self): | ||
| 203 | + try: | ||
| 204 | + self.assertRaisesRegex | ||
| 205 | + except AttributeError: | ||
| 206 | + self.assertRaisesRegex = self.assertRaisesRegexp | ||
| 207 | + | ||
| 208 | + def assertRaisesWithMessage(self, exception): | ||
| 209 | + return self.assertRaisesRegex(exception, r".+") | ||
| 190 | 210 | ||
| 191 | 211 | ||
| 192 | 212 | if __name__ == '__main__': | |
| Back | FazBrowse Home | New Git URL |
0 commit comments