<commit_before>
"""
Tests for L{pyflakes.scripts.pyflakes}.
"""

import sys
from StringIO import StringIO

from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase

from pyflakes.messages import UnusedImport
from pyflakes.scripts.pyflakes import (
    checkPath,
    Reporter,
    )


def withStderrTo(stderr, f, *args, **kwargs):
    """
    Call C{f} with C{sys.stderr} redirected to C{stderr}.
    """
    (outer, sys.stderr) = (sys.stderr, stderr)
    try:
        return f(*args, **kwargs)
    finally:
        sys.stderr = outer


class LoggingReporter(object):

    def __init__(self, log):
        self.log = log

    def flake(self, message):
        self.log.append(('flake', str(message)))

    def ioError(self, filename, exception):
        self.log.append(('ioError', filename, exception.args[1]))

    def problemDecodingSource(self, filename):
        self.log.append(('problemDecodingSource', filename))

    def syntaxError(self, filename, msg, lineno, offset, line):
        self.log.append(('syntaxError', filename, msg, lineno, offset, line))



class TestReporter(TestCase):
    """
    Tests for L{Reporter}.
    """

    def test_problemDecodingSource(self):<commit_msg>Whitespace<commit_after>
"""
Tests for L{pyflakes.scripts.pyflakes}.
"""

import sys
from StringIO import StringIO

from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase

from pyflakes.messages import UnusedImport
from pyflakes.scripts.pyflakes import (
    checkPath,
    Reporter,
    )


def withStderrTo(stderr, f, *args, **kwargs):
    """
    Call C{f} with C{sys.stderr} redirected to C{stderr}.
    """
    (outer, sys.stderr) = (sys.stderr, stderr)
    try:
        return f(*args, **kwargs)
    finally:
        sys.stderr = outer



class LoggingReporter(object):

    def __init__(self, log):
        self.log = log


    def flake(self, message):
        self.log.append(('flake', str(message)))


    def ioError(self, filename, exception):
        self.log.append(('ioError', filename, exception.args[1]))


    def problemDecodingSource(self, filename):
        self.log.append(('problemDecodingSource', filename))


    def syntaxError(self, filename, msg, lineno, offset, line):
        self.log.append(('syntaxError', filename, msg, lineno, offset, line))



class TestReporter(TestCase):
    """
    Tests for L{Reporter}.
    """

    def test_problemDecodingSource(self):
{'fraction_non_alphanumeric': 0.12876935615321924, 'fraction_numerical': 0.0008149959250203749, 'mean_word_length': 3.431407942238267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7631995', 'n_tokens_mistral': 796, 'n_tokens_neox': 760, 'n_words': 187}