mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
add test.
This commit is contained in:
parent
6cb2910d14
commit
c96b517774
1 changed files with 20 additions and 30 deletions
|
|
@ -52,42 +52,21 @@ async def test_plotting_code():
|
|||
|
||||
# 显示图形
|
||||
plt.show()
|
||||
plt.close()
|
||||
"""
|
||||
output = await pi.run(code)
|
||||
assert output[1] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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 success
|
||||
assert message.startswith("Cell execution timed out")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue