Completed
Pull Request — master (#1487)
by Lasse
01:38
created

bears.tests.python.PyLintBearTest.test_rcfile()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
import os
2
import re
3
from queue import Queue
4
from shutil import which
5
from unittest.case import skipIf
6
7
from coalib.settings.Setting import Setting
8
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
9
from bears.python.PyLintBear import PyLintBear
10
from coalib.settings.Section import Section
11
12
13
@skipIf(which('pylint') is None, 'PyLint is not installed')
14
class PyLintBearTest(LocalBearTestHelper):
15
16
    def setUp(self):
17
        self.section = Section("test section")
18
        self.uut = PyLintBear(self.section, Queue())
19
        self.test_file = os.path.join(os.path.dirname(__file__),
20
                                      "test_files",
21
                                      "pylint_test.py")
22
        self.rc_file = os.path.join(os.path.dirname(__file__),
23
                                    "test_files",
24
                                    "pylint_config")
25
26
    def test_run(self):
27
        self.section.append(Setting("pylint_disable", ""))
28
        self.check_validity(
29
            self.uut,
30
            [],  # Doesn't matter, pylint will parse the file
31
            self.test_file,
32
            valid=False)
33
34
        # This is a special case because there's only one result yielded.
35
        # This was a bug once where the last result got ignored.
36
        self.section.append(Setting("pylint_disable", "E0211,W0611,C0111"))
37
        self.check_validity(self.uut, [], self.test_file, valid=False)
38
39
        self.section.append(
40
            Setting("pylint_disable", "E0211,W0611,C0111,W0311"))
41
        self.check_validity(self.uut, [], self.test_file)
42
43
        self.section.append(Setting("pylint_disable", "all"))
44
        self.check_validity(self.uut, [], self.test_file)
45
46
        self.section.append(Setting("pylint_enable", "C0111"))
47
        self.check_validity(self.uut, [], self.test_file, valid=False)
48
49
        self.section.append(Setting("pylint_cli_options", "--disable=all"))
50
        self.check_validity(self.uut, [], self.test_file)
51
52
    def test_rcfile(self):
53
        self.section.append(Setting("pylint_rcfile", re.escape(self.rc_file)))
54
        self.check_validity(self.uut, [], self.test_file)
55