Completed
Pull Request — master (#1665)
by Abdeali
02:02
created

coalib.tests.coalaTest.setUp()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
1
import os
2
import re
3
import sys
4
import unittest
5
6
from coalib import coala
7
from coalib.misc.ContextManagers import prepare_file
8
from coalib.tests.test_bears.LineCountTestBear import (
9
    LineCountTestBear)
10
from coalib.tests.TestUtilities import execute_coala, bear_test_module
11
12
13
class coalaTest(unittest.TestCase):
14
15
    def setUp(self):
16
        self.old_argv = sys.argv
17
18
    def tearDown(self):
19
        sys.argv = self.old_argv
20
21
    def test_coala(self):
22
        with bear_test_module(), \
23
                prepare_file(["#fixme"], None) as (lines, filename):
24
            retval, output = execute_coala(
25
                             coala.main,
26
                            "coala", "-c", os.devnull,
27
                            "-f", re.escape(filename),
28
                            "-b", "LineCountTestBear")
29
            self.assertIn("This file has 1 lines.",
30
                          output,
31
                          "The output should report count as 1 lines")
32
33
    def test_did_nothing(self):
34
        retval, output = execute_coala(coala.main, "coala", "-c", os.devnull,
35
                                       "-S", "default.enabled=false")
36
        self.assertEqual(retval, 0)
37
        self.assertIn("No existent section was targeted or enabled", output)
38
39
    def test_show_bears(self):
40
        retval, output = execute_coala(coala.main, "coala", "-A")
41
        self.assertEqual(retval, 0)
42
        lines = output.splitlines()
43
        bear_missing_lines = sum(1 for line in lines if "WARNING" in line)
44
        self.assertEqual(bear_missing_lines, 0)
45
46
        with bear_test_module():
47
            retval, output = execute_coala(coala.main, "coala", "-A")
48
            self.assertEqual(retval, 0)
49
50
            lines = output.splitlines()
51
            bear_lines = sum(1 for line in lines if line.startswith(" * "))
52
            self.assertEqual(bear_lines, 2)
53
54
            for line in lines:
55
                self.assertNotIn("WARNING", line)
56
57
            retval, output = execute_coala(
58
                coala.main, "coala", "-B",
59
                "-b", "LineCountTestBear, SpaceConsistencyTestBear",
60
                "-c", os.devnull)
61
            self.assertEqual(retval, 0)
62
            self.assertIn(LineCountTestBear.run.__doc__.strip(), output)
63