test_issue_references.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. from openhands.resolver.issue_definitions import IssueHandler
  2. def test_extract_issue_references():
  3. handler = IssueHandler("test-owner", "test-repo", "test-token")
  4. # Test basic issue reference
  5. assert handler._extract_issue_references("Fixes #123") == [123]
  6. # Test multiple issue references
  7. assert handler._extract_issue_references("Fixes #123, #456") == [123, 456]
  8. # Test issue references in code blocks should be ignored
  9. assert handler._extract_issue_references("""
  10. Here's a code block:
  11. ```python
  12. # This is a comment with #123
  13. def func():
  14. pass # Another #456
  15. ```
  16. But this #789 should be extracted
  17. """) == [789]
  18. # Test issue references in inline code should be ignored
  19. assert handler._extract_issue_references("This `#123` should be ignored but #456 should be extracted") == [456]
  20. # Test issue references in URLs should be ignored
  21. assert handler._extract_issue_references("Check http://example.com/#123 but #456 should be extracted") == [456]
  22. # Test issue references in markdown links should be extracted
  23. assert handler._extract_issue_references("[Link to #123](http://example.com) and #456") == [123, 456]
  24. # Test issue references with text around them
  25. assert handler._extract_issue_references("Issue #123 is fixed and #456 is pending") == [123, 456]