Completed
Pull Request — master (#1504)
by Abdeali
01:48
created

coalib.tests.coalaFormatTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %
Metric Value
dl 0
loc 23
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 2 1
A setUp() 0 2 1
A test_line_count() 0 15 2
1
import os
2
import re
3
import sys
4
import unittest
5
6
from coalib import coala_format
7
from coalib.tests.TestUtilities import execute_coala
8
from coalib.misc.ContextManagers import prepare_file
9
10
11
class coalaFormatTest(unittest.TestCase):
12
13
    def setUp(self):
14
        self.old_argv = sys.argv
15
16
    def tearDown(self):
17
        sys.argv = self.old_argv
18
19
    def test_line_count(self):
20
        with prepare_file(["#fixme"], None) as (lines, filename):
21
            bear = "LineCountBear"
22
            retval, output = execute_coala(
23
                             coala_format.main,
24
                            "coala-format", "-c", os.devnull,
25
                            "--settings", "files=" + re.escape(filename),
26
                            "bears=" + bear)
27
            self.assertRegex(output,
28
                             r'msg:This file has [0-9]+ lines.',
29
                             "coala-format output for line count should"
30
                             " not be empty")
31
            self.assertEqual(retval,
32
                             1,
33
                             "coala-format must return exitcode 1 when it "
34
                             "yields results")
35