timid/main.py
def timid(ctxt, test, key=None, check=False, exts=None):
    """
    Execute a test described by a YAML file.

    :param ctxt: A ``timid.context.Context`` object.
    :param test: The name of a YAML file containing the test
                 description.  Note that the current working directory
                 set up in ``ctxt.environment`` does not affect the
                 resolution of this file.
    :param key: An optional key into the test description file.  If
                not ``None``, the file named by ``test`` must be a
                YAML dictionary of lists of steps; otherwise, it must
                be a simple list of steps.
    :param check: If ``True``, only performs a syntax check of the
                  test steps indicated by ``test`` and ``key``; the
                  test itself is not run.
    :param exts: An instance of ``timid.extensions.ExtensionSet``
                 describing the extensions to be called while
                 processing the test steps.
    """

    # Normalize the extension set
    if exts is None:
        exts = extensions.ExtensionSet()

    # Begin by reading the steps and adding them to the list in the
    # context (which may already have elements thanks to the
    # extensions)
    ctxt.emit('Reading test steps from %s%s...' %
              (test, '[%s]' % key if key else ''), debug=True)
    ctxt.steps += exts.read_steps(ctxt, steps.Step.parse_file(ctxt, test, key))

    # If all we were supposed to do was check, well, we've
    # accomplished that...
    if check:
        return None

    # Now we execute each step in turn
    for idx, step in enumerate(ctxt.steps):
        # Emit information about what we're doing
        ctxt.emit('[Step %d]: %s . . .' % (idx, step.name))

        # Run through extension hooks
        if exts.pre_step(ctxt, step, idx):
            ctxt.emit('[Step %d]: `- Step %s' %
                      (idx, steps.states[steps.SKIPPED]))
            continue

        # Now execute the step
        result = step(ctxt)

        # Let the extensions process the result of the step
        exts.post_step(ctxt, step, idx, result)

        # Emit the result
        ctxt.emit('[Step %d]: `- Step %s%s' %
                  (idx, steps.states[result.state],
                   ' (ignored)' if result.ignore else ''))

        # Was the step a success?
        if not result:
            msg = 'Test step failure'
            if result.msg:
                msg += ': %s' % result.msg

            return msg

    # All done!  And a success, to boot...
    return None
def timid(ctxt, test, key=None, check=False, exts=None):
    """
    Execute a test described by a YAML file.

    :param ctxt: A ``timid.context.Context`` object.
    :param test: The name of a YAML file containing the test
                 description.  Note that the current working directory
                 set up in ``ctxt.environment`` does not affect the
                 resolution of this file.
    :param key: An optional key into the test description file.  If
                not ``None``, the file named by ``test`` must be a
                YAML dictionary of lists of steps; otherwise, it must
                be a simple list of steps.
    :param check: If ``True``, only performs a syntax check of the
                  test steps indicated by ``test`` and ``key``; the
                  test itself is not run.
    :param exts: An instance of ``timid.extensions.ExtensionSet``
                 describing the extensions to be called while
                 processing the test steps.
    """

    # Normalize the extension set
    if exts is None:
        exts = extensions.ExtensionSet()

    # Begin by reading the steps and adding them to the list in the
    # context (which may already have elements thanks to the
    # extensions)
    ctxt.emit('Reading test steps from %s%s...' %
              (test, '[%s]' % key if key else ''), debug=True)
    ctxt.steps += exts.read_steps(ctxt, steps.Step.parse_file(ctxt, test, key))

    # If all we were supposed to do was check, well, we've
    # accomplished that...
    if check:
        return None

    # Now we execute each step in turn
    for idx, step in enumerate(ctxt.steps):
        # Emit information about what we're doing
        ctxt.emit('[Step %d]: %s . . .' % (idx, step.name))

        # Run through extension hooks
        if exts.pre_step(ctxt, step, idx):
            ctxt.emit('[Step %d]: `- Step %s' %
                      (idx, steps.states[steps.SKIPPED]))
            continue

        # Now execute the step
        result = step(ctxt)

        # Let the extensions process the result of the step
        exts.post_step(ctxt, step, idx, result)

        # Emit the result
        ctxt.emit('[Step %d]: `- Step %s%s' %
                  (idx, steps.states[result.state],
                   ' (ignored)' if result.ignore else ''))

        # Was the step a success?
        if not result:
            msg = 'Test step failure'
            if result.msg:
                msg += ': %s' % result.msg

            return msg

    # All done!  And a success, to boot...
    return None
Execute a test described by a YAML file.

    :param ctxt: A ``timid.context.Context`` object.
    :param test: The name of a YAML file containing the test
                 description.  Note that the current working directory
                 set up in ``ctxt.environment`` does not affect the
                 resolution of this file.
    :param key: An optional key into the test description file.  If
                not ``None``, the file named by ``test`` must be a
                YAML dictionary of lists of steps; otherwise, it must
                be a simple list of steps.
    :param check: If ``True``, only performs a syntax check of the
                  test steps indicated by ``test`` and ``key``; the
                  test itself is not run.
    :param exts: An instance of ``timid.extensions.ExtensionSet``
                 describing the extensions to be called while
                 processing the test steps.