Skip to content

Commit

Permalink
Add import checks to see if openai or anthropic keys are present and …
Browse files Browse the repository at this point in the history
…not to run if not
  • Loading branch information
elliottower committed Nov 14, 2023
1 parent da49744 commit c9bfd75
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import unittest
import warnings
from unittest import TestCase
Expand All @@ -7,22 +8,42 @@

class TestCLI(TestCase):
def test_cli_1(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/nlp-classroom.json")
arena.launch_cli(max_steps=10, interactive=False)

def test_cli_2(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/chameleon.json")
arena.launch_cli(max_steps=10, interactive=False)

def test_cli_3(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/tic-tac-toe.json")
arena.launch_cli(max_steps=10, interactive=False)

def test_cli_4(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/rock-paper-scissors.json")
arena.launch_cli(max_steps=10, interactive=False)

def test_cli_5(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/nlp-classroom-3players.json")
arena.launch_cli(max_steps=10, interactive=False)

Expand All @@ -31,8 +52,11 @@ def test_cli_6(self):
arena = Arena.from_config("examples/pettingzoo_chess.json")
arena.launch_cli(max_steps=10, interactive=False)

@unittest.skip("Disabled because it requires an anthropic API key to test")
def test_cli_7(self):
unittest.skipIf(
not os.environ.get("ANTHROPIC_API_KEY"),
"Anthropic API key must be set to run this test.",
)
# Suppress ResourceWarning
warnings.filterwarnings(
action="ignore", message="unclosed", category=ResourceWarning
Expand All @@ -42,6 +66,10 @@ def test_cli_7(self):
arena.launch_cli(max_steps=6, interactive=False)

def test_cli_8(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/interview.json")
arena.launch_cli(max_steps=16, interactive=False)

Expand All @@ -51,6 +79,10 @@ def test_cli_9(self):
arena.launch_cli(max_steps=6, interactive=False)

def test_cli_10(self):
unittest.skipIf(
not os.getenv("OPENAI_API_KEY"),
"OpenAI API key must be set to run this test.",
)
arena = Arena.from_config("examples/prisoners_dilemma.json")
arena.launch_cli(max_steps=3, interactive=False)

Expand Down

0 comments on commit c9bfd75

Please sign in to comment.