Skip to content

Commit 1be80e9

Browse files
authored
🧪 Fix test file
🧪 Fix test file
2 parents f2079cc + 166cd87 commit 1be80e9

File tree

2 files changed

+0
-114
lines changed

2 files changed

+0
-114
lines changed

‎test/backend/agents/test_create_agent_info.py‎

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def _create_stub_module(name: str, **attrs):
182182
prepare_prompt_templates,
183183
_get_skills_for_template,
184184
_get_skill_script_tools,
185-
_print_prompt_with_token_count,
186185
)
187186

188187
# Import constants for testing
@@ -433,88 +432,6 @@ def test_get_skill_script_tools_tool_descriptions(self):
433432
assert "skill" in desc.lower()
434433

435434

436-
class TestPrintPromptWithTokenCount:
437-
"""Tests for the _print_prompt_with_token_count function"""
438-
439-
def test_print_prompt_with_token_count_success(self):
440-
"""Test successful token counting with tiktoken available"""
441-
import tiktoken
442-
443-
with patch('backend.agents.create_agent_info.logger') as mock_logger:
444-
mock_encoding = MagicMock()
445-
mock_encoding.encode.return_value = ["token1", "token2", "token3"]
446-
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
447-
_print_prompt_with_token_count("test prompt content", agent_id=123, stage="TEST")
448-
449-
mock_encoding.encode.assert_called_once_with("test prompt content")
450-
mock_logger.info.assert_called()
451-
452-
# Check that log messages contain expected content
453-
log_calls = mock_logger.info.call_args_list
454-
log_text = " ".join([str(call) for call in log_calls])
455-
assert "TEST" in log_text
456-
assert "123" in log_text
457-
assert "3" in log_text # Token count
458-
459-
def test_print_prompt_with_token_count_tiktoken_failure(self):
460-
"""Test graceful handling when tiktoken fails"""
461-
import tiktoken
462-
463-
with patch('backend.agents.create_agent_info.logger') as mock_logger:
464-
with patch.object(tiktoken, 'get_encoding', side_effect=Exception("tiktoken not available")):
465-
_print_prompt_with_token_count("test prompt", agent_id=456, stage="FALLBACK")
466-
467-
# Should log a warning and then log the prompt
468-
mock_logger.warning.assert_called_once()
469-
assert "Failed to count tokens: tiktoken not available" in mock_logger.warning.call_args[0][0]
470-
471-
# Should still log the prompt
472-
mock_logger.info.assert_called()
473-
474-
def test_print_prompt_with_token_count_default_stage(self):
475-
"""Test with default stage parameter"""
476-
import tiktoken
477-
478-
with patch('backend.agents.create_agent_info.logger') as mock_logger:
479-
mock_encoding = MagicMock()
480-
mock_encoding.encode.return_value = ["a", "b"]
481-
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
482-
_print_prompt_with_token_count("short prompt")
483-
484-
log_calls = mock_logger.info.call_args_list
485-
log_text = " ".join([str(call) for call in log_calls])
486-
assert "PROMPT" in log_text # Default stage
487-
488-
def test_print_prompt_with_token_count_empty_prompt(self):
489-
"""Test with empty prompt"""
490-
import tiktoken
491-
492-
with patch('backend.agents.create_agent_info.logger') as mock_logger:
493-
mock_encoding = MagicMock()
494-
mock_encoding.encode.return_value = []
495-
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
496-
_print_prompt_with_token_count("", agent_id=1, stage="EMPTY")
497-
498-
mock_encoding.encode.assert_called_once_with("")
499-
# Should log token count of 0
500-
log_calls = mock_logger.info.call_args_list
501-
log_text = " ".join([str(call) for call in log_calls])
502-
assert "0" in log_text
503-
504-
def test_print_prompt_with_token_count_none_agent_id(self):
505-
"""Test with None agent_id"""
506-
import tiktoken
507-
508-
with patch('backend.agents.create_agent_info.logger') as mock_logger:
509-
mock_encoding = MagicMock()
510-
mock_encoding.encode.return_value = ["token"]
511-
with patch.object(tiktoken, 'get_encoding', return_value=mock_encoding):
512-
_print_prompt_with_token_count("prompt", agent_id=None, stage="NO_ID")
513-
514-
# Should not raise an error
515-
mock_encoding.encode.assert_called_once_with("prompt")
516-
517-
518435
class TestDiscoverLangchainTools:
519436
"""Tests for the discover_langchain_tools function"""
520437

‎test/sdk/core/utils/test_prompt_template_utils.py‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,6 @@ def test_get_prompt_template_unsupported_type(self):
8686
assert "Unsupported template type" in str(excinfo.value)
8787
assert "unsupported_type" in str(excinfo.value)
8888

89-
@patch('builtins.open', new_callable=mock_open, read_data='system_prompt: "Test prompt"')
90-
@patch('yaml.safe_load')
91-
def test_get_prompt_template_with_kwargs(self, mock_yaml_load, mock_file):
92-
"""Test get_prompt_template with additional kwargs (should be logged but not used)"""
93-
mock_yaml_load.return_value = {"system_prompt": "Test prompt"}
94-
95-
with patch('sdk.nexent.core.utils.prompt_template_utils.logger') as mock_logger:
96-
result = get_prompt_template(template_type='analyze_image', language='en', extra_param='value')
97-
98-
# Verify kwargs were logged
99-
log_calls = [str(call) for call in mock_logger.info.call_args_list]
100-
assert any("extra_param" in str(call) or "kwargs" in str(call) for call in log_calls)
101-
102-
# Verify function still works
103-
assert result == {"system_prompt": "Test prompt"}
104-
10589
@patch('builtins.open', side_effect=FileNotFoundError("File not found"))
10690
def test_get_prompt_template_file_not_found(self, mock_file):
10791
"""Test get_prompt_template when template file is not found"""
@@ -119,21 +103,6 @@ def test_get_prompt_template_yaml_error(self, mock_yaml_load, mock_file):
119103

120104
assert "YAML parse error" in str(excinfo.value)
121105

122-
@patch('builtins.open', new_callable=mock_open, read_data='system_prompt: "Test prompt"')
123-
@patch('yaml.safe_load')
124-
@patch('sdk.nexent.core.utils.prompt_template_utils.logger')
125-
def test_get_prompt_template_logging(self, mock_logger, mock_yaml_load, mock_file):
126-
"""Test that get_prompt_template logs correctly"""
127-
mock_yaml_load.return_value = {"system_prompt": "Test prompt"}
128-
129-
get_prompt_template(template_type='analyze_image', language='en')
130-
131-
# Verify logger was called
132-
mock_logger.info.assert_called_once()
133-
log_call = str(mock_logger.info.call_args)
134-
assert "analyze_image" in log_call
135-
assert "en" in log_call
136-
137106
@patch('builtins.open', new_callable=mock_open, read_data='system_prompt: "Test prompt"')
138107
@patch('yaml.safe_load')
139108
def test_get_prompt_template_path_construction(self, mock_yaml_load, mock_file):

0 commit comments

Comments
 (0)