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
![]() |
|||
17 | |||
18 | def setUp(self): |
||
19 | self.old_argv = sys.argv |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
22 | |||
23 | def tearDown(self): |
||
24 | sys.argv = self.old_argv |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
29 | self.assertRegex( |
||
30 | output, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
Comprehensibility
Best Practice
introduced
by
|
|||
36 | retval, output = execute_coala(coala_ci.main, "coala-ci", |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
37 | '-c', os.devnull, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
42 | self.assertEqual(retval, 0, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
Comprehensibility
Best Practice
introduced
by
|
|||
48 | retval, output = execute_coala(coala_ci.main, "coala-ci", |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
49 | "-c", os.devnull, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
54 | "The output should report count as 1 lines") |
||
55 | self.assertNotEqual(retval, 0, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
Comprehensibility
Best Practice
introduced
by
|
|||
61 | retval, output = execute_coala( |
||
62 | coala_ci.main, "coala-ci", |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
63 | "-c", os.devnull, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
69 | self.assertEqual(retval, 5, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
Comprehensibility
Best Practice
introduced
by
|
|||
76 | log_printer = LogPrinter(NullPrinter()) |
||
77 | execute_coala(coala_ci.main, "coala-ci", "default", |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
78 | "-c", self.coafile, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
85 | self.assertTrue(os.path.exists(tag_path)) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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
|
|||
96 | "-b", 'SpaceConsistencyTestBear', |
||
97 | '-c', os.devnull) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
98 | self.assertIn("During execution, we found that some", output) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
99 | |||
100 | def test_coala_delete_orig(self): |
||
101 | with TemporaryDirectory() as tempdir,\ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
102 | NamedTemporaryFile(suffix='.orig', |
||
103 | dir=tempdir, |
||
104 | delete=False) as orig_file,\ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
105 | make_temp(suffix='.coafile', prefix='', dir=tempdir) as coafile,\ |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
106 | make_temp(dir=tempdir) as unrelated_file: |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
107 | orig_file.close() |
||
108 | |||
109 | execute_coala(coala_ci.main, "coala-ci", "-S", |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
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 |