🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
add test.
刘棒棒c96b51777440
diff --git a/tests/metagpt/actions/test_execute_code.py b/tests/metagpt/actions/test_execute_code.pyindex 904cc3c58..ecddccf6f 100644--- a/tests/metagpt/actions/test_execute_code.py+++ b/tests/metagpt/actions/test_execute_code.py@@ -52,42 +52,21 @@ async def test_plotting_code():# 显示图形plt.show()+ plt.close()"""output = await pi.run(code)assert output[1] is True-async def test_plotting_bug():- code = """- import matplotlib.pyplot as plt- import seaborn as sns- import pandas as pd- from sklearn.datasets import load_iris- # Load the Iris dataset- iris_data = load_iris()- # Convert the loaded Iris dataset into a DataFrame for easier manipulation- iris_df = pd.DataFrame(iris_data['data'], columns=iris_data['feature_names'])- # Add a column for the target- iris_df['species'] = pd.Categorical.from_codes(iris_data['target'], iris_data['target_names'])- # Set the style of seaborn- sns.set(style='whitegrid')- # Create a pairplot of the iris dataset- plt.figure(figsize=(10, 8))- pairplot = sns.pairplot(iris_df, hue='species')- # Show the plot- plt.show()- """- pi = ExecutePyCode()- output = await pi.run(code)- assert output[1] is True--def test_truncate():- output = "hello world"- assert truncate(output) == output- output = "hello world"- assert truncate(output, 5) == "Truncated to show only the last 5 characters\nworld"+ # 代码执行成功+ output, is_success = truncate("hello world", 5, True)+ assert "Truncated to show only first 5 characters\nhello" in output+ assert is_success+ # 代码执行失败+ output, is_success = truncate("hello world", 5, False)+ assert "Truncated to show only last 5 characters\nworld" in output+ assert not is_success@pytest.mark.asyncio@@ -97,3 +76,14 @@ async def test_run_with_timeout():message, success = await pi.run(code)assert not successassert message.startswith("Cell execution timed out")+++async def test_run_code_text():+ pi = ExecutePyCode()+ message, success = await pi.run(code='print("This is a code!")', language="python")+ assert success+ assert message == "This is a code!\n"+ message, success = await pi.run(code="# This is a code!", language="markdown")+ assert success+ assert message == "# This is a code!"