Skip to content

Commit

Permalink
🧪 more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Dec 23, 2023
1 parent c8898d0 commit 4f96011
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/chain_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from codeinterpreterapi.chains import remove_download_link, get_file_modifications


def test_remove_download_link() -> None:
example = (
"I have created the plot to your dataset.\n\n"
"Link to the file [here](sandbox:/plot.png)."
)
assert (
remove_download_link(example).formatted_response.strip()
== "I have created the plot to your dataset."
)


def test_get_file_modifications() -> None:
base_code = """
import matplotlib.pyplot as plt
x = list(range(1, 11))
y = [29, 39, 23, 32, 4, 43, 43, 23, 43, 77]
plt.plot(x, y, marker='o')
plt.xlabel('Index')
plt.ylabel('Value')
plt.title('Data Plot')
"""
code_with_mod = base_code + "\nplt.savefig('plot.png')"

code_no_mod = base_code + "\nplt.show()"

assert get_file_modifications(code_with_mod).modifications == ["plot.png"]
assert get_file_modifications(code_no_mod).modifications == []


if __name__ == "__main__":
# test_remove_download_link()
test_get_file_modifications()
20 changes: 20 additions & 0 deletions tests/general_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def run_sync(session: CodeInterpreterSession) -> bool:
.name
)

assert (
".png"
in session.generate_response(
"Plot the current stock price of Tesla.",
)
.files[0]
.name
)

finally:
assert session.stop() == "stopped"

Expand Down Expand Up @@ -71,6 +80,17 @@ async def run_async(session: CodeInterpreterSession) -> bool:
.name
)

assert (
".jpeg"
in (
await session.agenerate_response(
"Plot the current stock price of Tesla.",
)
)
.files[0]
.name
)

finally:
assert await session.astop() == "stopped"

Expand Down

0 comments on commit 4f96011

Please sign in to comment.