def test_tagging(self): with bear_test_module(), prepare_file(["\t#include <a>"], None) as (lines, filename): log_printer = LogPrinter(NullPrinter()) execute_coala( coala_ci.main, "coala-ci", "default", "-c", self.coafile, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "-S", "tag=test_tag", ) tag_path = get_tag_path("test_tag", self.unescaped_coafile, log_printer) self.assertTrue(os.path.exists(tag_path)) execute_coala( coala_ci.main, "coala-ci", "default", "-c", self.coafile, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "-S", "dtag=test_tag", ) self.assertFalse(os.path.exists(tag_path))
def test_find_issues(self): with bear_test_module(), prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename) ) self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines") self.assertNotEqual(retval, 0, "coala-ci was expected to return non-zero")
def test_find_issues(self): with bear_test_module(), prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala( coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename) ) output = json.loads(output) self.assertEqual(output["results"]["default"][0]["message"], "This file has 1 lines.") self.assertNotEqual(retval, 0, "coala-json must return nonzero when " "results found")
def test_coala(self): with bear_test_module(), \ prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala(coala.main, "coala", "-c", os.devnull, "-f", re.escape(filename), "-b", "LineCountTestBear") self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines")
def test_fail_acquire_settings(self): with bear_test_module(): retval, output = execute_coala( coala_json.main, "coala-json", "-c", os.devnull, "-b", "SpaceConsistencyTestBear" ) output = json.loads(output) found = False for msg in output["logs"]: if "During execution, we found that some" in msg["message"]: found = True self.assertTrue(found, "Missing settings not logged")
def test_fail_acquire_settings(self): with bear_test_module(): retval, output = execute_coala(coala_json.main, 'coala-json', '-c', os.devnull, '-b', 'SpaceConsistencyTestBear') output = json.loads(output) found = False for msg in output["logs"]: if "During execution, we found that some" in msg["message"]: found = True self.assertTrue(found, "Missing settings not logged")
def test_find_no_issues(self): with bear_test_module(), \ prepare_file(["#include <a>"], None) as (lines, filename): retval, output = execute_coala(coala_ci.main, "coala-ci", '-c', os.devnull, '-f', re.escape(filename), '-b', 'SpaceConsistencyTestBear', "--settings", "use_spaces=True") self.assertIn("Executing section Default", output) self.assertEqual(retval, 0, "coala-ci must return zero when successful")
def test_coala(self): with bear_test_module(), \ prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala( coala.main, "coala", "-c", os.devnull, "-f", re.escape(filename), "-b", "LineCountTestBear") self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines")
def test_find_issues(self): with bear_test_module(), \ prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala(coala_ci.main, "coala-ci", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename)) self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines") self.assertNotEqual(retval, 0, "coala-ci was expected to return non-zero")
def test_show_bears(self): with bear_test_module(): retval, output = execute_coala(coala.main, "coala", "-A") self.assertEqual(retval, 0) bear_lines = [i.startswith(" * ") for i in output.split()] self.assertGreater(len(bear_lines), 0) retval, output = execute_coala(coala.main, "coala", "-B", "-b", "LineCountTestBear", "-c", os.devnull) self.assertEqual(retval, 0) self.assertIn(LineCountTestBear.run.__doc__.strip(), output)
def test_fix_patchable_issues(self): with bear_test_module(), \ prepare_file(["\t#include <a>"], None) as (lines, filename): retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "--settings", "autoapply=true", "use_spaces=True", "default_actions=SpaceConsistencyTestBear:ApplyPatchAction") self.assertIn("Applied 'ApplyPatchAction'", output) self.assertEqual( retval, 5, "coala-ci must return exitcode 5 when it " "autofixes the code.")
def test_line_count(self): with bear_test_module(), \ prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala(coala_format.main, "coala-format", "-c", os.devnull, "-f", re.escape(filename), "-b", "LineCountTestBear") self.assertRegex(output, r'msg:This file has [0-9]+ lines.', "coala-format output for line count should " "not be empty") self.assertEqual(retval, 1, "coala-format must return exitcode 1 when it " "yields results")
def test_find_issues(self): with bear_test_module(), \ prepare_file(["#fixme"], None) as (lines, filename): retval, output = execute_coala(coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename)) output = json.loads(output) self.assertEqual(output["results"]["default"][0]["message"], "This file has 1 lines.") self.assertNotEqual( retval, 0, "coala-json must return nonzero when " "results found")
def test_tagging(self): with bear_test_module(), \ prepare_file(["\t#include <a>"], None) as (lines, filename): log_printer = LogPrinter(NullPrinter()) execute_coala(coala_ci.main, "coala-ci", "default", "-c", self.coafile, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "-S", "tag=test_tag") tag_path = get_tag_path("test_tag", self.unescaped_coafile, log_printer) self.assertTrue(os.path.exists(tag_path)) execute_coala(coala_ci.main, "coala-ci", "default", "-c", self.coafile, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "-S", "dtag=test_tag") self.assertFalse(os.path.exists(tag_path))
def test_fix_patchable_issues(self): with bear_test_module(), \ prepare_file(["\t#include <a>"], None) as (lines, filename): retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "--settings", "autoapply=true", "use_spaces=True", "default_actions=SpaceConsistencyTestBear:ApplyPatchAction") self.assertIn("Applied 'ApplyPatchAction'", output) self.assertEqual(retval, 5, "coala-ci must return exitcode 5 when it " "autofixes the code.")
def test_find_no_issues(self): with bear_test_module(), prepare_file(["#include <a>"], None) as (lines, filename): retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "-f", re.escape(filename), "-b", "SpaceConsistencyTestBear", "--settings", "use_spaces=True", ) self.assertIn("Executing section Default", output) self.assertEqual(retval, 0, "coala-ci must return zero when successful")
def test_fill_settings(self): sections = {"test": self.section} with simulate_console_inputs() as generator: fill_settings(sections, acquire_settings, self.log_printer) self.assertEqual(generator.last_input, -1) self.section.append(Setting("bears", "SpaceConsistencyTestBear")) with simulate_console_inputs("True"), bear_test_module(): local_bears, global_bears = fill_settings(sections, acquire_settings, self.log_printer) self.assertEqual(len(local_bears["test"]), 1) self.assertEqual(len(global_bears["test"]), 0) self.assertEqual(bool(self.section["use_spaces"]), True) self.assertEqual(len(self.section.contents), 3)
def test_show_bears(self): retval, output = execute_coala(coala.main, "coala", "-A") self.assertEqual(retval, 0) lines = output.splitlines() bear_missing_lines = sum(1 for line in lines if "WARNING" in line) self.assertEqual(bear_missing_lines, 0) with bear_test_module(): retval, output = execute_coala(coala.main, "coala", "-A") self.assertEqual(retval, 0) lines = output.splitlines() bear_lines = sum(1 for line in lines if line.startswith(" * ")) self.assertEqual(bear_lines, 2) for line in lines: self.assertNotIn("WARNING", line) retval, output = execute_coala( coala.main, "coala", "-B", "-b", "LineCountTestBear, SpaceConsistencyTestBear", "-c", os.devnull) self.assertEqual(retval, 0) self.assertIn(LineCountTestBear.run.__doc__.strip(), output)
def test_fail_acquire_settings(self): with bear_test_module(): retval, output = execute_coala( coala_ci.main, "coala-ci", "-b", "SpaceConsistencyTestBear", "-c", os.devnull ) self.assertIn("During execution, we found that some", output)
def test_fail_acquire_settings(self): with bear_test_module(): retval, output = execute_coala(coala_ci.main, "coala-ci", "-b", 'SpaceConsistencyTestBear', '-c', os.devnull) self.assertIn("During execution, we found that some", output)