Esempio n. 1
0
    def test_should_repeat_last_answer_when_asking_for_more_answers_than_given(
            self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')
        stub_configuration.then_answer('Hello world!', 'Hello error!', 0)
        stub_configuration.then_answer('Foo bar!', 'Foo error!', 1)

        actual_first_answer = stub_configuration.next_answer()

        self.assertEqual('Hello world!', actual_first_answer.stdout)
        self.assertEqual('Hello error!', actual_first_answer.stderr)
        self.assertEqual(0, actual_first_answer.return_code)

        actual_second_answer = stub_configuration.next_answer()

        self.assertEqual('Foo bar!', actual_second_answer.stdout)
        self.assertEqual('Foo error!', actual_second_answer.stderr)
        self.assertEqual(1, actual_second_answer.return_code)

        actual_third_answer = stub_configuration.next_answer()

        self.assertEqual('Foo bar!', actual_third_answer.stdout)
        self.assertEqual('Foo error!', actual_third_answer.stderr)
        self.assertEqual(1, actual_third_answer.return_code)
Esempio n. 2
0
    def test_should_append_second_answer(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")
        stub_configuration.then_answer("Hello world!", "Hello error!", 0)
        stub_configuration.then_answer("Foo bar!", "Foo error!", 1)

        actual_count_of_answers = len(stub_configuration.answers)

        self.assertEqual(2, actual_count_of_answers)
Esempio n. 3
0
    def test_should_append_second_answer(self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')
        stub_configuration.then_answer('Hello world!', 'Hello error!', 0)
        stub_configuration.then_answer('Foo bar!', 'Foo error!', 1)

        actual_count_of_answers = len(stub_configuration.answers)

        self.assertEqual(2, actual_count_of_answers)
Esempio n. 4
0
    def test_should_unset_waiting_time_by_default_when_answering(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")
        stub_configuration.then_answer("Hello world!", "Hello error!", 15)

        actual_answer = stub_configuration.next_answer()

        self.assertEqual("Hello world!", actual_answer.stdout)
        self.assertEqual("Hello error!", actual_answer.stderr)
        self.assertEqual(15, actual_answer.return_code)
        self.assertEqual(None, actual_answer.milliseconds_to_wait)
Esempio n. 5
0
    def test_should_unset_waiting_time_by_default_when_answering(self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')
        stub_configuration.then_answer('Hello world!', 'Hello error!', 15)

        actual_answer = stub_configuration.next_answer()

        self.assertEqual('Hello world!', actual_answer.stdout)
        self.assertEqual('Hello error!', actual_answer.stderr)
        self.assertEqual(15, actual_answer.return_code)
        self.assertEqual(None, actual_answer.milliseconds_to_wait)
Esempio n. 6
0
    def test_should_return_object_as_dictionary(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")
        stub_configuration.then_answer("Hello world.", "Hello error!", 19)

        actual_dictionary = stub_configuration.as_dictionary()

        expected_command_input = {"command": "any_command", "arguments": ["any_arg1", "any_arg2"], "stdin": "any_stdin"}
        self.assertEqual(expected_command_input, actual_dictionary["command_input"])
        self.assertEqual(0, actual_dictionary["current_answer"])
        actual_answer_dictionary = actual_dictionary["answers"][0]

        self.assertEqual("Hello world.", actual_answer_dictionary["stdout"])
        self.assertEqual("Hello error!", actual_answer_dictionary["stderr"])
        self.assertEqual(19, actual_answer_dictionary["return_code"])
Esempio n. 7
0
    def test_should_return_self_when_using_method_then_answer(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")

        actual_result = stub_configuration.then_answer("Hello world!", "Hello error", 99)

        self.assertTrue(actual_result is not None, "Not returning anything!")
        self.assertEqual(stub_configuration, actual_result)
Esempio n. 8
0
    def test_should_send_two_different_answers_when_asking_for_next_answer_twice(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")
        stub_configuration.then_answer("Hello world!", "Hello error!", 0)
        stub_configuration.then_answer("Foo bar!", "Foo error!", 1)

        actual_first_answer = stub_configuration.next_answer()

        self.assertEqual("Hello world!", actual_first_answer.stdout)
        self.assertEqual("Hello error!", actual_first_answer.stderr)
        self.assertEqual(0, actual_first_answer.return_code)

        actual_second_answer = stub_configuration.next_answer()

        self.assertEqual("Foo bar!", actual_second_answer.stdout)
        self.assertEqual("Foo error!", actual_second_answer.stderr)
        self.assertEqual(1, actual_second_answer.return_code)
Esempio n. 9
0
    def test_should_return_self_when_using_method_then_answer(self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')

        actual_result = stub_configuration.then_answer('Hello world!',
                                                       'Hello error', 99)

        self.assertTrue(actual_result is not None, 'Not returning anything!')
        self.assertEqual(stub_configuration, actual_result)
Esempio n. 10
0
    def test_should_send_two_different_answers_when_asking_for_next_answer_twice(
            self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')
        stub_configuration.then_answer('Hello world!', 'Hello error!', 0)
        stub_configuration.then_answer('Foo bar!', 'Foo error!', 1)

        actual_first_answer = stub_configuration.next_answer()

        self.assertEqual('Hello world!', actual_first_answer.stdout)
        self.assertEqual('Hello error!', actual_first_answer.stderr)
        self.assertEqual(0, actual_first_answer.return_code)

        actual_second_answer = stub_configuration.next_answer()

        self.assertEqual('Foo bar!', actual_second_answer.stdout)
        self.assertEqual('Foo error!', actual_second_answer.stderr)
        self.assertEqual(1, actual_second_answer.return_code)
Esempio n. 11
0
    def test_should_return_object_as_dictionary(self):
        stub_configuration = StubConfiguration('any_command',
                                               ['any_arg1', 'any_arg2'],
                                               'any_stdin')
        stub_configuration.then_answer('Hello world.', 'Hello error!', 19)

        actual_dictionary = stub_configuration.as_dictionary()

        expected_command_input = {
            'command': 'any_command',
            'arguments': ['any_arg1', 'any_arg2'],
            'stdin': 'any_stdin'
        }
        self.assertEqual(expected_command_input,
                         actual_dictionary['command_input'])
        self.assertEqual(0, actual_dictionary['current_answer'])
        actual_answer_dictionary = actual_dictionary['answers'][0]

        self.assertEqual('Hello world.', actual_answer_dictionary['stdout'])
        self.assertEqual('Hello error!', actual_answer_dictionary['stderr'])
        self.assertEqual(19, actual_answer_dictionary['return_code'])
Esempio n. 12
0
    def test_should_repeat_last_answer_when_asking_for_more_answers_than_given(self):
        stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin")
        stub_configuration.then_answer("Hello world!", "Hello error!", 0)
        stub_configuration.then_answer("Foo bar!", "Foo error!", 1)

        actual_first_answer = stub_configuration.next_answer()

        self.assertEqual("Hello world!", actual_first_answer.stdout)
        self.assertEqual("Hello error!", actual_first_answer.stderr)
        self.assertEqual(0, actual_first_answer.return_code)

        actual_second_answer = stub_configuration.next_answer()

        self.assertEqual("Foo bar!", actual_second_answer.stdout)
        self.assertEqual("Foo error!", actual_second_answer.stderr)
        self.assertEqual(1, actual_second_answer.return_code)

        actual_third_answer = stub_configuration.next_answer()

        self.assertEqual("Foo bar!", actual_third_answer.stdout)
        self.assertEqual("Foo error!", actual_third_answer.stderr)
        self.assertEqual(1, actual_third_answer.return_code)