Failed Conditions
Pull Request — master (#2076)
by Abdeali
02:11
created

coalaCITest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 97
rs 10
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A test_tagging() 0 19 2
A tearDown() 0 2 1
A test_fix_patchable_issues() 0 13 2
A test_nonexistent() 0 6 1
A test_find_issues() 0 12 2
A test_find_no_issues() 0 11 2
A test_fail_acquire_settings() 0 6 2
A setUp() 0 4 1
A test_coala_delete_orig() 0 13 2
1
import os
2
import re
3
import sys
4
import unittest
5
from tempfile import NamedTemporaryFile, TemporaryDirectory
6
7
from pyprint.NullPrinter import NullPrinter
8
9
from coalib import coala_ci
10
from coalib.misc.ContextManagers import make_temp, prepare_file
11
from coalib.output.printers.LogPrinter import LogPrinter
12
from coalib.output.Tagging import get_tag_path
13
from tests.TestUtilities import bear_test_module, execute_coala
14
15
16
class coalaCITest(unittest.TestCase):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable unittest does not seem to be defined.
Loading history...
17
18
    def setUp(self):
19
        self.old_argv = sys.argv
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable sys does not seem to be defined.
Loading history...
20
        self.unescaped_coafile = os.path.abspath("./.coafile")
21
        self.coafile = re.escape(self.unescaped_coafile)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
22
23
    def tearDown(self):
24
        sys.argv = self.old_argv
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
25
26
    def test_nonexistent(self):
27
        retval, output = execute_coala(
28
            coala_ci.main, "coala-ci", "-c", 'nonex', "test")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
29
        self.assertRegex(
30
            output,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output does not seem to be defined.
Loading history...
31
            ".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n")
32
33
    def test_find_no_issues(self):
34
        with bear_test_module(), \
35
                prepare_file(["#include <a>"], None) as (lines, filename):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable lines does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable filename does not seem to be defined.
Loading history...
36
            retval, output = execute_coala(coala_ci.main, "coala-ci",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
37
                                           '-c', os.devnull,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable os does not seem to be defined.
Loading history...
38
                                           '-f', re.escape(filename),
39
                                           '-b', 'SpaceConsistencyTestBear',
40
                                           "--settings", "use_spaces=True")
41
            self.assertIn("Executing section Default", output)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output does not seem to be defined.
Loading history...
42
            self.assertEqual(retval, 0,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable retval does not seem to be defined.
Loading history...
43
                             "coala-ci must return zero when successful")
44
45
    def test_find_issues(self):
46
        with bear_test_module(), \
47
                prepare_file(["#fixme"], None) as (lines, filename):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable lines does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable filename does not seem to be defined.
Loading history...
48
            retval, output = execute_coala(coala_ci.main, "coala-ci",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
49
                                           "-c", os.devnull,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable os does not seem to be defined.
Loading history...
50
                                           "-b", "LineCountTestBear",
51
                                           "-f", re.escape(filename))
52
            self.assertIn("This file has 1 lines.",
53
                          output,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output does not seem to be defined.
Loading history...
54
                          "The output should report count as 1 lines")
55
            self.assertNotEqual(retval, 0,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable retval does not seem to be defined.
Loading history...
56
                                "coala-ci was expected to return non-zero")
57
58
    def test_fix_patchable_issues(self):
59
        with bear_test_module(), \
60
                prepare_file(["\t#include <a>"], None) as (lines, filename):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable lines does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable filename does not seem to be defined.
Loading history...
61
            retval, output = execute_coala(
62
                coala_ci.main, "coala-ci",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
63
                "-c", os.devnull,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable os does not seem to be defined.
Loading history...
64
                "-f", re.escape(filename),
65
                "-b", "SpaceConsistencyTestBear",
66
                "--settings", "autoapply=true", "use_spaces=True",
67
                "default_actions=SpaceConsistencyTestBear:ApplyPatchAction")
68
            self.assertIn("Applied 'ApplyPatchAction'", output)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output does not seem to be defined.
Loading history...
69
            self.assertEqual(retval, 5,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable retval does not seem to be defined.
Loading history...
70
                             "coala-ci must return exitcode 5 when it "
71
                             "autofixes the code.")
72
73
    def test_tagging(self):
74
        with bear_test_module(), \
75
                prepare_file(["\t#include <a>"], None) as (lines, filename):
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable lines does not seem to be defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable filename does not seem to be defined.
Loading history...
76
            log_printer = LogPrinter(NullPrinter())
77
            execute_coala(coala_ci.main, "coala-ci", "default",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
78
                          "-c", self.coafile,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable self does not seem to be defined.
Loading history...
79
                          "-f", re.escape(filename),
80
                          "-b", "SpaceConsistencyTestBear",
81
                          "-S", "tag=test_tag")
82
            tag_path = get_tag_path("test_tag",
83
                                    self.unescaped_coafile,
84
                                    log_printer)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable log_printer does not seem to be defined.
Loading history...
85
            self.assertTrue(os.path.exists(tag_path))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable tag_path does not seem to be defined.
Loading history...
86
            execute_coala(coala_ci.main, "coala-ci", "default",
87
                          "-c", self.coafile,
88
                          "-f", re.escape(filename),
89
                          "-b", "SpaceConsistencyTestBear",
90
                          "-S", "dtag=test_tag")
91
            self.assertFalse(os.path.exists(tag_path))
92
93
    def test_fail_acquire_settings(self):
94
        with bear_test_module():
95
            retval, output = execute_coala(coala_ci.main, "coala-ci",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
96
                                           "-b", 'SpaceConsistencyTestBear',
97
                                           '-c', os.devnull)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable os does not seem to be defined.
Loading history...
98
            self.assertIn("During execution, we found that some", output)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable output does not seem to be defined.
Loading history...
99
100
    def test_coala_delete_orig(self):
101
        with TemporaryDirectory() as tempdir,\
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable tempdir does not seem to be defined.
Loading history...
102
             NamedTemporaryFile(suffix='.orig',
103
                                dir=tempdir,
104
                                delete=False) as orig_file,\
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable orig_file does not seem to be defined.
Loading history...
105
             make_temp(suffix='.coafile', prefix='', dir=tempdir) as coafile,\
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coafile does not seem to be defined.
Loading history...
106
             make_temp(dir=tempdir) as unrelated_file:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable unrelated_file does not seem to be defined.
Loading history...
107
            orig_file.close()
108
109
            execute_coala(coala_ci.main, "coala-ci", "-S",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable coala_ci does not seem to be defined.
Loading history...
110
                          "project_dir=" + os.path.dirname(coafile))
111
            self.assertFalse(os.path.isfile(orig_file.name))
112
            self.assertTrue(os.path.isfile(unrelated_file))
113