Fix unit tests
This commit is contained in:
parent
d0a7a23cb6
commit
1c8337ff69
2 changed files with 5 additions and 3 deletions
|
|
@ -56,7 +56,7 @@ class LLMNPC(DefaultCharacter):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def llm_client(self):
|
def llm_client(self):
|
||||||
if not hasattr(self, "_llm_client"):
|
if not self.ndb.llm_client:
|
||||||
self.ndb.llm_client = LLMClient()
|
self.ndb.llm_client = LLMClient()
|
||||||
return self.ndb.llm_client
|
return self.ndb.llm_client
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ Unit tests for the LLM Client and npc.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from anything import Something
|
from anything import Something
|
||||||
|
from django.test import override_settings
|
||||||
from evennia.utils.create import create_object
|
from evennia.utils.create import create_object
|
||||||
from evennia.utils.test_resources import EvenniaTestCase
|
from evennia.utils.test_resources import EvenniaTestCase
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
|
|
@ -12,6 +13,7 @@ from .llm_npc import LLMNPC
|
||||||
|
|
||||||
|
|
||||||
class TestLLMClient(EvenniaTestCase):
|
class TestLLMClient(EvenniaTestCase):
|
||||||
|
@override_settings(LLM_PROMPT_PREFIX="You are a test bot.")
|
||||||
@patch("evennia.contrib.rpg.llm.llm_npc.task.deferLater")
|
@patch("evennia.contrib.rpg.llm.llm_npc.task.deferLater")
|
||||||
def test_npc_at_talked_to(self, mock_deferLater):
|
def test_npc_at_talked_to(self, mock_deferLater):
|
||||||
"""
|
"""
|
||||||
|
|
@ -19,9 +21,9 @@ class TestLLMClient(EvenniaTestCase):
|
||||||
"""
|
"""
|
||||||
npc = create_object(LLMNPC, key="Test NPC")
|
npc = create_object(LLMNPC, key="Test NPC")
|
||||||
mock_LLMClient = Mock()
|
mock_LLMClient = Mock()
|
||||||
npc._llm_client = mock_LLMClient
|
npc.ndb.llm_client = mock_LLMClient
|
||||||
|
|
||||||
npc.at_talked_to("Hello", npc)
|
npc.at_talked_to("Hello", npc)
|
||||||
|
|
||||||
mock_deferLater.assert_called_with(Something, npc.thinking_timeout, Something)
|
mock_deferLater.assert_called_with(Something, npc.thinking_timeout, Something)
|
||||||
mock_LLMClient.get_response.assert_called_with("Hello")
|
mock_LLMClient.get_response.assert_called_with("You are a test bot.\nTest NPC: Hello")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue