def test_get_gameover_screen(self): # Partitions # Coverage run_tests = testtools.run_function_tests game = hangman.Game('hangman') function = game.get_gameover_screen screen = r"""---------------------------------- |__| /\ |\ | /** |\/| /\ |\ | | | /--\ | \| \__| | | /--\ | \| ---------------------------------- o-----------------o | _ _ _ _ _ _ _ | o-----------------o [ Already Guessed ] | | o-----------------o """ gameover = OrderedDict([ ('win', 'You guessed the word: hangman'), ('lose', 'You lose. The word was: hangman')]) cases = [{'args': [state]} for state in gameover.keys()] expectedv = [screen + text for text in gameover.values()] for result, message in run_tests(function, cases, expectedv): self.assertTrue(result, message)
def test_custom_word_list(): word_list = ['Foo', 'Bar', 'Baz'] game = hangman.Game(word_list=word_list) # Asserting length, not the identity of game.word_list as I might be # converting the word list to a different data structure in the future assert len(game.word_list) == len(word_list) assert game.word in word_list
def test_get_screen(self): # Partitions # Coverage message = testtools.function_message game = hangman.Game('hangman') expected = r"""---------------------------------- |__| /\ |\ | /** |\/| /\ |\ | | | /--\ | \| \__| | | /--\ | \| ---------------------------------- o-----------------o | _ _ _ _ _ _ _ | o-----------------o [ Already Guessed ] | | o-----------------o""" actual = game.get_screen() self.assertTrue(expected == actual)
import hangman import sys if __name__ == "__main__": ARGV = sys.argv if len(ARGV) == 1: use_argv = False else: use_argv = True if not use_argv: hangman.Game().play() else: tries = int(ARGV[1]) word = str(ARGV[2]) hangman.Game(word, tries).play()
import hangman import to_spec game = hangman.Game() game = to_spec.Game() while True: game.iterate()
import hangman game = hangman.Game(word="EXAMPLE").play()
def default_game(): game = hangman.Game() return game
def test_custom_guesses(): game = hangman.Game(num_guesses=id(mock.sentinel.guess_count)) assert game.num_guesses == id(mock.sentinel.guess_count)
def game(): game = hangman.Game(word_list=['FooBar'], num_guesses=4) return game