Skip to content

Commit

Permalink
Add tests for create method
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed May 29, 2024
1 parent 4f4fc17 commit 67982a7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/llm/services/test_llm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import inspect
from abc import ABC
from unittest import mock

import pytest

Expand All @@ -39,11 +40,15 @@ def test_create(service_name: str, expected_cls: type):
assert isinstance(service, expected_cls)


@pytest.mark.parametrize(
"service_name, class_name",
[("nemo", "morpheus.llm.services.nemo_llm_service.NeMoLLMService"),
("openai", "morpheus.llm.services.openai_chat_service.OpenAIChatService"),
("nvfoundation", NVFoundationLLMService, marks=pytest.mark.xfail(reason="missing dependency"))])
@pytest.mark.parametrize("service_name, class_name",
[("nemo", "morpheus.llm.services.nemo_llm_service.NeMoLLMService"),
("openai", "morpheus.llm.services.openai_chat_service.OpenAIChatService"),
("nvfoundation", "morpheus.llm.services.nvfoundation_llm_service.NVFoundationLLMService")])
def test_create_mocked(service_name: str, class_name: str):
service = LLMService.create(service_name)
assert isinstance(service, expected_cls)
with mock.patch(class_name) as mock_cls:
mock_instance = mock.MagicMock()
mock_cls.return_value = mock_instance

service = LLMService.create(service_name)
mock_cls.assert_called_once()
assert service is mock_instance

0 comments on commit 67982a7

Please sign in to comment.