Exemple #1
0
    def status(self, status, message='', just=None, level=logging.INFO):
        if just == 'center':
            status = status.center(self.status_width - 2)
        elif just == 'right':
            status = status.rjust(self.status_width - 2)
        else:
            status = status.ljust(self.status_width - 2)

        status_stripped = status.strip()
        if self.colorize:
            if status_stripped == 'SKIP':
                status = color.colorize(status, color.YELLOW)
            elif status_stripped in ['FAIL', 'FAILED', 'ERROR']:
                status = color.colorize(status, color.RED)
            else:
                status = color.colorize(status, color.GREEN)

        final_msg = f'[ {status} ] '
        if status_stripped in ['OK', 'SKIP', 'FAIL']:
            self._progress_count += 1
            width = len(str(self._progress_total))
            padded_progress = str(self._progress_count).rjust(width)
            final_msg += f'({padded_progress}/{self._progress_total}) '

        final_msg += message
        logging.getlogger().log(level, final_msg)
Exemple #2
0
def test_colorize():
    s = color.colorize('hello', color.RED, palette='ANSI')
    assert '\033' in s
    assert '[3' in s
    assert '1m' in s
    with pytest.raises(ValueError):
        color.colorize('hello', color.RED, palette='FOO')

    with pytest.raises(ValueError):
        color.colorize('hello', color.ColorRGB(128, 0, 34), palette='ANSI')
Exemple #3
0
    def test_colorize(self):
        s = color.colorize('hello', color.RED, palette='ANSI')
        self.assertIn('\033', s)
        self.assertIn('[3', s)
        self.assertIn('1m', s)

        with self.assertRaises(ValueError):
            color.colorize('hello', color.RED, palette='FOO')

        with self.assertRaises(ValueError):
            color.colorize('hello', color.ColorRGB(128, 0, 34), palette='ANSI')
Exemple #4
0
def test_deprecation_warning_formatting(with_colors):
    message = warnings.formatwarning('deprecated',
                                     warn.ReframeDeprecationWarning, 'file',
                                     10, 'a = 1')
    expected = 'file:10: WARNING: deprecated\na = 1\n'
    if with_colors:
        expected = color.colorize(expected, color.YELLOW)

    assert message == expected
Exemple #5
0
    def status(self, status, message='', just=None, level=logging.INFO):
        if just == 'center':
            status = status.center(self.status_width - 2)
        elif just == 'right':
            status = status.rjust(self.status_width - 2)
        else:
            status = status.ljust(self.status_width - 2)

        if self.colorize:
            status_stripped = status.strip().lower()
            if status_stripped == 'skip':
                status = color.colorize(status, color.YELLOW)
            elif status_stripped in ['fail', 'failed', 'error']:
                status = color.colorize(status, color.RED)
            else:
                status = color.colorize(status, color.GREEN)

        logging.getlogger().log(level, '[ %s ] %s' % (status, message))
Exemple #6
0
def test_deprecation_warning_formatting_noline(tmp_path, with_colors):
    srcfile = tmp_path / 'file'
    srcfile.touch()

    message = warnings.formatwarning('deprecated',
                                     warn.ReframeDeprecationWarning, srcfile,
                                     10)
    expected = f'{srcfile}:10: WARNING: deprecated\n<no line information>\n'
    if with_colors:
        expected = color.colorize(expected, color.YELLOW)

    assert message == expected
Exemple #7
0
    def warning(self, message, *args, cache=False, **kwargs):
        if cache:
            if message in _WARN_ONCE:
                return

            _WARN_ONCE.add(message)

        message = f'{sys.argv[0]}: {message}'
        if self.colorize:
            message = color.colorize(message, color.YELLOW)

        super().warning(message, *args, **kwargs)
Exemple #8
0
def _format_warning(message, category, filename, lineno, line=None):
    import reframe.core.runtime as rt
    import reframe.utility.color as color

    if category != ReframeDeprecationWarning:
        return _format_warning_orig(message, category, filename, lineno, line)

    if line is None:
        # Read in the line from the file
        with open(filename) as fp:
            try:
                line = fp.readlines()[lineno - 1]
            except IndexError:
                line = '<no line information>'

    message = f'{filename}:{lineno}: WARNING: {message}\n{line}\n'

    # Ignore coloring if runtime has not been initialized; this can happen
    # when generating the documentation of deprecated APIs
    with contextlib.suppress(ReframeFatalError):
        if rt.runtime().get_option('general/0/colorize'):
            message = color.colorize(message, color.YELLOW)

    return message
Exemple #9
0
    def error(self, message, *args, **kwargs):
        message = '%s: %s' % (sys.argv[0], message)
        if self.colorize:
            message = color.colorize(message, color.RED)

        super().error(message, *args, **kwargs)
Exemple #10
0
    def warning(self, message, *args, **kwargs):
        message = '%s: %s' % (sys.argv[0], message)
        if self.colorize:
            message = color.colorize(message, color.YELLOW)

        super().warning(message, *args, **kwargs)
Exemple #11
0
    def error(self, message, *args, **kwargs):
        message = f'{sys.argv[0]}: {message}'
        if self.colorize:
            message = color.colorize(message, color.RED)

        super().error(message, *args, **kwargs)