Beispiel #1
0
 def _open(self, path):
     if not os.path.isfile(path):
         raise DataError("Data source does not exist.")
     try:
         # IronPython handles BOM incorrectly if not using binary mode:
         # https://ironpython.codeplex.com/workitem/34655
         return open(path, 'rb')
     except:
         raise DataError(get_error_message())
Beispiel #2
0
 def populate(self, path, resource=False):
     LOGGER.info("Parsing file '%s'." % path)
     source = self._open(path)
     try:
         self._get_reader(path, resource).read(source, self)
     except:
         raise DataError(get_error_message())
     finally:
         source.close()
Beispiel #3
0
 def _open(self, path):
     if not os.path.isfile(path):
         raise DataError("Data source does not exist.")
     try:
         # IronPython handles BOM incorrectly if not using binary mode:
         # https://ironpython.codeplex.com/workitem/34655
         return open(path, 'rb')
     except:
         raise DataError(get_error_message())
Beispiel #4
0
 def populate(self, path, resource=False):
     LOGGER.info("Parsing file '%s'." % path)
     source = self._open(path)
     try:
         self._get_reader(path, resource).read(source, self)
     except:
         raise DataError(get_error_message())
     finally:
         source.close()
Beispiel #5
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" % (unicode(ets), error))
Beispiel #6
0
 def _transform_items(self, items):
     try:
         items = [self._to_number_with_arithmetics(item) for item in items]
     except:
         raise DataError('Converting argument of FOR IN RANGE failed: %s.'
                         % get_error_message())
     if not 1 <= len(items) <= 3:
         raise DataError('FOR IN RANGE expected 1-3 arguments, got %d.'
                         % len(items))
     return frange(*items)
Beispiel #7
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("Reading XML source '%s' failed: %s" % (unic(ets), error))
Beispiel #8
0
 def _screenshot_to_file(self, path):
     path = self._validate_screenshot_path(path)
     logger.debug('Using %s modules for taking screenshot.'
                  % self._screenshot_taker.module)
     try:
         self._screenshot_taker(path)
     except:
         logger.warn('Taking screenshot failed: %s\n'
                     'Make sure tests are run with a physical or virtual display.'
                     % utils.get_error_message())
     return path
Beispiel #9
0
 def _screenshot_to_file(self, path):
     path = self._validate_screenshot_path(path)
     logger.debug('Using %s module/tool for taking screenshot.' %
                  self._screenshot_taker.module)
     try:
         self._screenshot_taker(path)
     except:
         logger.warn('Taking screenshot failed: %s\n'
                     'Make sure tests are run with a physical or virtual '
                     'display.' % get_error_message())
     return path
Beispiel #10
0
def gather_failed_suites(output):
    if output.upper() == 'NONE':
        return []
    gatherer = GatherFailedSuites()
    try:
        ExecutionResult(output, include_keywords=False).suite.visit(gatherer)
        if not gatherer.suites:
            raise DataError('All suites passed.')
    except:
        raise DataError("Collecting failed suites from '%s' failed: %s"
                        % (output, get_error_message()))
    return gatherer.suites
def gather_failed_tests(output):
    if output.upper() == 'NONE':
        return []
    gatherer = GatherFailedTests()
    try:
        ExecutionResult(output, include_keywords=False).suite.visit(gatherer)
        if not gatherer.tests:
            raise DataError('All tests passed.')
    except:
        raise DataError("Collecting failed tests from '%s' failed: %s" %
                        (output, get_error_message()))
    return gatherer.tests
Beispiel #12
0
 def _import_if_needed(self, path_or_variables, args=None):
     if not is_string(path_or_variables):
         return path_or_variables
     LOGGER.info("Importing variable file '%s' with args %s" %
                 (path_or_variables, args))
     if path_or_variables.lower().endswith('.yaml'):
         importer = YamlImporter()
     else:
         importer = PythonImporter()
     try:
         return importer.import_variables(path_or_variables, args)
     except:
         args = 'with arguments %s ' % seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s" %
                         (path_or_variables, args, get_error_message()))
Beispiel #13
0
def LibraryDocumentation(library_or_resource, name=None, version=None, doc_format=None):
    builder = DocumentationBuilder(library_or_resource)
    try:
        libdoc = builder.build(library_or_resource)
    except DataError:
        raise
    except:
        raise DataError("Building library '%s' failed: %s" % (library_or_resource, get_error_message()))
    if name:
        libdoc.name = name
    if version:
        libdoc.version = version
    if doc_format:
        libdoc.doc_format = doc_format
    return libdoc
Beispiel #14
0
 def _import_if_needed(self, path_or_variables, args=None):
     if not is_string(path_or_variables):
         return path_or_variables
     LOGGER.info("Importing variable file '%s' with args %s"
                 % (path_or_variables, args))
     if path_or_variables.lower().endswith('.yaml'):
         importer = YamlImporter()
     else:
         importer = PythonImporter()
     try:
         return importer.import_variables(path_or_variables, args)
     except:
         args = 'with arguments %s ' % seq2str2(args) if args else ''
         raise DataError("Processing variable file '%s' %sfailed: %s"
                         % (path_or_variables, args, get_error_message()))
def gather_failed_tests(output):
    if output.upper() == 'NONE':
        return []
    gatherer = GatherFailedTests()
    tests_or_tasks = 'tests or tasks'
    try:
        suite = ExecutionResult(output, include_keywords=False).suite
        suite.visit(gatherer)
        tests_or_tasks = 'tests' if not suite.rpa else 'tasks'
        if not gatherer.tests:
            raise DataError('All %s passed.' % tests_or_tasks)
    except:
        raise DataError("Collecting failed %s from '%s' failed: %s" %
                        (tests_or_tasks, output, get_error_message()))
    return gatherer.tests
 def find(self, name):
     match = self._match_extended(name[2:-1])
     if match is None:
         raise ValueError
     base_name, extended = match.groups()
     try:
         variable = self._find_variable('${%s}' % base_name)
     except DataError as err:
         raise VariableError("Resolving variable '%s' failed: %s" %
                             (name, unicode(err)))
     try:
         return eval('_BASE_VAR_' + extended, {'_BASE_VAR_': variable})
     except:
         raise VariableError("Resolving variable '%s' failed: %s" %
                             (name, get_error_message()))
Beispiel #17
0
 def find(self, name):
     match = self._match_extended(name[2:-1])
     if match is None:
         raise ValueError
     base_name, extended = match.groups()
     try:
         variable = self._find_variable('${%s}' % base_name)
     except DataError as err:
         raise VariableError("Resolving variable '%s' failed: %s"
                             % (name, err.message))
     try:
         return eval('_BASE_VAR_' + extended, {'_BASE_VAR_': variable})
     except:
         raise VariableError("Resolving variable '%s' failed: %s"
                             % (name, get_error_message()))
Beispiel #18
0
def gather_failed_tests(output):
    if output.upper() == 'NONE':
        return []
    gatherer = GatherFailedTests()
    tests_or_tasks = 'tests or tasks'
    try:
        suite = ExecutionResult(output, include_keywords=False).suite
        suite.visit(gatherer)
        tests_or_tasks = 'tests' if not suite.rpa else 'tasks'
        if not gatherer.tests:
            raise DataError('All %s passed.' % tests_or_tasks)
    except:
        raise DataError("Collecting failed %s from '%s' failed: %s"
                        % (tests_or_tasks, output, get_error_message()))
    return gatherer.tests
 def test(self, path=None):
     print "Using '%s' module." % self.module
     if not self:
         return False
     if not path:
         print "Not taking test screenshot."
         return True
     print "Taking test screenshot to '%s'." % path
     try:
         self(path)
     except:
         print "Failed: %s" % utils.get_error_message()
         return False
     else:
         print "Success!"
         return True
Beispiel #20
0
 def test(self, path=None):
     print "Using '%s' module." % self.module
     if not self:
         return False
     if not path:
         print "Not taking test screenshot."
         return True
     print "Taking test screenshot to '%s'." % path
     try:
         self(path)
     except:
         print "Failed: %s" % utils.get_error_message()
         return False
     else:
         print "Success!"
         return True
Beispiel #21
0
 def test(self, path=None):
     if not self:
         print("Cannot take screenshots.")
         return False
     print("Using '%s' to take screenshot." % self.module)
     if not path:
         print("Not taking test screenshot.")
         return True
     print("Taking test screenshot to '%s'." % path)
     try:
         self(path)
     except:
         print("Failed: %s" % get_error_message())
         return False
     else:
         print("Success!")
         return True
Beispiel #22
0
 def find(self, name):
     validate_var(name, '$@&%')
     identifier = name[0]
     for finder in self._finders:
         if identifier in finder.identifiers:
             try:
                 value = finder.find(name)
             except (KeyError, ValueError):
                 continue
             try:
                 return self._validate_value(value, identifier, name)
             except VariableError:
                 raise
             except:
                 raise VariableError("Resolving variable '%s' failed: %s"
                                     % (name, get_error_message()))
     variable_not_found(name, self._store.data)
Beispiel #23
0
 def find(self, name):
     validate_var(name, '$@&%')
     identifier = name[0]
     for finder in self._finders:
         if identifier in finder.identifiers:
             try:
                 value = finder.find(name)
             except (KeyError, ValueError):
                 continue
             try:
                 return self._validate_value(value, identifier, name)
             except VariableError:
                 raise
             except:
                 raise VariableError("Resolving variable '%s' failed: %s" %
                                     (name, get_error_message()))
     variable_not_found(name, self._store.data)
Beispiel #24
0
 def _extended_assign(self, name, value, variables):
     if name[0] != '$' or '.' not in name or name in variables:
         return False
     base, attr = self._split_extended_assign(name)
     try:
         var = variables[base]
     except DataError:
         return False
     if not (self._variable_supports_extended_assign(var) and
             self._is_valid_extended_attribute(attr)):
         return False
     try:
         setattr(var, attr, value)
     except:
         raise DataError("Setting attribute '%s' to variable '%s' failed: %s"
                         % (attr, base, get_error_message()))
     return True
Beispiel #25
0
 def test(self, path=None):
     if not self:
         print("Cannot take screenshots.")
         return False
     print("Using '%s' to take screenshot." % self.module)
     if not path:
         print("Not taking test screenshot.")
         return True
     print("Taking test screenshot to '%s'." % path)
     try:
         self(path)
     except:
         print("Failed: %s" % get_error_message())
         return False
     else:
         print("Success!")
         return True
Beispiel #26
0
 def _extended_assign(self, name, value, variables):
     if name[0] != '$' or '.' not in name or name in variables:
         return False
     base, attr = self._split_extended_assign(name)
     try:
         var = variables[base]
     except DataError:
         return False
     if not (self._variable_supports_extended_assign(var)
             and self._is_valid_extended_attribute(attr)):
         return False
     try:
         setattr(var, attr, value)
     except:
         raise VariableError("Setting attribute '%s' to variable '%s' "
                             "failed: %s" %
                             (attr, base, get_error_message()))
     return True
Beispiel #27
0
def LibraryDocumentation(library_or_resource,
                         name=None,
                         version=None,
                         doc_format=None):
    builder = DocumentationBuilder(library_or_resource)
    try:
        libdoc = builder.build(library_or_resource)
    except DataError:
        raise
    except:
        raise DataError("Building library '%s' failed: %s" %
                        (library_or_resource, get_error_message()))
    if name:
        libdoc.name = name
    if version:
        libdoc.version = version
    if doc_format:
        libdoc.doc_format = doc_format
    return libdoc
Beispiel #28
0
 def __call__(self, *args):
     try:
         return self._handle_return_value(self.method(*args))
     except:
         raise DataError("Calling dynamic method '%s' failed: %s"
                         % (self.method.__name__, get_error_message()))
Beispiel #29
0
 def __call__(self, *args):
     try:
         return self._handle_return_value(self.method(*args))
     except:
         raise DataError("Calling dynamic method '%s' failed: %s" %
                         (self.method.__name__, get_error_message()))
Beispiel #30
0
 def _compile_regexp(self, pattern):
     try:
         return re.compile(''.join(pattern), re.IGNORECASE)
     except:
         raise DataError("Compiling embedded arguments regexp failed: %s"
                         % get_error_message())