def test_adds_misuse(self): finding = Finding({}) finding.is_potential_hit = lambda misuse, y: misuse == self.misuse potential_hits = self.uut.get_potential_hits([finding]) assert_equals(self.misuse.id, potential_hits[0]["misuse"])
def test_loads_snippet(self, utils_mock): utils_mock.side_effect =\ lambda tool, args: "42:T:-code-" if tool == "MethodExtractor" and args == '"-file-" "-method-"' else "" finding = Finding({"file": "-file-", "method": "-method-"}) assert_equals([Snippet("class T {\n-code-\n}", 41)], finding.get_snippets())
def test_extraction_error(self, utils_mock): utils_mock.side_effect = CommandFailedError("cmd", "output") finding = Finding({"file": "-file-"}) assert_equals([Snippet("Failed to execute 'cmd': output", 1)], finding.get_snippets())
def test_strips_additional_output(self, utils_mock): utils_mock.return_value = "Arbitrary additional output\n1:C:code" finding = Finding({"file": "-file-"}) assert_equals(1, len(finding.get_snippets()))
def test_loads_multiple_snippets(self, utils_mock): utils_mock.return_value = "42:T:t-code\n===\n32:A:a-code" finding = Finding({"file": "-file-"}) assert_equals(2, len(finding.get_snippets()))
def test_no_code(self, utils_mock): utils_mock.return_value = "" finding = Finding({"file": "-file-"}) assert_equals(finding.get_snippets(), [])