Ejemplo n.º 1
0
    def test_get_bool(self):
        input_seq = ["as", "ye", " y", "y"]
        with mock.patch("builtins.input", side_effect=input_seq):
            self.assertTrue(ioutil.get_bool(""))

        input_seq = ["", "Nope", "y", "banana", "ananas"]
        with mock.patch("builtins.input", side_effect=input_seq):
            self.assertTrue(ioutil.get_bool("", accepted=["banana"]))

        input_seq = ["", "N", "yup", "banana", "ananas", "pehta"]
        with mock.patch("builtins.input", side_effect=input_seq):
            self.assertFalse(ioutil.get_bool("", rejected=["ananas"]))

        input_seq = ["", "N", "yup", "banana", "ananas", "pehta"]
        with mock.patch("builtins.input", side_effect=input_seq):
            self.assertFalse(ioutil.get_bool("", rejected=["ananas", ""]))

        input_seq = [""]
        with mock.patch("builtins.input", side_effect=input_seq):
            self.assertTrue(ioutil.get_bool("", accepted=[""]))
    def test_get_bool(self):
        input_seq = ['as', 'ye', ' y', 'y']
        with mock.patch('builtins.input', side_effect=input_seq):
            self.assertTrue(ioutil.get_bool(''))

        input_seq = ['', 'Nope', 'y', 'banana', 'ananas']
        with mock.patch('builtins.input', side_effect=input_seq):
            self.assertTrue(ioutil.get_bool('', accepted=['banana']))

        input_seq = ['', 'N', 'yup', 'banana', 'ananas', 'pehta']
        with mock.patch('builtins.input', side_effect=input_seq):
            self.assertFalse(ioutil.get_bool('', rejected=['ananas']))

        input_seq = ['', 'N', 'yup', 'banana', 'ananas', 'pehta']
        with mock.patch('builtins.input', side_effect=input_seq):
            self.assertFalse(ioutil.get_bool('', rejected=['ananas', '']))

        input_seq = ['']
        with mock.patch('builtins.input', side_effect=input_seq):
            self.assertTrue(ioutil.get_bool('', accepted=['']))
Ejemplo n.º 3
0
    def mainloop(self):
        """Runs the whole game.

        First :func:`setup` is called. Then :func:`play_round` is called
        indefinitely, until player does not want another round. After that,
        :func:`goodbye` is called.
        """
        self.setup()
        while True:
            self.play_round()
            another = ioutil.get_bool("Want to play another round [Y/n]: ", accepted={'Y', 'y', '', 'yes'})
            if not another:
                self.goodbye()
                return