Failed Conditions
Pull Request — master (#1109)
by Abdeali
01:46
created

bears.tests.linters.JSHintBearTest.test_run()   A

Complexity

Conditions 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 19
rs 9.4286
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.linters.JSHintBear import JSHintBear
11
from coalib.settings.Section import Section
12
13
14
class JSHintBearTest(LocalBearTestHelper):
15
    def setUp(self):
16
        self.section = Section("test section")
17
        self.uut = JSHintBear(self.section, Queue())
18
        self.test_file1 = os.path.join(os.path.dirname(__file__),
19
                                       "test_files",
20
                                       "jshint_test1.js")
21
        self.test_file2 = os.path.join(os.path.dirname(__file__),
22
                                       "test_files",
23
                                       "jshint_test2.js")
24
        self.conf_file = os.path.join(os.path.dirname(__file__),
25
                                      "test_files",
26
                                      "jshint_config.js")
27
28
    def test_run(self):
29
        # Test a file with errors and warnings
30
        self.assertLinesInvalid(
31
            self.uut,
32
            [],
33
            self.test_file2)
34
35
        # Test a file with a warning which can be changed using a config
36
        self.assertLinesInvalid(
37
            self.uut,
38
            [],
39
            self.test_file1)
40
41
        # Test if warning disappears
42
        self.section.append(Setting("jshint_config", self.conf_file))
43
        self.assertLinesValid(
44
            self.uut,
45
            [],
46
            self.test_file1)
47
48
49
def skip_test():
50
    try:
51
        subprocess.Popen(['jshint', '--version'],
52
                         stdout=subprocess.PIPE,
53
                         stderr=subprocess.PIPE)
54
        return False
55
    except OSError:
56
        return "JSHint is not installed."
57
58
59
if __name__ == '__main__':
60
    unittest.main(verbosity=2)
61