Skip to content

Commit

Permalink
Merge pull request #112 from AVEgame/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
mscroggs authored Jul 5, 2020
2 parents f7eb0ef + 363d1c4 commit 893e25a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
8 changes: 5 additions & 3 deletions ave/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def reset(self, items={}):
self.inventory = []
self.numbers = {}
for i in items.values():
if self.is_number(i):
if isinstance(i, NumberItem):
self.numbers[i.id] = i.default.get_value(self)
self.location = "start"

Expand Down Expand Up @@ -90,7 +90,9 @@ def remove(self, item, value=1):

def is_number(self, item):
"""Check if item is a NumberItem."""
return isinstance(item, NumberItem)
if not isinstance(item, str):
raise ValueError("item must be a string")
return item in self.numbers

def get_inventory(self, items):
"""Get the names of the character's inventory.
Expand Down Expand Up @@ -123,7 +125,7 @@ class Game:
def __init__(self, file=None, url=None,
filename=None, title="untitled", number=None,
description="", author="anonymous",
version=0, ave_version=(0, 0),
version=1, ave_version=(0, 0),
active=True):
"""Make the class.
Expand Down
31 changes: 30 additions & 1 deletion ave/test/game_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
from .error_handlers import (
AVEFatalError, AVEError, AVEWarning, AVEInfo, AVENote)
from ..game import Character
from ..components.items import NumberItem


def check_game(game):
"""Check a game for errors."""
errors = []
errors += check_metadata(game)
errors += check_first_room(game)
errors += get_inaccessible_rooms(game)
errors += get_undefined_rooms(game)
Expand All @@ -16,6 +18,33 @@ def check_game(game):
return errors


def check_metadata(game):
"""Check that the game has valid metadata."""
errors = []
if game.title == "untitled":
errors.append(AVEError("The game's title is 'untitled' (the "
"default value)."))
if game.description == "untitled":
errors.append(AVEError("The game's description is '' (the "
"default value)."))
if game.author == "anonymous":
errors.append(AVEWarning("The game's title is 'anonymous' "
"(the default value)."))
if game.version > 1:
errors.append(AVEInfo("The game's verion is greater than 1. "
"It should be an update of a preexisting "
"game."))
if not isinstance(game.version, int):
errors.append(AVEError("The game's version is not an integer."))
if max(game.ave_version) > 0:
errors.append(AVENote(
"The game is set to only work on AVE"
">=" + ".".join(str(i) for i in game.ave_version) + "."))
if not game.active:
errors.append(AVEInfo("The game is deactivated."))
return errors


def check_first_room(game):
"""Check that the first room of the game works."""
errors = []
Expand Down Expand Up @@ -98,7 +127,7 @@ def explore_items(game):
numbers = set()
named_items = set()
for i in game.items:
if c.is_number(i):
if isinstance(i, NumberItem):
numbers.add(i)
if i.default.get_value(c) != 0:
used_num.add(i)
Expand Down
4 changes: 2 additions & 2 deletions games/make.ave
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ vv 1 vv
# start
You wake up. It is the weekend, so you decide to write an AVE game.
After spending some time thinking, you decide to write a shopping simulator.
To test your game, you need to download the latest Python version of AVE, or the VirtualBox image of it. ?! __PYTHON__
Help me download and run the Python version or image => download ?! __PYTHON__
To test your game, you need to download the latest Python version of AVE, or the VirtualBox image of it.
Help me download and run the Python version or image => download
Get started => go

# go
Expand Down
20 changes: 10 additions & 10 deletions games/tea.ave
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Walk down the stairs => trollbridge_in
You are at one end of a bridge guarded by a troll. On the other end of the bridge is a grand golden doorway.
The troll says:
"You look horrible, clean yourself up, you cannot pass." ?! face_washed
"You look nice. I like your face." ? face_washed ?! real_tea
"You look nice. I like your face." ? face_washed ?! realtea
"Why have you given me a note from your mother?" ? troll_note ?! troll_crossed
The troll takes pity on you and allows you to cross. ? troll_note ?! troll_crossed
Give the troll your note => trollbridge_in ? face_washed ? mystery_note ~ mystery_note + troll_note
Expand All @@ -230,7 +230,7 @@ You are at one end of a bridge guarded by a troll. On the other end of the bridg
The troll says:
"You look nice. I like your face." ? face_washed
"You have a receipt. I want it. Please give it to me" ? receipt
"You didn't bring me back a present. I don't like you anymore" ? real_tea ?! receipt ?! troll_receipt
"You didn't bring me back a present. I don't like you anymore" ? realtea ?! receipt ?! troll_receipt
Give the troll your receipt => trollbridge_mug + mug ? receipt ~ receipt + troll_receipt
Cross the bridge => troll_kill ?! troll_receipt
Cross the bridge => ornate_doorway ? troll_receipt
Expand Down Expand Up @@ -276,14 +276,14 @@ Conveniently, there is some milk here as well. You grab it.
Continue => tea_aisle

# checkout_choice
You need to have an item before you can check out. ?! yorkshire ?! pg_tips ?! real_tea
You have two choices. You can either go to self-checkout or regular checkout. ? yorkshire ?! real_tea
You have two choices. You can either go to self-checkout or regular checkout. ? pg_tips ?! real_tea
You already paid. What are you doing? ? real_tea
Go to the regular checkout => checkout ? pg_tips ?! real_tea
Go to self-checkout => self_check ? pg_tips ?! real_tea
Go to the regular checkout => checkout ? yorkshire ?! real_tea
Go to self-checkout => self_check ? yorkshire ?! real_tea
You need to have an item before you can check out. ?! yorkshire ?! pg_tips ?! realtea
You have two choices. You can either go to self-checkout or regular checkout. ? yorkshire ?! realtea
You have two choices. You can either go to self-checkout or regular checkout. ? pg_tips ?! realtea
You already paid. What are you doing? ? realtea
Go to the regular checkout => checkout ? pg_tips ?! realtea
Go to self-checkout => self_check ? pg_tips ?! realtea
Go to the regular checkout => checkout ? yorkshire ?! realtea
Go to self-checkout => self_check ? yorkshire ?! realtea
Go back to the tea aisle => tea_aisle

# self_check
Expand Down
1 change: 1 addition & 0 deletions games/test.ave
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** Matthew Scroggs **
vv 1 vv
~~ off ~~
:: 1.9 ::

# start
You wake up. What do you want to do?
Expand Down
30 changes: 14 additions & 16 deletions test/test_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ def test_games_for_errors(filename):
game = load_game_from_file(filename)
game.load()

issues = check_game(game)
errors = [i for i in issues if i.error_value > 3]
info = [i for i in issues if i.error_value <= 3]
errors.sort(key=lambda e: -e.error_value)
info.sort(key=lambda e: -e.error_value)

if len(errors) > 0:
print("\n " + str(len(errors)) + " errors(s) in " + filename)
for e in errors:
print(e)
if len(info) > 0:
print("\n " + str(len(info)) + " info(s) in " + filename)
for e in info:
print(e)
errors = check_game(game)

for i in range(5, 0, -1):
ls = [e for e in errors if e.error_value == i]
if len(ls) > 0:
print("")
for e in ls:
print(e)

# remove Info and Note errors

errors = [i for i in errors if i.error_value > 2]

if filename.endswith("test.ave"):
assert len(errors) == 1
Expand All @@ -58,12 +56,12 @@ def test_games_for_errors(filename):
assert len(errors) == 0


def test_game_library():
def xtest_game_library():
ave = AVE()
ave.get_download_menu()


def test_load_game_from_library():
def xtest_load_game_from_library():
ave = AVE()
game = load_game_from_library(ave.get_download_menu()[0][2])
game.load()
Expand Down

0 comments on commit 893e25a

Please sign in to comment.