def test_should_send_answers_in_given_order_when_asking_for_next_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) stub_configuration.then_answer('Spam eggs!', 'Spam error!', 2) 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('Spam eggs!', actual_third_answer.stdout) self.assertEqual('Spam error!', actual_third_answer.stderr) self.assertEqual(2, actual_third_answer.return_code)
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)
def test_should_set_stdout_and_stderr_with_chaining_when_answering(self): stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin") stub_configuration.then_write("Hello world!", "Hello error!") actual_answer = stub_configuration.next_answer() self.assertEqual("Hello world!", actual_answer.stdout) self.assertEqual("Hello error!", actual_answer.stderr) self.assertEqual(0, actual_answer.return_code)
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)
def test_should_set_return_code_and_waiting_time_when_answering(self): stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin") stub_configuration.then_return(7, milliseconds_to_wait=3) actual_answer = stub_configuration.next_answer() self.assertEqual(None, actual_answer.stdout) self.assertEqual(None, actual_answer.stderr) self.assertEqual(7, actual_answer.return_code) self.assertEqual(3, actual_answer.milliseconds_to_wait)
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)
def test_should_set_stdout_and_stderr_with_chaining_when_answering(self): stub_configuration = StubConfiguration('any_command', ['any_arg1', 'any_arg2'], 'any_stdin') stub_configuration.then_write('Hello world!', 'Hello error!') actual_answer = stub_configuration.next_answer() self.assertEqual('Hello world!', actual_answer.stdout) self.assertEqual('Hello error!', actual_answer.stderr) self.assertEqual(0, actual_answer.return_code)
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)
def test_should_set_stdout_and_waiting_time_when_answering(self): stub_configuration = StubConfiguration('any_command', ['any_arg1', 'any_arg2'], 'any_stdin') stub_configuration.then_write('Hello world!', milliseconds_to_wait=6) actual_answer = stub_configuration.next_answer() self.assertEqual('Hello world!', actual_answer.stdout) self.assertEqual(None, actual_answer.stderr) self.assertEqual(0, actual_answer.return_code) self.assertEqual(6, actual_answer.milliseconds_to_wait)
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)
def test_should_append_answer_when_using_method_then(self): stub_configuration = StubConfiguration("any_command", ["any_arg1", "any_arg2"], "any_stdin") stub_configuration.then(Answer("Hello world!", "Hello error", 99)) actual_count_of_answers = len(stub_configuration.answers) self.assertEqual(1, actual_count_of_answers) actual_answer = stub_configuration.next_answer() self.assertEqual("Hello world!", actual_answer.stdout) self.assertEqual("Hello error", actual_answer.stderr) self.assertEqual(99, actual_answer.return_code)
def test_should_append_answer_when_using_method_then(self): stub_configuration = StubConfiguration('any_command', ['any_arg1', 'any_arg2'], 'any_stdin') stub_configuration.then(Answer('Hello world!', 'Hello error', 99)) actual_count_of_answers = len(stub_configuration.answers) self.assertEqual(1, actual_count_of_answers) actual_answer = stub_configuration.next_answer() self.assertEqual('Hello world!', actual_answer.stdout) self.assertEqual('Hello error', actual_answer.stderr) self.assertEqual(99, actual_answer.return_code)