From b8530a30d7f96b590668e251dd932904a38681ef Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Sun, 5 Jul 2020 09:21:24 +0100 Subject: [PATCH 1/5] no warnings in built in games --- test/test_games.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/test_games.py b/test/test_games.py index 0020bf0..1509b33 100644 --- a/test/test_games.py +++ b/test/test_games.py @@ -35,20 +35,14 @@ 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 = check_game(game) 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) + for e in errors: + 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 From 9f3fdb2b4c9c3ac19a09f1f1d191e4ebf2af6422 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Sun, 5 Jul 2020 09:49:46 +0100 Subject: [PATCH 2/5] fix the number tests --- ave/game.py | 6 ++++-- ave/parsing/file_parsing.py | 1 + ave/test/game_validation.py | 4 +++- games/make.ave | 4 ++-- games/tea.ave | 20 ++++++++++---------- test/test_games.py | 7 +++++-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/ave/game.py b/ave/game.py index 180d26f..8ea41cf 100644 --- a/ave/game.py +++ b/ave/game.py @@ -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" @@ -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. diff --git a/ave/parsing/file_parsing.py b/ave/parsing/file_parsing.py index a78aeab..5893991 100644 --- a/ave/parsing/file_parsing.py +++ b/ave/parsing/file_parsing.py @@ -189,6 +189,7 @@ def parse_item(id, item): if hidden is None: hidden = False names.append(parse_name_part(line)) + print(id, number) if number: return NumberItem(id=id, names=names, hidden=hidden, default=default) else: diff --git a/ave/test/game_validation.py b/ave/test/game_validation.py index 34a5b1e..aee25b6 100644 --- a/ave/test/game_validation.py +++ b/ave/test/game_validation.py @@ -2,6 +2,7 @@ from .error_handlers import ( AVEFatalError, AVEError, AVEWarning, AVEInfo, AVENote) from ..game import Character +from ..components.items import NumberItem def check_game(game): @@ -75,6 +76,7 @@ def get_undefined_numbers(game): for room in game.rooms.values(): for thing in room.options + room.text: for item in thing.items: + print(item.item, c.is_number(item.item)) if not c.is_number(item.item) and item.value.get_value(c) != 1: not_def.add(item.item) return [AVEWarning("The game wants to add a number to '" + i + "'," @@ -98,7 +100,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) diff --git a/games/make.ave b/games/make.ave index f710ff7..bc4f6da 100644 --- a/games/make.ave +++ b/games/make.ave @@ -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 diff --git a/games/tea.ave b/games/tea.ave index 157750e..1124e6d 100644 --- a/games/tea.ave +++ b/games/tea.ave @@ -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 @@ -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 @@ -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 diff --git a/test/test_games.py b/test/test_games.py index 1509b33..507d432 100644 --- a/test/test_games.py +++ b/test/test_games.py @@ -38,10 +38,13 @@ def test_games_for_errors(filename): errors = check_game(game) errors.sort(key=lambda e: -e.error_value) - for e in errors: - print(e) + if len(errors) > 0: + print("Info about", filename) + for e in errors: + print(e) # remove Info and Note errors + errors = [i for i in errors if i.error_value > 2] if filename.endswith("test.ave"): From e3c73dac405cd383386ed2c29ab6e26eeac19f20 Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Sun, 5 Jul 2020 10:06:00 +0100 Subject: [PATCH 3/5] Check the game metadata for issues --- ave/game.py | 2 +- ave/parsing/file_parsing.py | 1 - ave/test/game_validation.py | 22 +++++++++++++++++++++- games/test.ave | 1 + test/test_games.py | 11 ++++++----- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ave/game.py b/ave/game.py index 8ea41cf..59db6fd 100644 --- a/ave/game.py +++ b/ave/game.py @@ -125,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. diff --git a/ave/parsing/file_parsing.py b/ave/parsing/file_parsing.py index 5893991..a78aeab 100644 --- a/ave/parsing/file_parsing.py +++ b/ave/parsing/file_parsing.py @@ -189,7 +189,6 @@ def parse_item(id, item): if hidden is None: hidden = False names.append(parse_name_part(line)) - print(id, number) if number: return NumberItem(id=id, names=names, hidden=hidden, default=default) else: diff --git a/ave/test/game_validation.py b/ave/test/game_validation.py index aee25b6..aca3396 100644 --- a/ave/test/game_validation.py +++ b/ave/test/game_validation.py @@ -8,6 +8,7 @@ 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) @@ -17,6 +18,26 @@ 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 = [] @@ -76,7 +97,6 @@ def get_undefined_numbers(game): for room in game.rooms.values(): for thing in room.options + room.text: for item in thing.items: - print(item.item, c.is_number(item.item)) if not c.is_number(item.item) and item.value.get_value(c) != 1: not_def.add(item.item) return [AVEWarning("The game wants to add a number to '" + i + "'," diff --git a/games/test.ave b/games/test.ave index 9d3ad3b..f6ea1a6 100644 --- a/games/test.ave +++ b/games/test.ave @@ -3,6 +3,7 @@ ** Matthew Scroggs ** vv 1 vv ~~ off ~~ +:: 1.9 :: # start You wake up. What do you want to do? diff --git a/test/test_games.py b/test/test_games.py index 507d432..ab5d887 100644 --- a/test/test_games.py +++ b/test/test_games.py @@ -36,12 +36,13 @@ def test_games_for_errors(filename): game.load() errors = check_game(game) - errors.sort(key=lambda e: -e.error_value) - if len(errors) > 0: - print("Info about", filename) - for e in errors: - print(e) + 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 From 551db7fb343cd5c25bfa26c883764acaa540c58e Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Sun, 5 Jul 2020 10:07:43 +0100 Subject: [PATCH 4/5] flake --- ave/test/game_validation.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ave/test/game_validation.py b/ave/test/game_validation.py index aca3396..bffa76f 100644 --- a/ave/test/game_validation.py +++ b/ave/test/game_validation.py @@ -22,17 +22,24 @@ 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).")) + 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).")) + 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).")) + 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.")) + 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) + ".")) + 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 From 363d1c4023d8013db04dc00a419420344408d0df Mon Sep 17 00:00:00 2001 From: Matthew Scroggs Date: Sun, 5 Jul 2020 10:10:14 +0100 Subject: [PATCH 5/5] temporarily disable library tests --- test/test_games.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_games.py b/test/test_games.py index ab5d887..21b63bb 100644 --- a/test/test_games.py +++ b/test/test_games.py @@ -56,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()