Spaces:
Build error
Build error
File size: 2,185 Bytes
51ff9e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
from typing import Type
from unittest.mock import MagicMock
import pytest
from pydantic import SecretStr
from openhands.core.config import LLMConfig
from openhands.integrations.provider import ProviderType
from openhands.resolver.interfaces.github import GithubIssueHandler, GithubPRHandler
from openhands.resolver.interfaces.gitlab import GitlabIssueHandler, GitlabPRHandler
from openhands.resolver.issue_handler_factory import IssueHandlerFactory
from openhands.resolver.interfaces.issue_definitions import (
ServiceContextIssue,
ServiceContextPR,
)
@pytest.fixture
def llm_config():
return LLMConfig(
model='test-model',
api_key=SecretStr('test-key'),
)
@pytest.fixture
def factory_params(llm_config):
return {
'owner': 'test-owner',
'repo': 'test-repo',
'token': 'test-token',
'username': 'test-user',
'base_domain': 'github.com',
'llm_config': llm_config,
}
test_cases = [
# platform, issue_type, expected_context_type, expected_handler_type
(ProviderType.GITHUB, 'issue', ServiceContextIssue, GithubIssueHandler),
(ProviderType.GITHUB, 'pr', ServiceContextPR, GithubPRHandler),
(ProviderType.GITLAB, 'issue', ServiceContextIssue, GitlabIssueHandler),
(ProviderType.GITLAB, 'pr', ServiceContextPR, GitlabPRHandler),
]
@pytest.mark.parametrize(
'platform,issue_type,expected_context_type,expected_handler_type',
test_cases
)
def test_handler_creation(
factory_params,
platform: ProviderType,
issue_type: str,
expected_context_type: Type,
expected_handler_type: Type,
):
factory = IssueHandlerFactory(
**factory_params,
platform=platform,
issue_type=issue_type
)
handler = factory.create()
assert isinstance(handler, expected_context_type)
assert isinstance(handler._strategy, expected_handler_type)
def test_invalid_issue_type(factory_params):
factory = IssueHandlerFactory(
**factory_params,
platform=ProviderType.GITHUB,
issue_type='invalid'
)
with pytest.raises(ValueError, match='Invalid issue type: invalid'):
factory.create() |