def test_quality(self):

        # Patch the output of `pyflakes`
        _mock_communicate = patch.object(Popen, 'communicate').start()
        return_string = '\n' + dedent("""
                ../new_file.py:328: undefined name '_thing'
                ../new_file.py:418: 'random' imported but unused
            """).strip() + '\n'
        _mock_communicate.return_value = (
            (return_string.encode('utf-8'), b''))

        # Parse the report
        quality = PyflakesQualityReporter('pyflakes', [])

        # Expect that the name is set
        self.assertEqual(quality.name(), 'pyflakes')

        # Measured_lines is undefined for
        # a quality reporter since all lines are measured
        self.assertEqual(quality.measured_lines('../new_file.py'), None)

        # Expect that we get the right violations
        expected_violations = [
            Violation(328, "undefined name '_thing'"),
            Violation(418, "'random' imported but unused")
        ]

        self.assertEqual(
            expected_violations,
            quality.violations('../new_file.py'))
示例#2
0
    def test_quality(self):

        # Patch the output of `pyflakes`
        _mock_communicate = patch.object(Popen, 'communicate').start()
        return_string = '\n' + dedent("""
                ../new_file.py:328: undefined name '_thing'
                ../new_file.py:418: 'random' imported but unused
            """).strip() + '\n'
        _mock_communicate.return_value = ((return_string.encode('utf-8'), b''))

        # Parse the report
        quality = PyflakesQualityReporter('pyflakes', [])

        # Expect that the name is set
        self.assertEqual(quality.name(), 'pyflakes')

        # Measured_lines is undefined for
        # a quality reporter since all lines are measured
        self.assertEqual(quality.measured_lines('../new_file.py'), None)

        # Expect that we get the right violations
        expected_violations = [
            Violation(328, "undefined name '_thing'"),
            Violation(418, "'random' imported but unused")
        ]

        self.assertEqual(expected_violations,
                         quality.violations('../new_file.py'))
    def test_quality_error(self):

        # Patch the output of `pyflakes`
        _mock_communicate = patch.object(Popen, 'communicate').start()
        _mock_communicate.return_value = (b"", b'whoops')

        # Parse the report
        quality = PyflakesQualityReporter('pyflakes', [])

        # Expect that the name is set
        self.assertEqual(quality.name(), 'pyflakes')

        self.assertRaises(QualityReporterError, quality.violations, 'file1.py')
示例#4
0
    def test_quality_error(self):

        # Patch the output of `pyflakes`
        _mock_communicate = patch.object(Popen, 'communicate').start()
        _mock_communicate.return_value = (b"", b'whoops')

        # Parse the report
        quality = PyflakesQualityReporter('pyflakes', [])

        # Expect that the name is set
        self.assertEqual(quality.name(), 'pyflakes')

        self.assertRaises(QualityReporterError, quality.violations, 'file1.py')