Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /li-boxuan_OpenDevin /enterprise /tests /unit /solvability /conftest.py
| """ | |
| Shared fixtures for all tests. | |
| """ | |
| from typing import Any | |
| from unittest.mock import MagicMock | |
| import numpy as np | |
| import pytest | |
| from integrations.solvability.models.classifier import SolvabilityClassifier | |
| from integrations.solvability.models.featurizer import ( | |
| Feature, | |
| FeatureEmbedding, | |
| Featurizer, | |
| ) | |
| from sklearn.ensemble import RandomForestClassifier | |
| from openhands.core.config import LLMConfig | |
| def features() -> list[Feature]: | |
| """Create a list of features for testing.""" | |
| return [ | |
| Feature(identifier='feature1', description='Test feature 1'), | |
| Feature(identifier='feature2', description='Test feature 2'), | |
| Feature(identifier='feature3', description='Test feature 3'), | |
| ] | |
| def feature_embedding() -> FeatureEmbedding: | |
| """Create a feature embedding for testing.""" | |
| return FeatureEmbedding( | |
| samples=[ | |
| {'feature1': True, 'feature2': False, 'feature3': True}, | |
| {'feature1': False, 'feature2': True, 'feature3': True}, | |
| ], | |
| prompt_tokens=10, | |
| completion_tokens=5, | |
| response_latency=0.1, | |
| ) | |
| def featurizer(mock_llm, features) -> Featurizer: | |
| """ | |
| Create a featurizer for testing. | |
| Mocks out any calls to LLM.completion | |
| """ | |
| pytest.MonkeyPatch().setattr( | |
| 'integrations.solvability.models.featurizer.LLM', | |
| lambda *args, **kwargs: mock_llm, | |
| ) | |
| featurizer = Featurizer( | |
| system_prompt='Test system prompt', | |
| message_prefix='Test message prefix: ', | |
| features=features, | |
| ) | |
| return featurizer | |
| def mock_completion_response() -> dict[str, Any]: | |
| """Create a mock response for the feature sample model.""" | |
| mock_response = MagicMock() | |
| mock_response.choices = [MagicMock()] | |
| mock_response.choices[0].message.tool_calls = [MagicMock()] | |
| mock_response.choices[0].message.tool_calls[ | |
| 0 | |
| ].function.arguments = '{"feature1": true, "feature2": false, "feature3": true}' | |
| mock_response.usage.prompt_tokens = 10 | |
| mock_response.usage.completion_tokens = 5 | |
| return mock_response | |
| def mock_llm(mock_completion_response): | |
| """Create a mock LLM instance.""" | |
| mock_llm_instance = MagicMock() | |
| mock_llm_instance.completion.return_value = mock_completion_response | |
| return mock_llm_instance | |
| def mock_llm_config(): | |
| """Create a mock LLM config for testing.""" | |
| return LLMConfig(model='test-model') | |
| def mock_classifier(): | |
| """Create a mock classifier for testing.""" | |
| clf = RandomForestClassifier(random_state=42) | |
| # Initialize with some dummy data to avoid errors | |
| X = np.array([[0, 0, 0], [1, 1, 1]]) # noqa: N806 | |
| y = np.array([0, 1]) | |
| clf.fit(X, y) | |
| return clf | |
| def solvability_classifier(featurizer, mock_classifier): | |
| """Create a SolvabilityClassifier instance for testing.""" | |
| return SolvabilityClassifier( | |
| identifier='test-classifier', | |
| featurizer=featurizer, | |
| classifier=mock_classifier, | |
| random_state=42, | |
| ) | |
Xet Storage Details
- Size:
- 3.13 kB
- Xet hash:
- d50da7cc4a877b75c5b67687542a9c0d6bcf1f41dc35ea4c0fb6906863171d09
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.