timid/steps.py
def parse_file(cls, ctxt, fname, key=None, step_addr=None):
        """
        Parse a YAML file containing test steps.

        :param ctxt: The context object.
        :param fname: The name of the file to parse.
        :param key: An optional dictionary key.  If specified, the
                    file must be a YAML dictionary, and the referenced
                    value will be interpreted as a list of steps.  If
                    not provided, the file must be a YAML list, which
                    will be interpreted as the list of steps.
        :param step_addr: The address of the step in the test
                          configuration.  This may be used in the case
                          of includes, for instance.

        :returns: A list of ``Step`` objects.
        """

        # Load the YAML file
        try:
            with open(fname) as f:
                step_data = yaml.load(f)
        except Exception as exc:
            raise ConfigError(
                'Failed to read file "%s": %s' % (fname, exc),
                step_addr,
            )

        # Do we have a key?
        if key is not None:
            if (not isinstance(step_data, collections.Mapping) or
                    key not in step_data):
                raise ConfigError(
                    'Bad step configuration file "%s": expecting dictionary '
                    'with key "%s"' % (fname, key),
                    step_addr,
                )

            # Extract just the step data
            step_data = step_data[key]

        # Validate that it's a sequence
        if not isinstance(step_data, collections.Sequence):
            addr = ('%s[%s]' % (fname, key)) if key is not None else fname
            raise ConfigError(
                'Bad step configuration sequence at %s: expecting list, '
                'not "%s"' % (addr, step_data.__class__.__name__),
                step_addr,
            )

        # OK, assemble the step list and return it
        steps = []
        for idx, step_conf in enumerate(step_data):
            steps.extend(cls.parse_step(
                ctxt, StepAddress(fname, idx, key), step_conf))

        return steps
def parse_file(cls, ctxt, fname, key=None, step_addr=None):
        """
        Parse a YAML file containing test steps.

        :param ctxt: The context object.
        :param fname: The name of the file to parse.
        :param key: An optional dictionary key.  If specified, the
                    file must be a YAML dictionary, and the referenced
                    value will be interpreted as a list of steps.  If
                    not provided, the file must be a YAML list, which
                    will be interpreted as the list of steps.
        :param step_addr: The address of the step in the test
                          configuration.  This may be used in the case
                          of includes, for instance.

        :returns: A list of ``Step`` objects.
        """

        # Load the YAML file
        try:
            with open(fname) as f:
                step_data = yaml.load(f)
        except Exception as exc:
            raise ConfigError(
                'Failed to read file "%s": %s' % (fname, exc),
                step_addr,
            )

        # Do we have a key?
        if key is not None:
            if (not isinstance(step_data, collections.Mapping) or
                    key not in step_data):
                raise ConfigError(
                    'Bad step configuration file "%s": expecting dictionary '
                    'with key "%s"' % (fname, key),
                    step_addr,
                )

            # Extract just the step data
            step_data = step_data[key]

        # Validate that it's a sequence
        if not isinstance(step_data, collections.Sequence):
            addr = ('%s[%s]' % (fname, key)) if key is not None else fname
            raise ConfigError(
                'Bad step configuration sequence at %s: expecting list, '
                'not "%s"' % (addr, step_data.__class__.__name__),
                step_addr,
            )

        # OK, assemble the step list and return it
        steps = []
        for idx, step_conf in enumerate(step_data):
            steps.extend(cls.parse_step(
                ctxt, StepAddress(fname, idx, key), step_conf))

        return steps
Parse a YAML file containing test steps.

        :param ctxt: The context object.
        :param fname: The name of the file to parse.
        :param key: An optional dictionary key.  If specified, the
                    file must be a YAML dictionary, and the referenced
                    value will be interpreted as a list of steps.  If
                    not provided, the file must be a YAML list, which
                    will be interpreted as the list of steps.
        :param step_addr: The address of the step in the test
                          configuration.  This may be used in the case
                          of includes, for instance.

        :returns: A list of ``Step`` objects.