test_issue_references.py 1.5 KB

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