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