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_output_file(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): retval, output = execute_coala( coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename) ) exp_retval, exp_output = execute_coala( coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename), "-o", "file.json", ) with open("file.json") as fp: data = json.load(fp) output = json.loads(output) self.assertEqual(data["logs"][0]["log_level"], output["logs"][0]["log_level"]) os.remove("file.json")
def test_tagging(self): execute_coala(coala_ci.main, "coala-ci", 'docs', "-S", "tag=test_tag", "-c", self.coafile) tag_path = get_tag_path("test_tag", self.unescaped_coafile) self.assertTrue(os.path.exists(tag_path)) execute_coala(coala_ci.main, "coala-ci", 'docs', "-S", "dtag=test_tag", "-c", self.coafile) self.assertFalse(os.path.exists(tag_path))
def test_coala_delete_orig(self): with TemporaryDirectory() as tempdir, NamedTemporaryFile( suffix=".orig", dir=tempdir, delete=False ) as orig_file, make_temp(suffix=".coafile", prefix="", dir=tempdir) as coafile, make_temp( dir=tempdir ) as unrelated_file: orig_file.close() execute_coala(coala_ci.main, "coala-ci", "-c", re.escape(coafile)) self.assertFalse(os.path.isfile(orig_file.name)) self.assertTrue(os.path.isfile(unrelated_file))
def test_show_bears(self): 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", "LineCountBear", "-c", os.devnull) self.assertEqual(retval, 0) self.assertIn(LineCountBear.run.__doc__.strip(), output)
def test_coala_delete_orig(self): with TemporaryDirectory() as tempdir,\ NamedTemporaryFile(suffix='.orig', dir=tempdir, delete=False) as orig_file,\ make_temp(suffix='.coafile', prefix='', dir=tempdir) as coafile,\ make_temp(dir=tempdir) as unrelated_file: orig_file.close() execute_coala(coala_ci.main, "coala-ci", "-c", re.escape(coafile)) self.assertFalse(os.path.isfile(orig_file.name)) self.assertTrue(os.path.isfile(unrelated_file))
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_nonexistent(self): retval, output = execute_coala( coala_json.main, "coala-json", "-c", 'nonex', "test") output = json.loads(output) self.assertRegex( output["logs"][0]["message"], "The requested coafile '.*' does not exist.")
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_fail_acquire_settings(self): retval, output = execute_coala(coala_ci.main, "coala-ci", "-b", 'SpaceConsistencyBear', '-c', os.devnull) self.assertIn("During execution, we found that some", output)
def test_coala(self): with prepare_file(["#fixme"], None) as (lines, filename): bear = "LineCountBear" retval, output = execute_coala(coala.main, "coala", "-c", os.devnull, "--settings", "files=" + re.escape(filename), "bears=" + bear) self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines")
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): retval, output = execute_coala(coala_json.main, 'coala-json', '-b', 'SpaceConsistencyBear', '-c', os.devnull) 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)
def test_fail_acquire_settings(self): retval, output = execute_coala( coala_json.main, 'coala-json', '-b', 'SpaceConsistencyBear', '-c', os.devnull) 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)
def test_find_no_issues(self): retval, output = execute_coala(coala_ci.main, "coala-ci", 'docs', '-c', self.coafile) self.assertRegex( output, "(.*Unable to collect bears from.*PyLintBear.*)?", "coala-ci output should be empty when running " "over its own code.") self.assertEqual( retval, 0, "coala-ci must return zero when running over its " "own code.")
def test_fix_patchable_issues(self): with prepare_file([" #include <a>"], None) as (lines, filename): bear = "IndentBear" retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "--settings", "files=" + filename, "bears=" + bear, "autoapply=true", "default_actions=" + bear + ":ApplyPatchAction") self.assertEqual( retval, 5, "coala-ci must return exitcode 5 when it " "autofixes the code.")
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_issues(self): retval, output = execute_coala( coala_ci.main, "coala-ci", "todos", "-c", self.coafile) self.assertRegex(output, r'The line contains the keyword `# \w+`.', "coala-ci output should be empty when running " "over its own code. (Target section: todos)") self.assertNotEqual(retval, 0, "coala-ci must return nonzero when running over " "its own code. (Target section: todos)")
def test_find_no_issues(self): retval, output = execute_coala( coala_ci.main, "coala-ci", 'docs', '-c', self.coafile) self.assertRegex(output, "(.*Unable to collect bears from.*PyLintBear.*)?", "coala-ci output should be empty when running " "over its own code.") self.assertEqual(retval, 0, "coala-ci must return zero when running over its " "own 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_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_fix_patchable_issues(self): with prepare_file([" #include <a>"], None) as (lines, filename): bear = "IndentBear" retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", os.devnull, "--settings", "files=" + filename, "bears=" + bear, "autoapply=true", "default_actions=" + bear + ":ApplyPatchAction") self.assertEqual(retval, 5, "coala-ci must return exitcode 5 when it " "autofixes the code.")
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_coala(self): with prepare_file(["#fixme"], None) as (lines, filename): bear = "LineCountBear" retval, output = execute_coala( coala.main, "coala", "-c", os.devnull, "--settings", "files=" + re.escape(filename), "bears=" + bear) self.assertIn("This file has 1 lines.", output, "The output should report count as 1 lines")
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_output_file(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): retval, output = execute_coala(coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename)) exp_retval, exp_output = execute_coala(coala_json.main, "coala-json", "-c", os.devnull, "-b", "LineCountTestBear", "-f", re.escape(filename), "-o", "file.json") with open('file.json') as fp: data = json.load(fp) output = json.loads(output) self.assertEqual(data['logs'][0]['log_level'], output['logs'][0]['log_level']) os.remove('file.json')
def test_find_issues(self): retval, output = execute_coala(coala_json.main, "coala-json", "todos", "-c", self.coafile) output = json.loads(output) self.assertRegex( output["results"]["todos"][0]["message"], r'The line contains the keyword `# \w+`.', "coala-json output should be empty when running " "over its own code. (Target section: todos)") self.assertNotEqual( retval, 0, "coala-json must return nonzero when running over " "its own code. (Target section: todos)")
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_find_issues(self): retval, output = execute_coala( coala_json.main, "coala-json", "todos", "-c", self.coafile) output = json.loads(output) self.assertRegex(output["results"]["todos"][0]["message"], r'The line contains the keyword `# \w+`.', "coala-json output should be empty when running " "over its own code. (Target section: todos)") self.assertNotEqual(retval, 0, "coala-json must return nonzero when running over " "its own code. (Target section: todos)")
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_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_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_find_issues(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): bear = "KeywordBear" retval, output = execute_coala(coala_ci.main, "coala-ci", "-c", os.devnull, "-S", "ci_keywords=#TODO", "cs_keywords=#todo", "bears=" + bear, "-f", re.escape(filename)) self.assertIn("The line contains the keyword `#todo`.", output, "coala-ci output should match the keyword\ #todo") self.assertNotEqual(retval, 0, "coala-ci must return nonzero when " "matching `#todo` keyword")
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_find_issues(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): bear = "KeywordBear" retval, output = execute_coala(coala_json.main, "coala-json", "-c", os.devnull, "-S", "ci_keywords=#TODO", "cs_keywords=#todo", "bears=" + bear, "-f", re.escape(filename)) output = json.loads(output) self.assertEqual(output["results"]["default"][0]["message"], "The line contains the keyword `#todo`.", "coala-json output should match the keyword #todo") self.assertNotEqual(retval, 0, "coala-json must return nonzero when " "matching `#todo` keyword")
def test_find_issues(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): bear = "KeywordBear" retval, output = execute_coala(coala_ci.main, "coala-ci", "-c", os.devnull, "-S", "ci_keywords=#TODO", "cs_keywords=#todo", "bears=" + bear, "-f", re.escape(filename)) self.assertIn( "The line contains the keyword `#todo`.", output, "coala-ci output should match the keyword\ #todo") self.assertNotEqual( retval, 0, "coala-ci must return nonzero when " "matching `#todo` keyword")
def test_find_issues(self): with prepare_file(["#todo this is todo"], None) as (lines, filename): bear = "KeywordBear" retval, output = execute_coala(coala_json.main, "coala-json", "-c", os.devnull, "-S", "ci_keywords=#TODO", "cs_keywords=#todo", "bears=" + bear, "-f", re.escape(filename)) output = json.loads(output) self.assertEqual( output["results"]["default"][0]["message"], "The line contains the keyword `#todo`.", "coala-json output should match the keyword #todo") self.assertNotEqual( retval, 0, "coala-json must return nonzero when " "matching `#todo` keyword")
def test_version(self): retval, output = execute_coala(coala_json.main, 'coala-json', '-v') self.assertEquals(retval, 0) self.assertNotIn("{", output)
def test_did_nothing(self): retval, output = execute_coala(coala.main, "coala", "-c", os.devnull, "-S", "default.enabled=false") self.assertEqual(retval, 0) self.assertIn("No existent section was targeted or enabled", output)
def test_nonexistent(self): retval, output = execute_coala( coala_ci.main, "coala-ci", "-c", 'nonex', "test") self.assertRegex( output, ".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n")
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_nonexistent(self): retval, output = execute_coala(coala_json.main, "coala-json", "-c", 'nonex', "test") output = json.loads(output) self.assertRegex(output["logs"][0]["message"], "The requested coafile '.*' does not exist.")
def test_nonexistent(self): retval, output = execute_coala(coala_ci.main, "coala-ci", "-c", 'nonex', "test") self.assertRegex( output, ".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n")
def test_version(self): with self.assertRaises(SystemExit): execute_coala(coala_json.main, "coala-json", "-v")
def test_text_logs(self): retval, output = execute_coala(coala_json.main, 'coala-json', '--text-logs', '-c', 'nonex') self.assertRegex( output, ".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n")
def test_version(self): with self.assertRaises(SystemExit): execute_coala(coala_json.main, 'coala-json', '-v')
def test_text_logs(self): retval, output = execute_coala( coala_json.main, 'coala-json', '--text-logs', '-c', 'nonex') self.assertRegex( output, ".*\\[ERROR\\].*The requested coafile '.*' does not exist.\n")