コード例 #1
0
ファイル: commandstub.py プロジェクト: pombredanne/shtub
def dispatch(command_input):
    """
        currently this will handle the given command_input by testing whether it
        fulfills a stub configuration. If so it will save a execution (with the expected flag
        set to true) and send the next answer as defined in the stub configuration object.
    """

    stub_configurations = deserialize_stub_configurations(
        CONFIGURED_STUBS_FILENAME)

    logging.info('Got %s', command_input)

    execution = Execution(command_input.command, command_input.arguments,
                          command_input.stdin)

    for stub_configuration in stub_configurations:
        if command_input.fulfills(stub_configuration.command_input):
            logging.info('Execution fulfills %s', stub_configuration)
            execution.mark_as_expected()
            record_execution(execution)
            answer = stub_configuration.next_answer()
            serialize_as_dictionaries(CONFIGURED_STUBS_FILENAME,
                                      stub_configurations)
            unlock(lock_handle)
            if answer.milliseconds_to_wait:
                time.sleep(answer.milliseconds_to_wait / 1000)
            send_answer(answer)
            return

    unlock(lock_handle)
    logging.error(
        'Given command_input does not fulfill requirements of any stub configuration.'
    )
    sys.exit(255)
コード例 #2
0
ファイル: commandstub.py プロジェクト: yadt/shtub
def dispatch(command_input):
    """
        currently this will handle the given command_input by testing whether it
        fulfills a stub configuration. If so it will save a execution (with the expected flag
        set to true) and send the next answer as defined in the stub configuration object.
    """

    stub_configurations = deserialize_stub_configurations(
        CONFIGURED_STUBS_FILENAME)

    logging.info('Got %s', command_input)

    execution = Execution(
        command_input.command, command_input.arguments, command_input.stdin)

    for stub_configuration in stub_configurations:
        if command_input.fulfills(stub_configuration.command_input):
            logging.info('Execution fulfills %s', stub_configuration)
            execution.mark_as_expected()
            record_execution(execution)
            answer = stub_configuration.next_answer()
            serialize_as_dictionaries(
                CONFIGURED_STUBS_FILENAME, stub_configurations)
            unlock(lock_handle)
            if answer.milliseconds_to_wait:
                time.sleep(answer.milliseconds_to_wait / 1000)
            send_answer(answer)
            return

    unlock(lock_handle)
    logging.error(
        'Given command_input does not fulfill requirements of any stub configuration.')
    sys.exit(255)
コード例 #3
0
ファイル: execution_tests.py プロジェクト: pombredanne/shtub
    def test_should_mark_execution_as_fulfilled(self):
        execution = Execution(
            'any_command', ['any_arg1', 'any_arg2'], 'any_stdin')

        execution.mark_as_expected()

        self.assertTrue(execution.expected)