def _single_result(source, options):
    result = Result(source, rpa=options.pop('rpa', None))
    if source.upper().endswith("JSON"):
        try:
            with open(source, 'r') as source_file:
                json_data = json.load(source_file)
            return JsonExecutionResultBuilder(json_data,
                                              **options).build(result)
        except IOError as err:
            error = err.strerror
        except Exception:
            traceback.print_exc()
            error = get_error_message()
        raise DataError("Reading JSON source '%s' failed: %s" %
                        (unic(json_data), error))
    else:
        ets = ETSource(source)
        try:
            return XmlExecutionResultBuilder(ets, **options).build(result)
        except IOError as err:
            error = err.strerror
        except:
            error = get_error_message()
        raise DataError("Reading XML source '%s' failed: %s" %
                        (unic(ets), error))
Beispiel #2
0
 def _parse_spec(self, path):
     if not os.path.isfile(path):
         raise DataError("Spec file '%s' does not exist." % path)
     with ETSource(path) as source:
         root = ET.parse(source).getroot()
     if root.tag != 'keywordspec':
         raise DataError("Invalid spec file '%s'." % path)
     return root
 def test_rows_are_not_split_if_there_are_headers(self):
     output = self._add_long_step_and_save('html')
     with ETSource('\n'.join(output.splitlines()[1:])) as source:
         tree = ET.parse(source)
     lines = tree.findall('body/table/tr')
     assert_equal(len(lines), 3)
     for l in lines:
         cols = l.findall('td') or l.findall('th')
         assert_equal(len(cols), 9)
Beispiel #4
0
def _single_result(source, options):
    ets = ETSource(source)
    try:
        return ExecutionResultBuilder(ets, **options).build(Result(source))
    except IOError as err:
        error = err.strerror
    except:
        error = get_error_message()
    raise DataError("Reading XML source '%s' failed: %s" % (unic(ets), error))
Beispiel #5
0
def _single_result(source, options):
    ets = ETSource(source)
    result = Result(source, rpa=options.pop('rpa', None))
    try:
        return ExecutionResultBuilder(ets, **options).build(result)
    except IOError as err:
        error = err.strerror
    except:
        error = get_error_message()
    raise DataError(f"Reading XML source '{ets}' failed: {error}")
Beispiel #6
0
    def __init__(self, source, include_keywords=True):
        """Builds :class:`~.executionresult.Result` objects from existing
        output XML files on the file system.

        :param source: Path to output XML file.
        :param include_keywords: Include keyword information to the
            :class:`~.executionresult.Result` objects
        """
        self._source = source \
            if isinstance(source, ETSource) else ETSource(source)
        self._include_keywords = include_keywords
Beispiel #7
0
 def _parse_spec(self, path):
     if not os.path.isfile(path):
         raise DataError(f"Spec file '{path}' does not exist.")
     with ETSource(path) as source:
         root = ET.parse(source).getroot()
     if root.tag != 'keywordspec':
         raise DataError(f"Invalid spec file '{path}'.")
     version = root.get('specversion')
     if version not in ('3', '4'):
         raise DataError(f"Invalid spec file version '{version}'. "
                         f"Supported versions are 3 and 4.")
     return root
 def _parse_spec(self, path):
     if not os.path.isfile(path):
         raise DataError("Spec file '%s' does not exist." % path)
     with ETSource(path) as source:
         root = ET.parse(source).getroot()
     if root.tag != 'keywordspec':
         raise DataError("Invalid spec file '%s'." % path)
     version = root.get('specversion')
     if version != '3':
         raise DataError("Invalid spec file version '%s'. "
                         "Robot Framework 4.0 and newer requires spec version 3." % version)
     return root
 def __init__(self, source, include_keywords=True, flattened_keywords=None):
     """
     :param source: Path to the XML output file to build
         :class:`~.executionresult.Result` objects from.
     :param include_keywords: Boolean controlling whether to include
         keyword information in the result or not. Keywords are
         not needed when generating only report.
     :param flatten_keywords: List of patterns controlling what keywords to
         flatten. See the documentation of ``--flattenkeywords`` option for
         more details.
     """
     self._source = source \
         if isinstance(source, ETSource) else ETSource(source)
     self._include_keywords = include_keywords
     self._flattened_keywords = flattened_keywords
def ExecutionResult(*sources):
    """Constructs :class:`Result` object based on execution result xml file(s).

    :param sources: The Robot Framework output xml file(s).
    :returns: :py:class:`~.executionresult.Result` instance.

    See :py:mod:`robot.result` for usage example.
    """
    if not sources:
        raise DataError('One or more data source needed.')
    if len(sources) > 1:
        return CombinedResult(*[ExecutionResult(src) for src in sources])
    source = ETSource(sources[0])
    try:
        return ExecutionResultBuilder(source).build(Result(sources[0]))
    except IOError, err:
        error = err.strerror
Beispiel #11
0
    def parse_xml(self, source):
        """Parses the given XML file or string into an element structure.

        The `source` can either be a path to an XML file or a string containing
        XML. In both cases the XML is parsed into ElementTree
        [http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element|element structure]
        and the root element is returned.

        Examples:
        | ${xml} =  | Parse XML | ${CURDIR}/test.xml    |
        | ${root} = | Parse XML | <root><child/></root> |

        For more details and examples, see `Parsing XML` section in the
        `introduction`.

        See also `Get Element` and `Get Elements`.
        """
        with ETSource(source) as source:
            return ET.parse(source).getroot()
 def _get_root(self):
     self.writer.close()
     with ETSource(PATH) as source:
         return ET.parse(source).getroot()
 def __init__(self, source):
     self._source = source \
         if isinstance(source, ETSource) else ETSource(source)
Beispiel #14
0
def _single_result(source, options):
    ets = ETSource(source)
    try:
        return ExecutionResultBuilder(ets, **options).build(Result(source))
    except IOError, err:
        error = err.strerror
 def __init__(self, source, include_keywords=True):
     self._source = source \
         if isinstance(source, ETSource) else ETSource(source)
     self._include_keywords = include_keywords
Beispiel #16
0
 def parse_xml(self, source):
     with ETSource(source) as source:
         return ET.parse(source).getroot()
Beispiel #17
0
 def _xml_lines(self, text):
     with ETSource(text) as source:
         tree = ET.parse(source)
     output = BytesIO()
     tree.write(output)
     return output.getvalue().splitlines()
Beispiel #18
0
 def _parse_spec(self, path):
     with ETSource(path) as source:
         return ET.parse(source).getroot()