Ejemplo n.º 1
0
 def should_contain_suites(self, suite, *expected_names):
     print 'Suite has suites', suite.suites
     actual_names = [s.name for s in suite.suites]
     assert_equals(len(actual_names), len(expected_names), 'Wrong number of subsuites')
     for expected in expected_names:
         if not utils.Matcher(expected).match_any(actual_names):
             raise AssertionError('Suite %s not found' % expected)
Ejemplo n.º 2
0
 def should_contain_suites(self, suite, *expected):
     logger.info('Suite has suites', suite.suites)
     expected = sorted(expected)
     actual = sorted(s.name for s in suite.suites)
     if len(actual) != len(expected):
         raise AssertionError("Wrong number of suites.\n"
                              "Expected (%d): %s\n"
                              "Actual   (%d): %s" %
                              (len(expected), ', '.join(expected),
                               len(actual), ', '.join(actual)))
     for name in expected:
         if not utils.Matcher(name).match_any(actual):
             raise AssertionError('Suite %s not found' % name)
Ejemplo n.º 3
0
    def _check_test_status(self, test, status=None, message=None):
        """Verifies that test's status and message are as expected.

        Expected status and message can be given as parameters. If expected
        status is not given, expected status and message are read from test's
        documentation. If documentation doesn't contain any of PASS, FAIL or
        ERROR, test's status is expected to be PASS. If status is given that is
        used. Expected message is documentation after given status. Expected
        message can also be regular expression. In that case expected match
        starts with REGEXP: , which is ignored in the regexp match.
        """
        if status is not None:
            test.exp_status = status
        if message is not None:
            test.exp_message = message
        if test.exp_status != test.status:
            if test.exp_status == 'PASS':
                if test.status == 'FAIL':
                    msg = ("Test '%s' was expected to PASS but it FAILED.\n\n"
                           "Error message:\n%s" % (test.name, test.message))
                else:
                    msg = (
                        "Test '%s' was expected to PASS but it was SKIPPED.\n\n"
                        "Test message:\n%s" % (test.name, test.message))
            else:
                msg = ("Test '%s' was expected to %s but it %sED.\n\n"
                       "Expected message:\n%s" %
                       (test.name, test.exp_status, test.status,
                        test.exp_message))
            raise AssertionError(msg)
        if test.exp_message == test.message:
            return
        if test.exp_message.startswith('REGEXP:'):
            pattern = self._get_pattern(test, 'REGEXP:')
            if re.match('^%s$' % pattern, test.message, re.DOTALL):
                return
        if test.exp_message.startswith('GLOB:'):
            pattern = self._get_pattern(test, 'GLOB:')
            matcher = utils.Matcher(pattern, caseless=False, spaceless=False)
            if matcher.match(test.message):
                return
        if test.exp_message.startswith('STARTS:'):
            start = self._get_pattern(test, 'STARTS:')
            if test.message.startswith(start):
                return
        raise AssertionError("Test '%s' had wrong message.\n\n"
                             "Expected:\n%s\n\nActual:\n%s\n" %
                             (test.name, test.exp_message, test.message))
Ejemplo n.º 4
0
    def check_test_status(self, test, status=None, message=None):
        """Verifies that test's status and message are as expected.

        Expected status and message can be given as parameters. If expected
        status is not given, expected status and message are read from test's
        documentation. If documentation doesn't contain any of PASS, FAIL or
        ERROR, test's status is expected to be PASS. If status is given that is
        used. Expected message is documentation after given status. Expected
        message can also be regular expression. In that case expected match
        starts with REGEXP: , which is ignored in the regexp match.
        """
        if status is not None:
            test.exp_status = status
        if message is not None:
            test.exp_message = message
        if test.exp_status != test.status:
            if test.exp_status == 'PASS':
                msg = "Test was expected to PASS but it FAILED. "
                msg += "Error message:\n" + test.message
            else:
                msg = "Test was expected to FAIL but it PASSED. "
                msg += "Expected message:\n" + test.exp_message
            raise AssertionError(msg)
        if test.exp_message == test.message:
            return
        if test.exp_message.startswith('REGEXP:'):
            pattern = test.exp_message.replace('REGEXP:', '', 1).strip()
            if re.match('^%s$' % pattern, test.message, re.DOTALL):
                return
        if test.exp_message.startswith('GLOB:'):
            pattern = test.exp_message.replace('GLOB:', '', 1).strip()
            matcher = utils.Matcher(pattern, caseless=False, spaceless=False)
            if matcher.match(test.message):
                return
        if test.exp_message.startswith('STARTS:'):
            start = test.exp_message.replace('STARTS:', '', 1).strip()
            if not start:
                raise RuntimeError("Empty 'STARTS:' is not allowed")
            if test.message.startswith(start):
                return
        raise AssertionError("Wrong message\n\n"
                             "Expected:\n%s\n\nActual:\n%s\n" %
                             (test.exp_message, test.message))