Ejemplo n.º 1
0
 def test_with_suites_and_tests_no_matches(self):
     suite = _get_suite()
     for suites, tests in [ (['Root'], ['nonex']),
                            (['Nonex'], ['T1.1']),
                            (['Sub2'], ['T1.1']), ]:
         msg = ("Suite 'Root' contains no test cases %s in suites %s."
                % (utils.seq2str(tests, lastsep=' or '),
                   utils.seq2str(suites, lastsep=' or ')))
         assert_raises_with_msg(DataError, msg, suite.filter_by_names, suites, tests)
Ejemplo n.º 2
0
 def _raise_no_tests_filtered_by_names(self, suites, tests):
     tests = utils.seq2str(list(tests), lastsep=' or ')
     suites = utils.seq2str(['.'.join(p + s) for p, s in suites],
                            lastsep=' or ')
     if not suites:
         msg = 'test cases named %s.' % tests
     elif not tests:
         msg = 'test suites named %s.' % suites
     else:
         msg = 'test cases %s in suites %s.' % (tests, suites)
     raise DataError("Suite '%s' contains no %s" % (self.name, msg))
Ejemplo n.º 3
0
 def _raise_no_tests_filtered_by_tags(self, incls, excls):
     incl = utils.seq2str(incls)
     excl = utils.seq2str(excls)
     msg = "Suite '%s' with "  % self.name
     if incl:
         msg += 'includes %s ' % incl
         if excl:
             msg += 'and '
     if excl:
         msg += 'excludes %s ' % excl
     raise DataError(msg + 'contains no test cases.')
 def _validate_no_named_only_missing(self, named, spec):
     defined = set(named) | set(spec.defaults)
     missing = [arg for arg in spec.kwonlyargs if arg not in defined]
     if missing:
         raise DataError("%s '%s' missing named-only argument%s %s."
                         % (spec.type, spec.name, plural_or_not(missing),
                            seq2str(sorted(missing))))
Ejemplo n.º 5
0
 def _get_message(self):
     expected = "'%s'" % self.expected if isinstance(self.expected, basestring) \
                else utils.seq2str(self.expected, lastsep=' or ')
     msg = "No match found for %s in %s." % (expected, self.timeout)
     if self.output is not None:
         msg += ' Output:\n%s' % self.output
     return msg
Ejemplo n.º 6
0
 def _raise_multiple_matching_keywords_found(self, name, found):
     names = utils.seq2str([f.orig_name for f in found])
     if self.name is None:
         where = "Test case file"
     else:
         where = "Resource file '%s'" % self.name
     raise DataError("%s contains multiple keywords matching name '%s'\n" "Found: %s" % (where, name, names))
Ejemplo n.º 7
0
 def _raise_multiple_keywords_found(self, name, found, implicit=True):
     error = "Multiple keywords with name '%s' found.\n" % name
     if implicit:
         error += "Give the full name of the keyword you want to use.\n"
     names = sorted(handler.longname for handler in found)
     error += "Found: %s" % utils.seq2str(names)
     raise DataError(error)
 def _validate_no_extra_named(self, named, spec):
     if not spec.kwargs:
         extra = set(named) - set(spec.positional) - set(spec.kwonlyargs)
         if extra:
             raise DataError("%s '%s' got unexpected named argument%s %s."
                             % (spec.type, spec.name, plural_or_not(extra),
                                seq2str(sorted(extra))))
Ejemplo n.º 9
0
    def read_until_regexp(self, *expected):
        """Reads from the current output, until a match to a regexp in expected.

        Expected is a list of regular expression patterns as strings,
        or compiled regular expressions. The keyword returns the text
        up to and including the first match to any of the regular
        expressions.

        If the last argument in `*expected` is a valid log level, it
        is used as `loglevel` in the keyword `Read`.

        Examples:
        | Read Until Regexp | (#|$) |
        | Read Until Regexp | first_regexp | second_regexp |
        | Read Until Regexp | some regexp  | DEBUG |
        """
        expected = list(expected)
        if self._is_valid_log_level(expected[-1]):
            loglevel = expected[-1]
            expected = expected[:-1]
        else:
            loglevel = 'INFO'
        try:
            index, _, ret = self.expect(expected, self._timeout)
        except TypeError:
            index, ret = -1, ''
        ret = ret.decode('ASCII', 'ignore')
        self._log(ret, loglevel)
        if index == -1:
            expected = [ exp if isinstance(exp, basestring) else exp.pattern
                         for exp in expected ]
            raise AssertionError("No match found for %s in %s"
                                 % (utils.seq2str(expected, lastsep=' or '),
                                    utils.secs_to_timestr(self._timeout)))
        return ret
Ejemplo n.º 10
0
 def _get_test_selector_msgs(self):
     parts = []
     for explanation, selector in [('matching tags', self.include_tags),
                                   ('not matching tags', self.exclude_tags),
                                   ('matching name', self.include_tests)]:
         if selector:
             parts.append(self._format_selector_msg(explanation, selector))
     return seq2str(parts, quote='')
Ejemplo n.º 11
0
 def _get_test_selector_msgs(self):
     parts = []
     for explanation, selector in [('with tags', self.include_tags),
                                   ('without tags', self.exclude_tags),
                                   ('named', self.include_tests)]:
         if selector:
            parts.append(self._format_selector_msg(explanation, selector))
     return utils.seq2str(parts, quote='')
 def _js_logger(self, base, code, args):
     message = '%s:\n%s\n' % (base, code)
     if args:
         message = ('%sBy using argument%s:\n%s'
                    % (message, plural_or_not(args), seq2str(args)))
     else:
         message = '%sWithout any arguments.' % message
     self.info(message)
Ejemplo n.º 13
0
 def __init__(self, type, name, args=(), alias=None, source=None):
     if type not in self.ALLOWED_TYPES:
         raise ValueError("Invalid import type '%s'. Should be one of %s."
                          % (type, seq2str(self.ALLOWED_TYPES, lastsep=' or ')))
     self.type = type
     self.name = name
     self.args = args
     self.alias = alias
     self.source = source
Ejemplo n.º 14
0
 def _raise_creating_instance_failed(self):
     msg, details = utils.get_error_details()
     if self.positional_args:
         args = "argument%s %s" % (utils.plural_or_not(self.positional_args),
                                   utils.seq2str(self.positional_args))
     else:
         args = "no arguments"
     raise DataError("Creating an instance of the test library '%s' with %s "
                     "failed: %s\n%s" % (self.name, args, msg, details))
 def _convert(self, value, explicit_type=True):
     try:
         # This is compatible with the enum module in Python 3.4, its
         # enum34 backport, and the older enum module. `self._enum[value]`
         # wouldn't work with the old enum module.
         return getattr(self._enum, value)
     except AttributeError:
         members = self._get_members(self._enum)
         raise ValueError("%s does not have member '%s'. Available: %s"
                          % (self.type_name, value, seq2str(members)))
Ejemplo n.º 16
0
 def validate_type_dict(self, types):
     # 'return' isn't used for anything yet but it may be shown by Libdoc
     # in the future. Trying to be forward compatible.
     names = set(self._argspec.argument_names + ['return'])
     extra = [t for t in types if t not in names]
     if extra:
         raise DataError('Type information given to non-existing '
                         'argument%s %s.'
                         % (s(extra), seq2str(sorted(extra))))
     return types
Ejemplo n.º 17
0
    def list_should_contain_value(self,list_,value,msg=None):
        """
        fails if the 'value' is not found from list.

        if msg is not given. the default error message "[a|b|c]  does not contain the value 'x'" is shown in case of
        a failure.Otherwise.the given 'msg' is used in case of a failure

        """

        default ="%s contains value '%s'" %(seq2str(list_),value)
        _verify_condition(vlaue not in list_,default,msg)
Ejemplo n.º 18
0
 def set_tags(self,*tags):
     ctx = self._context
     if ctx.test:
         ctx.test.tags.add(tags)
         ctx.variables.set_test('@{TEST_TAGS}',list(ctx.test.tags))
     elif not ctx.in_suite_teardown:
         ctx.cuit.set_tags(tags,persist=True)
     else:
         raise RuntimeError(" 'set tags' cannot be used in suite teardown.")
     self.log('set tags%s %s.' %(utils.plural_or_not(tags),
                                 utils.seq2str(tags)))
Ejemplo n.º 19
0
 def _raise_no_single_match(self, name, found):
     if self._source is None:
         where = "Test case file"
     else:
         where = "Resource file '%s'" % self._source
     if not found:
         raise DataError("%s contains no keywords matching name '%s'."
                         % (where, name))
     names = seq2str([f.orig_name for f in found])
     # TODO: List found on separate lines like kw/var recommendations.
     # Both here and in namespace when multiple keywords match.
     raise DataError("%s contains multiple keywords matching name '%s'.\n"
                     "Found: %s" % (where, name, names))
Ejemplo n.º 20
0
 def _validate_arguments_exist(self, arguments):
     valid = []
     nonex = []
     for arg in arguments:
         (valid if os.path.exists(arg) else nonex).append(arg)
     if nonex:
         s, were = ('s', 'were') if len(nonex) > 1 else ('', 'was')
         LOGGER.warn("Argument%s %s did not exist and %s ignored. "
                     "Validate the used command line syntax."
                     % (s, seq2str(nonex), were))
         if not valid:
             raise DataError('No valid arguments given.')
     return valid
Ejemplo n.º 21
0
    def read_until_prompt(self, loglevel=None):
        """Reads from the current output until prompt is found.

        Expected is a list of regular expressions, and keyword returns the text
        up until and including the first match to any of the regular
        expressions.
        """
        loglevel = loglevel == None and self._loglevel or loglevel
        ret = self.expect(self._prompt, self._timeout)
        if ret[0] == -1 :
            self._log("Get Response: " + ret[2],'WARN')
            raise AssertionError("No match found for prompt '%s',detail info: %s "
                                 % (utils.seq2str([x.pattern for x in self._prompt ], lastsep=' or '),ret[2]))
        self._log("Get Response: " + ret[2], loglevel)
        return ret[2]
Ejemplo n.º 22
0
    def  list_should_not_contain_duplicates(self,list_,msg=None):
        """
        fails if any element in the 'list' is found from it more that were found
        from the 'list' multiple times .but it can be overriden by giving
        a custom 'msg' .All multiple times found items and their counts are also logged

        this keyword works with all iterables that can be converted to a list
        the original iterable is never altered

        """
        if not isinstance(list_,list):
            list_= list(list_)
        dupes = []
        for item in list_:
            if item not in dupes:
                count = list_.count(item)
                if count >1:
                    logger.info(" '%s' found %d times" %(item,count))
                    dupes.append(item)
        if dupes:
            raise AssertionError(msg or '%s found multiple times' %seq2str(dupes))
Ejemplo n.º 23
0
    def list_should_not_contain_duplicates(self, list_, msg=None):
        """Fails if any element in the `list` is found from it more than once.

        The default error message lists all the elements that were found
        from the `list` multiple times, but it can be overridded by giving
        a custom `msg`. All multiple times found items and their counts are
        also logged.

        This keyword works with all iterables that can be converted to a list.
        The original iterable is never altered.
        """
        if not isinstance(list_, list):
            list_ = list(list_)
        dupes = []
        for item in list_:
            if item not in dupes:
                count = list_.count(item)
                if count > 1:
                    print "*INFO* '%s' found %d times" % (item, count)
                    dupes.append(item)
        if dupes:
            if not msg:
                msg = "%s found multiple times" % utils.seq2str(dupes)
            raise AssertionError(msg)
Ejemplo n.º 24
0
 def _raise_error_from_duplicate_keywords(self, name, libs):
     kw_names = ['%s.%s' % (lib.name, name) for lib in libs]
     raise RuntimeError("Keyword '%s' available from multiple remote libraries. Use: %s" % (name, seq2str(kw_names, lastsep=' or ')))
Ejemplo n.º 25
0
 def _format_selector_msg(self, explanation, selector):
     if len(selector) == 1 and explanation[-1] == 's':
         explanation = explanation[:-1]
     return '%s %s' % (explanation, utils.seq2str(selector, lastsep=' or '))
Ejemplo n.º 26
0
 def _raise_no_match_found(self, expected, timeout=None):
     timeout = utils.secs_to_timestr(timeout or self._timeout)
     expected = "'%s'" % expected if isinstance(expected, basestring) \
         else utils.seq2str(expected, lastsep=' or ')
     raise AssertionError("No match found for %s in %s" % (expected, timeout))
Ejemplo n.º 27
0
 def _format_selector_msg(self, explanation, selector):
     if isinstance(selector, basestring):
         selector = [selector]
     if len(selector) == 1 and explanation[-1] == 's':
         explanation = explanation[:-1]
     return '%s %s' % (explanation, utils.seq2str(selector, lastsep=' or '))
Ejemplo n.º 28
0
 def _verify_format(self, type, format, valid):
     format = format.upper()
     if format not in valid:
         raise DataError("%s must be %s, got '%s'."
                         % (type, seq2str(valid, lastsep=' or '), format))
     return format
Ejemplo n.º 29
0
Archivo: model.py Proyecto: nbbull/RIDE
    try:
        return TestData(source=path, include_suites=include_suites, warn_on_skipped=warn_on_skipped)
    except DataError, err:
        raise DataError("Parsing '%s' failed: %s" % (path, unicode(err)))


def _get_multisource_suite(datasources, include_suites, warn_on_skipped):
    suitedatas = []
    for datasource in datasources:
        try:
            suitedatas.append(_parse_suite(datasource, include_suites, warn_on_skipped))
        except DataError, err:
            LOGGER.warn(err)
    suite = RunnableMultiTestSuite(suitedatas)
    if suite.get_test_count() == 0:
        raise DataError("Data sources %s contain no test cases." % utils.seq2str(datasources))
    return suite


def _check_suite_contains_tests(suite, run_empty_suites=False):
    suite.filter_empty_suites()
    if not suite.get_test_count() and not run_empty_suites:
        raise DataError("Test suite '%s' contains no test cases." % (suite.source))


class RunnableTestSuite(BaseTestSuite):
    def __init__(self, data, parent=None, defaults=None):
        BaseTestSuite.__init__(self, data.name, data.source, parent)
        self.variables = GLOBAL_VARIABLES.copy()
        self.variables.set_from_variable_table(data.variable_table)
        self.source = data.source
Ejemplo n.º 30
0
 def test_seq2str(self):
     patterns = TagPatterns([u'is\xe4', u'\xe4iti'])
     assert_equal(utils.seq2str(patterns), u"'is\xe4' and '\xe4iti'")