Skip to content

Commit

Permalink
Add functional pytest tests with fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandeborde committed Apr 25, 2024
1 parent b01acca commit 68c8c1b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
46 changes: 36 additions & 10 deletions tests/utils.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import pytest
from gigax.scene import Character, Item, Location, ParameterType
from gigax.parse import CharacterAction, ProtagonistCharacter, Skill


def create_scene():
@pytest.fixture()
def context():
# Example usage of the function
context = "A vast open world full of mystery and adventure."
locations = [Location(name="Old Town", description="A quiet and peaceful town.")]
NPCs = [
return "A vast open world full of mystery and adventure."


@pytest.fixture()
def locations():
return [Location(name="Old Town", description="A quiet and peaceful town.")]


@pytest.fixture()
def current_location(locations):
return locations[0]


@pytest.fixture()
def NPCs(current_location):
return [
Character(
name="John the Brave",
description="A fearless warrior",
current_location=locations[0],
current_location=current_location,
)
]
protagonist = ProtagonistCharacter(


@pytest.fixture()
def protagonist(current_location):
return ProtagonistCharacter(
name="Aldren",
description="Brave and curious",
current_location=locations[0],
current_location=current_location,
memories=["Saved the village", "Lost a friend"],
quests=["Find the ancient artifact", "Defeat the evil warlock"],
skills=[
Expand All @@ -28,12 +47,19 @@ def create_scene():
],
psychological_profile="Determined and compassionate",
)
items = [Item(name="Sword", description="A sharp blade")]
events = [


@pytest.fixture()
def items():
return [Item(name="Sword", description="A sharp blade")]


@pytest.fixture()
def events(protagonist, items):
return [
CharacterAction(
command="Say",
protagonist=protagonist,
parameters=[items[0], "What a fine sword!"],
)
]
return context, locations, NPCs, protagonist, items, events
11 changes: 7 additions & 4 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from gigax.parse import CharacterAction, get_guided_regex
from tests.utils import create_scene
from gigax.scene import Character, Item, Location, ProtagonistCharacter


def test_parse():
_, locations, NPCs, protagonist, items, _ = create_scene()

def test_parse(
locations: list[Location],
NPCs: list[Character],
protagonist: ProtagonistCharacter,
items: list[Item],
):
test_command = 'attack John the Brave "Hello, how are you"'

# Test the compiled regex
Expand Down
14 changes: 11 additions & 3 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from gigax.parse import CharacterAction
from gigax.prompt import NPCPrompt
from tests.utils import create_scene
from gigax.scene import Character, Item, Location, ProtagonistCharacter


def test_prompt():
prompt = NPCPrompt(*create_scene())
def test_prompt(
context: str,
locations: list[Location],
NPCs: list[Character],
protagonist: ProtagonistCharacter,
items: list[Item],
events: list[CharacterAction],
):
prompt = NPCPrompt(context, locations, NPCs, protagonist, items, events)
assert prompt

test_prompt = """- WORLD KNOWLEDGE: A vast open world full of mystery and adventure.
Expand Down

0 comments on commit 68c8c1b

Please sign in to comment.