Ejemplo n.º 1
0
    def status(self):
        """
        Writes a (final) status message to the log, telling the user how
        many errors and warnings were logged by this instance.

        Example:

            >>> l = Logger('test')
            >>> l.error('message')
            ERROR: message
            >>> l.warn('message')
            WARNING: message
            >>> l.status()
            Logged 1 error and 1 warning.
            >>> l.reset_stats()
            >>> l.status()
            Logged 0 errors and 0 warnings.

        """
        errors = _tu.format_plural('error', self._num_err)
        warnings = _tu.format_plural('warning', self._num_warn)
        self.info('Logged {} and {}.', errors, warnings)
Ejemplo n.º 2
0
def test_formatplural():
    assert textutils.format_plural('test', 0) == '0 tests'
    assert textutils.format_plural('test', 1) == '1 test'
    assert textutils.format_plural('test', 2) == '2 tests'
    assert textutils.format_plural('test', 3.14) == '3.14 tests'
    assert textutils.format_plural('bus', 2, 'es') == '2 buses'
    with pytest.raises(TypeError):
        textutils.format_plural(1, 'test')
        textutils.format_plural(None, 1)
        textutils.format_plural('test', None)
    with pytest.raises(ValueError):
        textutils.format_plural('123', 0)
        textutils.format_plural('--test--', 1)