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

coalib.tests.coalaTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 44
Duplicated Lines 0 %
Metric Value
dl 0
loc 44
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 2 1
A test_did_nothing() 0 5 1
A setUp() 0 2 1
A test_coala() 0 11 2
B test_show_bears() 0 18 6
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
        with bear_test_module():
41
            retval, output = execute_coala(coala.main, "coala", "-A")
42
            self.assertEqual(retval, 0)
43
44
            lines = output.splitlines()
45
            bear_lines = sum(1 for line in lines if line.startswith(" * "))
46
            self.assertEqual(bear_lines, 2)
47
48
            bear_missing_lines = sum(1
49
                for i in output.split() if "No bears were found matching" in i)
50
            self.assertEqual(bear_missing_lines, 0)
51
52
            retval, output = execute_coala(coala.main, "coala", "-B",
53
                                           "-b", "LineCountTestBear",
54
                                           "-c", os.devnull)
55
            self.assertEqual(retval, 0)
56
            self.assertIn(LineCountTestBear.run.__doc__.strip(), output)
57