<commit_before>import os
import tempfile
import unittest
from mock import patch
from ddt import ddt, file_data

import pavelib.quality
import paver.easy
from paver.easy import BuildFailure


@ddt
class TestPaverQualityViolations(unittest.TestCase):

    def setUp(self):
        self.f = tempfile.NamedTemporaryFile(delete=False)
        self.f.close()

    def test_pylint_parser_other_string(self):
        with open(self.f.name, 'w') as f:
            f.write("hello")
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 0)

    def test_pylint_parser_pep8(self):
        # Pep8 violations should be ignored.
        with open(self.f.name, 'w') as f:
            f.write("foo/hello/test.py:304:15: E203 whitespace before ':'")
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 0)

    @file_data('pylint_test_list.json')
    def test_pylint_parser_count_violations(self, value):
    # Tests:
    #     * Different types of violations
    #     * One violation covering multiple lines
        with open(self.f.name, 'w') as f:
            f.write(value)
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 1)

    def test_pep8_parser(self):
        with open(self.f.name, 'w') as f:
            f.write("hello\nhithere")
        num = pavelib.quality._count_pep8_violations(f.name)
        self.assertEqual(num, 2)

    def tearDown(self):
        os.remove(self.f.name)


class TestPaverRunQuality(unittest.TestCase):
    """
    For testing the paver run_quality task
    """

    def setUp(self):

        # mock the @needs decorator to skip it
        self._mock_paver_needs = patch.object(pavelib.quality.run_quality, 'needs').start()
        self._mock_paver_needs.return_value = 0
        self._mock_paver_sh = patch('pavelib.quality.sh').start()
        self.addCleanup(self._mock_paver_sh.stop())<commit_msg>Fix PEP8: E112 expected an indented block<commit_after>import os
import tempfile
import unittest
from mock import patch
from ddt import ddt, file_data

import pavelib.quality
import paver.easy
from paver.easy import BuildFailure


@ddt
class TestPaverQualityViolations(unittest.TestCase):

    def setUp(self):
        self.f = tempfile.NamedTemporaryFile(delete=False)
        self.f.close()

    def test_pylint_parser_other_string(self):
        with open(self.f.name, 'w') as f:
            f.write("hello")
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 0)

    def test_pylint_parser_pep8(self):
        # Pep8 violations should be ignored.
        with open(self.f.name, 'w') as f:
            f.write("foo/hello/test.py:304:15: E203 whitespace before ':'")
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 0)

    @file_data('pylint_test_list.json')
    def test_pylint_parser_count_violations(self, value):
        """
        Tests:
        - Different types of violations
        - One violation covering multiple lines
        """
        with open(self.f.name, 'w') as f:
            f.write(value)
        num = pavelib.quality._count_pylint_violations(f.name)
        self.assertEqual(num, 1)

    def test_pep8_parser(self):
        with open(self.f.name, 'w') as f:
            f.write("hello\nhithere")
        num = pavelib.quality._count_pep8_violations(f.name)
        self.assertEqual(num, 2)

    def tearDown(self):
        os.remove(self.f.name)


class TestPaverRunQuality(unittest.TestCase):
    """
    For testing the paver run_quality task
    """

    def setUp(self):

        # mock the @needs decorator to skip it
        self._mock_paver_needs = patch.object(pavelib.quality.run_quality, 'needs').start()
        self._mock_paver_needs.return_value = 0
        self._mock_paver_sh = patch('pavelib.quality.sh').start()
        self.addCleanup(self._mock_paver_sh.stop())
{'fraction_non_alphanumeric': 0.10710659898477157, 'fraction_numerical': 0.009644670050761422, 'mean_word_length': 2.856164383561644, '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': '2388959', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1296, 'n_words': 259}