def test_should_verify_at_least_one_argument_matches_using_and(self): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) self.assertEqual( wrapper.and_at_least_one_argument_matches, wrapper.at_least_one_argument_matches)
def test_should_verify_argument_when_argument_matches_given_pattern(self): command_input = CommandInput('command', ['arg1'], 'stdin') wrapper = CommandInputVerifier(command_input) actual_value = wrapper.at_least_one_argument_matches('^arg') self.assertEqual(wrapper, actual_value)
def test_should_raise_exception_when_no_argument_matches_given_string(self): command_input = CommandInput( 'command', ['arg1', 'arg2', 'arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) self.assertRaises( VerificationException, wrapper.at_least_one_argument_matches, 'spameggs')
def test_should_raise_exception_when_given_input_is_different(self): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) self.assertRaises( VerificationException, wrapper.with_input, 'hello world')
def test_should_raise_exception_when_given_argument_is_not_execution(self): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) self.assertRaises( VerificationException, wrapper.at_least_with_arguments, '-arg0')
def test_should_verify_more_complex_pattern_given(self): command_input = CommandInput( 'command', ['arg1', 'borg', 'spam', '123abc'], 'stdin') wrapper = CommandInputVerifier(command_input) actual_value = wrapper.at_least_one_argument_matches('\d{3}[a-c]{3}') self.assertEqual(wrapper, actual_value)
def test_should_verify_given_input(self): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) actual_value = wrapper.with_input('stdin') self.assertEqual(wrapper, actual_value)
def called(self, command): """ raises an exception when no more executions are available or when the current execution does not have the expected command attribute, otherwise it will return the execution and remove the current execution from the list of executions. """ if not self.executions: raise VerificationException( 'No more further executions: command "%s" can not be verified.' % command) actual_execution = self.executions.pop(0) if actual_execution.command_input.command != command: raise VerificationException( 'Execution does not fulfill stub configuration:\n' 'Expected command "%s", but got "%s"\n' % (command, actual_execution.command_input.command)) return CommandInputVerifier(actual_execution.command_input)
def test_should_verify_input_using_with_or_and(self): command_input = CommandInput( 'command', ['-arg1', '-arg2', '-arg3'], 'stdin') wrapper = CommandInputVerifier(command_input) self.assertEqual(wrapper.and_input, wrapper.with_input)