Skip to content

Commit 2206481

Browse files
haoranpbCopilot
andcommitted
Add NoTestsExtractedError handling and unit test for screen_gh_candidate
Co-authored-by: Copilot <copilot@github.com>
1 parent 0c43f73 commit 2206481

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

src/bcbench/collection/collect_gh.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bcbench.collection.patch_utils import extract_file_paths_from_patch, find_project_paths_from_diff, separate_patches
1111
from bcbench.config import get_config
1212
from bcbench.dataset import BugFixEntry
13-
from bcbench.exceptions import CollectionError
13+
from bcbench.exceptions import CollectionError, NoTestsExtractedError
1414
from bcbench.logger import get_logger
1515
from bcbench.operations import extract_tests_from_patch
1616

@@ -83,7 +83,9 @@ def fail(reason: str) -> ScreeningResult:
8383
file_contents[file_path] = gh_client.get_file_content(file_path, commit_id)
8484
except Exception:
8585
logger.debug("Could not fetch file content for %s", file_path)
86-
if not extract_tests_from_patch(patch_test, file_contents):
86+
try:
87+
extract_tests_from_patch(patch_test, file_contents)
88+
except NoTestsExtractedError:
8789
return fail("No testable functions found in test patch")
8890

8991
return ScreeningResult(pr_number=pr_number, repo=repo, passed=True)

tests/test_collect_gh.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77

8+
from bcbench.collection.collect_gh import screen_gh_candidate
89
from bcbench.collection.gh_client import GHClient
910
from bcbench.collection.patch_utils import extract_file_paths_from_patch, find_project_paths_from_diff, separate_patches
1011
from bcbench.exceptions import CollectionError
@@ -210,6 +211,38 @@ def test_get_file_content_success(self):
210211
assert "codeunit 12345" in result
211212

212213

214+
class TestScreenGHCandidate:
215+
def test_returns_failed_result_when_test_patch_has_no_testable_functions(self):
216+
diff = """diff --git a/App/Apps/W1/Foo/app/Foo.Codeunit.al b/App/Apps/W1/Foo/app/Foo.Codeunit.al
217+
--- a/App/Apps/W1/Foo/app/Foo.Codeunit.al
218+
+++ b/App/Apps/W1/Foo/app/Foo.Codeunit.al
219+
@@ -1,3 +1,4 @@
220+
+// Fix code
221+
procedure Main()
222+
begin
223+
end;
224+
diff --git a/App/Apps/W1/Foo/test/FooTests.Codeunit.al b/App/Apps/W1/Foo/test/FooTests.Codeunit.al
225+
--- a/App/Apps/W1/Foo/test/FooTests.Codeunit.al
226+
+++ b/App/Apps/W1/Foo/test/FooTests.Codeunit.al
227+
@@ -1,3 +1,4 @@
228+
+// Not a test procedure
229+
procedure Helper()
230+
begin
231+
end;
232+
"""
233+
234+
with patch("bcbench.collection.collect_gh.GHClient") as mock_client_class:
235+
mock_client = mock_client_class.return_value
236+
mock_client.get_pr_info.return_value = {"mergeCommit": {"oid": "abc123"}}
237+
mock_client.get_pr_diff.return_value = diff
238+
mock_client.get_file_content.return_value = 'codeunit 12345 "Foo Tests"'
239+
240+
result = screen_gh_candidate(12345)
241+
242+
assert not result.passed
243+
assert result.reason == "No testable functions found in test patch"
244+
245+
213246
class TestExtractFilePathsFromPatch:
214247
def test_extracts_single_file_path(self):
215248
patch = """diff --git a/App/Code.al b/App/Code.al

0 commit comments

Comments
 (0)