Completed
Pull Request — master (#2320)
by Lasse
01:53
created

coalaCITest.test_coala_delete_orig()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
1
import os
2
import re
3
import sys
4
import unittest
5
6
from coalib import coala_ci
7
from coalib.misc.ContextManagers import prepare_file
8
from tests.TestUtilities import bear_test_module, execute_coala
9
10
11
class coalaCITest(unittest.TestCase):
12
13
    def setUp(self):
14
        self.old_argv = sys.argv
15
        self.unescaped_coafile = os.path.abspath("./.coafile")
16
        self.coafile = re.escape(self.unescaped_coafile)
17
18
    def tearDown(self):
19
        sys.argv = self.old_argv
20
21
    def test_nonexistent(self):
22
        retval, output = execute_coala(
23
            coala_ci.main, "coala-ci", "-c", 'nonex', "test")
24
        self.assertRegex(
25
            output,
26
            ".*\\[ERROR\\].*The requested coafile '.*' does not exist. .+\n")
27
28
    def test_find_no_issues(self):
29
        with bear_test_module(), \
30
                prepare_file(["#include <a>"], None) as (lines, filename):
31
            retval, output = execute_coala(coala_ci.main, "coala-ci",
32
                                           '-c', os.devnull,
33
                                           '-f', re.escape(filename),
34
                                           '-b', 'SpaceConsistencyTestBear',
35
                                           "--settings", "use_spaces=True")
36
            self.assertIn("Executing section Default", output)
37
            self.assertEqual(retval, 0,
38
                             "coala-ci must return zero when successful")
39
40
    def test_find_issues(self):
41
        with bear_test_module(), \
42
                prepare_file(["#fixme"], None) as (lines, filename):
43
            retval, output = execute_coala(coala_ci.main, "coala-ci",
44
                                           "-c", os.devnull,
45
                                           "-b", "LineCountTestBear",
46
                                           "-f", re.escape(filename))
47
            self.assertIn("This file has 1 lines.",
48
                          output,
49
                          "The output should report count as 1 lines")
50
            self.assertNotEqual(retval, 0,
51
                                "coala-ci was expected to return non-zero")
52
53
    def test_fix_patchable_issues(self):
54
        with bear_test_module(), \
55
                prepare_file(["\t#include <a>"], None) as (lines, filename):
56
            retval, output = execute_coala(
57
                coala_ci.main, "coala-ci",
58
                "-c", os.devnull,
59
                "-f", re.escape(filename),
60
                "-b", "SpaceConsistencyTestBear",
61
                "--settings", "autoapply=true", "use_spaces=True",
62
                "default_actions=SpaceConsistencyTestBear:ApplyPatchAction")
63
            self.assertIn("Applied 'ApplyPatchAction'", output)
64
            self.assertEqual(retval, 5,
65
                             "coala-ci must return exitcode 5 when it "
66
                             "autofixes the code.")
67
68
    def test_fail_acquire_settings(self):
69
        with bear_test_module():
70
            retval, output = execute_coala(coala_ci.main, "coala-ci",
71
                                           "-b", 'SpaceConsistencyTestBear',
72
                                           '-c', os.devnull)
73
            self.assertIn("During execution, we found that some", output)
74