make qa_engineer, enable writetest and runcode

This commit is contained in:
yzlin 2023-07-25 22:57:24 +08:00
parent 007c8c0457
commit 84b6c2bf8a
7 changed files with 202 additions and 35 deletions

View file

@ -8,19 +8,35 @@
import pytest
from metagpt.actions.write_test import WriteTest
from metagpt.logs import logger
@pytest.mark.asyncio
async def test_write_test():
code = """
def add(a, b):
return a + b
import random
from typing import Tuple
class Food:
def __init__(self, position: Tuple[int, int]):
self.position = position
def generate(self, max_y: int, max_x: int):
self.position = (random.randint(1, max_y - 1), random.randint(1, max_x - 1))
"""
write_test = WriteTest("write_test")
write_test = WriteTest()
test_cases = await write_test.run(code)
test_code = await write_test.run(
code_to_test=code,
test_file_name="test_food.py",
source_file_path="/some/dummy/path/cli_snake_game/cli_snake_game/food.py",
workspace="/some/dummy/path/cli_snake_game"
)
logger.info(test_code)
# We cannot exactly predict the generated test cases, but we can check if it is a string and if it is not empty
assert isinstance(test_cases, str)
assert len(test_cases) > 0
assert isinstance(test_code, str)
assert "from cli_snake_game.food import Food" in test_code
assert "class TestFood(unittest.TestCase)" in test_code
assert "def test_generate" in test_code