update exp_pool tests

This commit is contained in:
seehi 2024-07-16 21:20:01 +08:00
parent d612d826d5
commit e70a080454
2 changed files with 8 additions and 14 deletions

View file

@ -25,31 +25,27 @@ class TestRoleZeroContextBuilder:
async def test_build_with_experiences(self, context_builder, mocker):
mocker.patch.object(BaseContextBuilder, "format_exps", return_value="Formatted experiences")
mocker.patch.object(RoleZeroContextBuilder, "replace_example_content", return_value="Updated content")
req = [{"content": "Original content 1"}, {"content": "Original content exp part"}]
req = [{"content": "Original content 1"}]
result = await context_builder.build(req=req)
assert result == [{"content": "Updated content"}, {"content": "Original content exp part"}]
assert result == [{"content": "Updated content"}]
def test_replace_example_content(self, context_builder, mocker):
mocker.patch.object(RoleZeroContextBuilder, "replace_content_between_markers", return_value="Replaced content")
result = context_builder.replace_example_content("Original text", "New example content")
assert result == "Replaced content"
context_builder.replace_content_between_markers.assert_called_once_with(
"Original text", "# Example", "# Available Commands", "New example content"
"Original text", "# Example", "# Instruction", "New example content"
)
def test_replace_content_between_markers(self):
text = "Start\n# Example\nOld content\n# Available Commands\nEnd"
text = "Start\n# Example\nOld content\n# Instruction\nEnd"
new_content = "New content"
result = RoleZeroContextBuilder.replace_content_between_markers(
text, "# Example", "# Available Commands", new_content
)
expected = "Start\n# Example\nNew content\n\n# Available Commands\nEnd"
result = RoleZeroContextBuilder.replace_content_between_markers(text, "# Example", "# Instruction", new_content)
expected = "Start\n# Example\nNew content\n\n# Instruction\nEnd"
assert result == expected
def test_replace_content_between_markers_no_match(self):
text = "Start\nNo markers\nEnd"
new_content = "New content"
result = RoleZeroContextBuilder.replace_content_between_markers(
text, "# Example", "# Available Commands", new_content
)
result = RoleZeroContextBuilder.replace_content_between_markers(text, "# Example", "# Instruction", new_content)
assert result == text

View file

@ -30,9 +30,7 @@ class TestRoleZeroSerializer:
{"role": "assistant", "content": "Some other content"},
last_item,
]
expected_output = json.dumps(
[{"role": "user", "content": "Command Editor.read executed: file_path=test.py"}, last_item]
)
expected_output = json.dumps([{"role": "user", "content": "Command Editor.read executed: file_path=test.py"}])
assert serializer.serialize_req(req=req) == expected_output
def test_filter_req(self, serializer: RoleZeroSerializer):