Failed Conditions
Pull Request — master (#1093)
by Lasse
01:45
created

bears.tests.python.PyLintBearTest.test_run()   B

Complexity

Conditions 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 39
rs 8.8571
1
import os
2
import subprocess
3
import sys
4
from queue import Queue
5
6
sys.path.insert(0, ".")
7
import unittest
8
from coalib.settings.Setting import Setting
9
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
10
from bears.python.PyLintBear import PyLintBear
11
from coalib.settings.Section import Section
12
13
14
class PyLintBearTest(LocalBearTestHelper):
15
    def setUp(self):
16
        self.section = Section("test section")
17
        self.uut = PyLintBear(self.section, Queue())
18
        self.test_file = os.path.join(os.path.dirname(__file__),
19
                                      "test_files",
20
                                      "pylint_test.py")
21
22
    def test_run(self):
23
        self.section.append(Setting("pylint_disable", ""))
24
        self.assertLinesInvalid(
25
            self.uut,
26
            [],  # Doesn't matter, pylint will parse the file
27
            self.test_file)
28
29
        # This is a special case because there's only one result yielded.
30
        # This was a bug once where the last result got ignored.
31
        self.section.append(Setting("pylint_disable", "E0211,W0611,C0111"))
32
        self.assertLinesInvalid(
33
            self.uut,
34
            [],
35
            self.test_file)
36
37
        self.section.append(
38
            Setting("pylint_disable", "E0211,W0611,C0111,W0311"))
39
        self.assertLinesValid(
40
            self.uut,
41
            [],
42
            self.test_file)
43
44
        self.section.append(Setting("pylint_disable", "all"))
45
        self.assertLinesValid(
46
            self.uut,
47
            [],
48
            self.test_file)
49
50
        self.section.append(Setting("pylint_enable", "C0111"))
51
        self.assertLinesInvalid(
52
            self.uut,
53
            [],
54
            self.test_file)
55
56
        self.section.append(Setting("pylint_cli_options", "--disable=all"))
57
        self.assertLinesValid(
58
            self.uut,
59
            [],
60
            self.test_file)
61
62
63
def skip_test():
64
    try:
65
        subprocess.Popen(['pylint', '--version'],
66
                         stdout=subprocess.PIPE,
67
                         stderr=subprocess.PIPE)
68
        return False
69
    except OSError:
70
        return "PyLint is not installed."
71
72
73
if __name__ == '__main__':
74
    unittest.main(verbosity=2)
75