From 7574fb9720c7897d4fe2ec9318926cd9a365588f Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Fri, 17 Nov 2023 23:43:18 -0600 Subject: [PATCH 01/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}' --- game/common/items/item.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/game/common/items/item.py b/game/common/items/item.py index 92c3ad3..fc56ba4 100644 --- a/game/common/items/item.py +++ b/game/common/items/item.py @@ -93,46 +93,53 @@ def stack_size(self) -> int: @durability.setter def durability(self, durability: int | None) -> None: if durability is not None and not isinstance(durability, int): - raise ValueError(f'{self.__class__.__name__}.durability must be an int or None.') + raise ValueError( + f'{self.__class__.__name__}.durability must be an int. It is a(n) {type(durability)} with the value of {durability}') if durability is not None and self.stack_size != 1: raise ValueError( - f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1.') + f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1. {self.__class__.__name__}.durability has the value of {durability}') self.__durability = durability @value.setter def value(self, value: int) -> None: if value is None or not isinstance(value, int): - raise ValueError(f'{self.__class__.__name__}.value must be an int.') + raise ValueError( + f'{self.__class__.__name__}.value must be an int. It is a(n) {type(value)} with the value of {value}') self.__value: int = value @quantity.setter def quantity(self, quantity: int) -> None: if quantity is None or not isinstance(quantity, int): - raise ValueError(f'{self.__class__.__name__}.quantity must be an int.') + raise ValueError( + f'{self.__class__.__name__}.quantity must be an int. It is a(n) {type(quantity)} with the value of {quantity}') if quantity < 0: - raise ValueError(f'{self.__class__.__name__}.quantity must be greater than or equal to 0.') + raise ValueError( + f'{self.__class__.__name__}.quantity must be greater than or equal to 0. {self.__class__.__name__}.quantity has the value of {quantity}') # The self.quantity is set to the lower value between stack_size and the given quantity # The remaining given quantity is returned if it's larger than self.quantity if quantity > self.stack_size: raise ValueError(f'{self.__class__.__name__}.quantity cannot be greater than ' - f'{self.__class__.__name__}.stack_size') + f'{self.__class__.__name__}.stack_size. {self.__class__.__name__}.quantity has the value of {quantity}') self.__quantity: int = quantity @stack_size.setter def stack_size(self, stack_size: int) -> None: if stack_size is None or not isinstance(stack_size, int): - raise ValueError(f'{self.__class__.__name__}.stack_size must be an int.') + raise ValueError( + f'{self.__class__.__name__}.stack_size must be an int. It is a(n) {type(stack_size)} with the value of {stack_size}') if self.durability is not None and stack_size != 1: raise ValueError(f'{self.__class__.__name__}.stack_size must be 1 if {self.__class__.__name__}.durability ' - f'is not None.') + f'is not None. {self.__class__.__name__}.stack_size has the value of {stack_size}') if self.__quantity is not None and stack_size < self.__quantity: - raise ValueError(f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity.') + raise ValueError( + f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity. {self.__class__.__name__}.stack_size has the value of {stack_size}') self.__stack_size: int = stack_size def take(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): - raise ValueError(f'{item.__class__.__name__} is not of type Item.') + raise ValueError( + f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}') # If the item is None, just return None if item is None: @@ -156,7 +163,8 @@ def take(self, item: Self) -> Self | None: def pick_up(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): - raise ValueError(f'{item.__class__.__name__} is not of type Item.') + raise ValueError( + f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}') # If the item is None, just return None if item is None: From 5f9e72ceaba1826afb659a5b141f9697a586bb8e Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 18 Nov 2023 00:08:50 -0600 Subject: [PATCH 02/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}.' in game_board.py and added periods to the errors in item.py. --- game/common/items/item.py | 22 +++++++++++----------- game/common/map/game_board.py | 32 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/game/common/items/item.py b/game/common/items/item.py index fc56ba4..a09716d 100644 --- a/game/common/items/item.py +++ b/game/common/items/item.py @@ -94,52 +94,52 @@ def stack_size(self) -> int: def durability(self, durability: int | None) -> None: if durability is not None and not isinstance(durability, int): raise ValueError( - f'{self.__class__.__name__}.durability must be an int. It is a(n) {type(durability)} with the value of {durability}') + f'{self.__class__.__name__}.durability must be an int. It is a(n) {type(durability)} with the value of {durability}.') if durability is not None and self.stack_size != 1: raise ValueError( - f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1. {self.__class__.__name__}.durability has the value of {durability}') + f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1. {self.__class__.__name__}.durability has the value of {durability}.') self.__durability = durability @value.setter def value(self, value: int) -> None: if value is None or not isinstance(value, int): raise ValueError( - f'{self.__class__.__name__}.value must be an int. It is a(n) {type(value)} with the value of {value}') + f'{self.__class__.__name__}.value must be an int. It is a(n) {type(value)} with the value of {value}.') self.__value: int = value @quantity.setter def quantity(self, quantity: int) -> None: if quantity is None or not isinstance(quantity, int): raise ValueError( - f'{self.__class__.__name__}.quantity must be an int. It is a(n) {type(quantity)} with the value of {quantity}') + f'{self.__class__.__name__}.quantity must be an int. It is a(n) {type(quantity)} with the value of {quantity}.') if quantity < 0: raise ValueError( - f'{self.__class__.__name__}.quantity must be greater than or equal to 0. {self.__class__.__name__}.quantity has the value of {quantity}') + f'{self.__class__.__name__}.quantity must be greater than or equal to 0. {self.__class__.__name__}.quantity has the value of {quantity}.') # The self.quantity is set to the lower value between stack_size and the given quantity # The remaining given quantity is returned if it's larger than self.quantity if quantity > self.stack_size: raise ValueError(f'{self.__class__.__name__}.quantity cannot be greater than ' - f'{self.__class__.__name__}.stack_size. {self.__class__.__name__}.quantity has the value of {quantity}') + f'{self.__class__.__name__}.stack_size. {self.__class__.__name__}.quantity has the value of {quantity}.') self.__quantity: int = quantity @stack_size.setter def stack_size(self, stack_size: int) -> None: if stack_size is None or not isinstance(stack_size, int): raise ValueError( - f'{self.__class__.__name__}.stack_size must be an int. It is a(n) {type(stack_size)} with the value of {stack_size}') + f'{self.__class__.__name__}.stack_size must be an int. It is a(n) {type(stack_size)} with the value of {stack_size}.') if self.durability is not None and stack_size != 1: raise ValueError(f'{self.__class__.__name__}.stack_size must be 1 if {self.__class__.__name__}.durability ' - f'is not None. {self.__class__.__name__}.stack_size has the value of {stack_size}') + f'is not None. {self.__class__.__name__}.stack_size has the value of {stack_size}.') if self.__quantity is not None and stack_size < self.__quantity: raise ValueError( - f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity. {self.__class__.__name__}.stack_size has the value of {stack_size}') + f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity. {self.__class__.__name__}.stack_size has the value of {stack_size}.') self.__stack_size: int = stack_size def take(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): raise ValueError( - f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}') + f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}.') # If the item is None, just return None if item is None: @@ -164,7 +164,7 @@ def take(self, item: Self) -> Self | None: def pick_up(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): raise ValueError( - f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}') + f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}.') # If the item is None, just return None if item is None: diff --git a/game/common/map/game_board.py b/game/common/map/game_board.py index d7a1ebc..b122072 100644 --- a/game/common/map/game_board.py +++ b/game/common/map/game_board.py @@ -136,7 +136,8 @@ def seed(self, seed: int | None) -> None: if self.game_map is not None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if seed is not None and not isinstance(seed, int): - raise ValueError(f'{self.__class__.__name__}.seed must be an integer or None.') + raise ValueError( + f'{self.__class__.__name__}.seed must be an int. It is a(n) {type(seed)} with the value of {seed}.') self.__seed = seed @property @@ -149,7 +150,8 @@ def game_map(self, game_map: list[list[Tile]]) -> None: any(map(lambda l: not isinstance(l, list), game_map)) or any([any(map(lambda g: not isinstance(g, Tile), tile_list)) for tile_list in game_map])): - raise ValueError(f'{self.__class__.__name__}.game_map must be a list[list[Tile]].') + raise ValueError( + f'{self.__class__.__name__}.game_map must be a list[list[Tile]]. It is a(n) {type(game_map)} with the value of {game_map}.') self.__game_map = game_map @property @@ -161,7 +163,8 @@ def map_size(self, map_size: Vector) -> None: if self.game_map is not None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if map_size is None or not isinstance(map_size, Vector): - raise ValueError(f'{self.__class__.__name__}.map_size must be a Vector.') + raise ValueError( + f'{self.__class__.__name__}.map_size must be a Vector. It is a(n) {type(map_size)} with the value of {map_size}.') self.__map_size = map_size @property @@ -173,13 +176,8 @@ def locations(self, locations: dict[tuple[Vector]:list[GameObject]] | None) -> N if self.game_map is not None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if locations is not None and not isinstance(locations, dict): - raise ValueError("Locations must be a dict. The key must be a tuple of Vector Objects, and the " - "value a list of GameObject.") - # if locations is not None: - # for k, v in locations.items(): - # if len(k) != len(v): - # raise ValueError("Cannot set the locations for the game_board. A key has a different " - # "length than its key.") + raise ValueError( + f'Locations must be a dict. The key must be a tuple of Vector Objects, and the value a list of GameObject. It is a(n) {type(locations)} with the value of {locations}.') self.__locations = locations @@ -192,7 +190,8 @@ def walled(self, walled: bool) -> None: if self.game_map is not None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if walled is None or not isinstance(walled, bool): - raise ValueError(f'{self.__class__.__name__}.walled must be a bool.') + raise ValueError( + f'{self.__class__.__name__}.walled must be a bool. It is a(n) {type(walled)} with the value of {walled}.') self.__walled = walled @@ -213,7 +212,8 @@ def generate_map(self) -> None: def __populate_map(self) -> None: for k, v in self.locations.items(): if len(k) == 0 or len(v) == 0: # Key-Value lengths must be > 0 and equal - raise ValueError("A key-value pair from game_board.locations has a length of 0. ") + raise ValueError( + f'A key-value pair from game_board.locations has a length of 0. The length of the keys is {len(k)} and the length of the values is {len(v)}.') # random.sample returns a randomized list which is used in __help_populate() j = random.sample(k, k=len(k)) @@ -253,7 +253,8 @@ def __help_populate(self, vector_list: list[Vector], game_object_list: list[Game temp_tile = temp_tile.occupied_by if temp_tile.occupied_by is not None: - raise ValueError("Last item on the given tile doesn't have the 'occupied_by' attribute.") + raise ValueError( + f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute. It is a(n) {type(temp_tile.occupied_by)}.') temp_tile.occupied_by = game_object @@ -268,7 +269,7 @@ def __help_populate(self, vector_list: list[Vector], game_object_list: list[Game for game_object in remaining_objects: if not hasattr(temp_tile, 'occupied_by') or temp_tile.occupied_by is not None: - raise ValueError("Last item on the given tile doesn't have the 'occupied_by' attribute.") + raise ValueError(f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute. It is a(n) {type(temp_tile.occupied_by)}.') temp_tile.occupied_by = game_object temp_tile = temp_tile.occupied_by @@ -327,8 +328,7 @@ def __from_json_helper(self, data: dict) -> GameObject: return Avatar().from_json(data) # If adding more ObjectTypes that can be placed on the game_board, specify here case _: - raise ValueError(f'The location (dict) must have a valid key (tuple of vectors) and a valid value (' - f'list of GameObjects).') + raise ValueError(f'The object type of the object is not handled properly. The object type passed in is {temp}.') def from_json(self, data: dict) -> Self: super().from_json(data) From 5e29350fcba1e6e8fb0ff4df86bd92026f641169 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 18 Nov 2023 00:13:23 -0600 Subject: [PATCH 03/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}.' in game_board.py and added periods to the errors in item.py. --- game/common/map/occupiable.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game/common/map/occupiable.py b/game/common/map/occupiable.py index fc1fc1b..d6941ac 100644 --- a/game/common/map/occupiable.py +++ b/game/common/map/occupiable.py @@ -28,9 +28,11 @@ def occupied_by(self) -> GameObject | None: @occupied_by.setter def occupied_by(self, occupied_by: GameObject | None) -> None: if occupied_by is not None and isinstance(occupied_by, Item): - raise ValueError(f'{self.__class__.__name__}.occupied_by cannot be an Item.') + raise ValueError( + f'{self.__class__.__name__}.occupied_by must be a GameObject. It is a(n) {type(occupied_by)} with the value of {occupied_by}') if occupied_by is not None and not isinstance(occupied_by, GameObject): - raise ValueError(f'{self.__class__.__name__}.occupied_by must be None or an instance of GameObject.') + raise ValueError( + f'{self.__class__.__name__}.occupied_by must be None or an instance of GameObject. It is a(n) {type(occupied_by)} with the value of {occupied_by}') self.__occupied_by = occupied_by def to_json(self) -> dict: From a45b9b664216a76b2a41c656132d6cc08cf541b6 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 18 Nov 2023 00:20:22 -0600 Subject: [PATCH 04/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}.' in game_board.py and added periods to the errors in item.py. --- game/common/avatar.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/game/common/avatar.py b/game/common/avatar.py index 5f3b074..dc32930 100644 --- a/game/common/avatar.py +++ b/game/common/avatar.py @@ -181,12 +181,13 @@ def held_item(self, item: Item | None) -> None: # If it's not an item, and it's not None, raise the error if item is not None and not isinstance(item, Item): - raise ValueError(f'{self.__class__.__name__}.held_item must be an Item or None.') + raise ValueError( + f'{self.__class__.__name__}.held_item must be an Item or None. It is a(n) {type(item)} and has the value of {item}') # If the item is not contained in the inventory, the error will be raised. if not self.inventory.__contains__(item): raise ValueError(f'{self.__class__.__name__}.held_item must be set to an item that already exists' - f' in the inventory.') + f' in the inventory. It has the value of {item}') # If the item is contained in the inventory, set the held_index to that item's index self.__held_index = self.inventory.index(item) @@ -194,13 +195,15 @@ def held_item(self, item: Item | None) -> None: @score.setter def score(self, score: int) -> None: if score is None or not isinstance(score, int): - raise ValueError(f'{self.__class__.__name__}.score must be an int.') + raise ValueError( + f'{self.__class__.__name__}.score must be an int. It is a(n) {type(score)} and has the value of {score}') self.__score: int = score @position.setter def position(self, position: Vector | None) -> None: if position is not None and not isinstance(position, Vector): - raise ValueError(f'{self.__class__.__name__}.position must be a Vector or None.') + raise ValueError( + f'{self.__class__.__name__}.position must be a Vector or None. It is a(n) {type(position)} and has the value of {position}') self.__position: Vector | None = position @inventory.setter @@ -209,16 +212,17 @@ def inventory(self, inventory: list[Item | None]) -> None: if inventory is None or not isinstance(inventory, list) \ or (len(inventory) > 0 and any(map(lambda item: item is not None and not isinstance(item, Item), inventory))): - raise ValueError(f'{self.__class__.__name__}.inventory must be a list of Items.') + raise ValueError( + f'{self.__class__.__name__}.inventory must be a list of Items. It is a(n) {type(inventory)} and has the value of {inventory}') if len(inventory) > self.max_inventory_size: raise ValueError(f'{self.__class__.__name__}.inventory size must be less than or equal to ' - f'max_inventory_size') + f'max_inventory_size. It has the value of {len(inventory)}') self.__inventory: list[Item] = inventory @max_inventory_size.setter def max_inventory_size(self, size: int) -> None: if size is None or not isinstance(size, int): - raise ValueError(f'{self.__class__.__name__}.max_inventory_size must be an int.') + raise ValueError(f'{self.__class__.__name__}.max_inventory_size must be an int. It is a(n) {type(size)} and has the value of {size}') self.__max_inventory_size: int = size # Private helper method that cleans the inventory of items that have a quantity of 0. This is a safety check From baba80e480fda4b455891e7ba7df4c09b6fc81ac Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 18 Nov 2023 00:24:08 -0600 Subject: [PATCH 05/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}.' in game_board.py and added periods to the errors in item.py. --- game/common/player.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/game/common/player.py b/game/common/player.py index 80c2dc9..ba3ff45 100644 --- a/game/common/player.py +++ b/game/common/player.py @@ -16,6 +16,7 @@ class Player(GameObject): items, etc.). For more details on the difference between the Player and Avatar classes, refer to the README document. """ + def __init__(self, code: object | None = None, team_name: str | None = None, actions: list[ActionType] = [], avatar: Avatar | None = None): super().__init__() @@ -39,7 +40,8 @@ def actions(self, actions: list[ActionType] | list) -> None: # showing it retur if actions is None or not isinstance(actions, list) \ or (len(actions) > 0 and any(map(lambda action_type: not isinstance(action_type, ActionType), actions))): - raise ValueError(f'{self.__class__.__name__}.action must be an empty list or a list of action types') + raise ValueError( + f'{self.__class__.__name__}.action must be an empty list or a list of action types. It is a(n) {type(actions)} and has the value of {actions}.') # ^if it's not either throw an error self.__actions = actions @@ -50,7 +52,8 @@ def functional(self) -> bool: @functional.setter # do this for all the setters def functional(self, functional: bool) -> None: # this enforces the type hinting if functional is None or not isinstance(functional, bool): # if this statement is true throw an error - raise ValueError(f'{self.__class__.__name__}.functional must be a boolean') + raise ValueError( + f'{self.__class__.__name__}.functional must be a boolean. It is a(n) {type(functional)} and has the value of {functional}.') self.__functional = functional @property @@ -60,7 +63,8 @@ def team_name(self) -> str: @team_name.setter def team_name(self, team_name: str) -> None: if team_name is not None and not isinstance(team_name, str): - raise ValueError(f'{self.__class__.__name__}.team_name must be a String or None') + raise ValueError( + f'{self.__class__.__name__}.team_name must be a String or None. It is a(n) {type(team_name)} and has the value of {team_name}.') self.__team_name = team_name @property @@ -70,7 +74,8 @@ def avatar(self) -> Avatar: @avatar.setter def avatar(self, avatar: Avatar) -> None: if avatar is not None and not isinstance(avatar, Avatar): - raise ValueError(f'{self.__class__.__name__}.avatar must be Avatar or None') + raise ValueError( + f'{self.__class__.__name__}.avatar must be Avatar or None. It is a(n) {type(avatar)} and has the value of {avatar}.') self.__avatar = avatar @property @@ -80,7 +85,8 @@ def object_type(self) -> ObjectType: @object_type.setter def object_type(self, object_type: ObjectType) -> None: if object_type is None or not isinstance(object_type, ObjectType): - raise ValueError(f'{self.__class__.__name__}.object_type must be ObjectType') + raise ValueError( + f'{self.__class__.__name__}.object_type must be ObjectType. It is a(n) {type(object_type)} and has the value of {object_type}.') self.__object_type = object_type def to_json(self): @@ -127,12 +133,12 @@ def from_json(self, data): # self.action = Action().from_json(data['action']) if data['action'] is not None else None # self.avatar = Avatar().from_json(data['avatar']) if data['avatar'] is not None else None -# to String + # to String def __str__(self): p = f"""ID: {self.id} Team name: {self.team_name} Actions: """ # This concatenates every action from the list of actions to the string - [p:= p + action for action in self.actions] + [p := p + action for action in self.actions] return p From 06d57ee5dd75b971ff2cff691f513a2e8b0b4301 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 18 Nov 2023 00:34:54 -0600 Subject: [PATCH 06/10] Changed the ValueError message to the structure of f'{self.class.name}. must be a It is a(n) {type()} with the value of {var_name}.' in game_board.py and changed occupational_station.py and tile.py to ValueError to The object type of the object is not handled properly. The object type passed in is {temp}. --- game/common/map/tile.py | 2 +- game/common/stations/occupiable_station.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/game/common/map/tile.py b/game/common/map/tile.py index 58060f8..4be6073 100644 --- a/game/common/map/tile.py +++ b/game/common/map/tile.py @@ -41,5 +41,5 @@ def from_json(self, data: dict) -> Self: case ObjectType.WALL: self.occupied_by: Wall = Wall().from_json(occupied_by) case _: - raise Exception(f'Could not parse occupied_by: {occupied_by}') + raise Exception(f'The object type of the object is not handled properly. The object type passed in is {occupied_by}.') return self \ No newline at end of file diff --git a/game/common/stations/occupiable_station.py b/game/common/stations/occupiable_station.py index 377a7b5..c7722b1 100644 --- a/game/common/stations/occupiable_station.py +++ b/game/common/stations/occupiable_station.py @@ -42,5 +42,5 @@ def from_json(self, data: dict) -> Self: case ObjectType.STATION: self.occupied_by: Station = Station().from_json(occupied_by) case _: - raise Exception(f'Could not parse occupied_by: {occupied_by}') + raise ValueError(f'The object type of the object is not handled properly. The object type passed in is {occupied_by}.') return self From a8e4bd7d7eeed4c7e11ced0d65b519c9f829f7ba Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 25 Nov 2023 23:41:44 -0600 Subject: [PATCH 07/10] Edited test files in occupiable_station.py, test_avatar.py, test_avatar_inventory.py, test_game_board_no_gen.py, test_item.py, test_occupiable_station.py, and test_station.py so that their error messages matched in both their main file and test file. Still need to fix OccupiableStation test_fail_item_occ, test_set_quantity_fail_greater_than_0, test_set_quantity_fail_stack_size, and test_stack_size_fail_quantity --- game/common/stations/occupiable_station.py | 3 +- game/test_suite/tests/test_avatar.py | 17 ++++-- .../test_suite/tests/test_avatar_inventory.py | 22 +++++--- .../tests/test_game_board_no_gen.py | 31 ++++++++--- game/test_suite/tests/test_item.py | 55 +++++++++++++------ .../tests/test_occupiable_station.py | 7 ++- game/test_suite/tests/test_station.py | 5 +- 7 files changed, 94 insertions(+), 46 deletions(-) diff --git a/game/common/stations/occupiable_station.py b/game/common/stations/occupiable_station.py index c7722b1..c457523 100644 --- a/game/common/stations/occupiable_station.py +++ b/game/common/stations/occupiable_station.py @@ -42,5 +42,6 @@ def from_json(self, data: dict) -> Self: case ObjectType.STATION: self.occupied_by: Station = Station().from_json(occupied_by) case _: - raise ValueError(f'The object type of the object is not handled properly. The object type passed in is {occupied_by}.') + raise ValueError(f'{self.__class__.__name__}.occupied_by must be a GameObject.' + f' It is a(n) {occupied_by.__class__.__name__} with the value of {occupied_by}') return self diff --git a/game/test_suite/tests/test_avatar.py b/game/test_suite/tests/test_avatar.py index 5ccd7ff..6446ee2 100644 --- a/game/test_suite/tests/test_avatar.py +++ b/game/test_suite/tests/test_avatar.py @@ -23,8 +23,10 @@ def test_avatar_set_item(self): def test_avatar_set_item_fail(self): with self.assertRaises(ValueError) as e: - self.avatar.held_item = 3 - self.assertEqual(str(e.exception), 'Avatar.held_item must be an Item or None.') + self.avatar.held_item = value + self.assertEqual(str(e.exception), f'Avatar.held_item must be an Item or None. It is a(n) ' + f'{value.__class__.__name__} and has the value of ' + f'{value}') # test set score def test_avatar_set_score(self): @@ -32,9 +34,11 @@ def test_avatar_set_score(self): self.assertEqual(self.avatar.score, 10) def test_avatar_set_score_fail(self): + value: str = 'wow' with self.assertRaises(ValueError) as e: - self.avatar.score = 'wow' - self.assertEqual(str(e.exception), 'Avatar.score must be an int.') + self.avatar.score = value + self.assertEqual(str(e.exception), f'Avatar.score must be an int. It is a(n) ' + f'{value.__class__.__name__} and has the value of {value}') # test set position def test_avatar_set_position(self): @@ -47,8 +51,9 @@ def test_avatar_set_position_None(self): def test_avatar_set_position_fail(self): with self.assertRaises(ValueError) as e: - self.avatar.position = 10 - self.assertEqual(str(e.exception), 'Avatar.position must be a Vector or None.') + self.avatar.position = value + self.assertEqual(str(e.exception), f'Avatar.position must be a Vector or None. ' + f'It is a(n) {value.__class__.__name__} and has the value of {value}') # test json method def test_avatar_json_with_none_item(self): diff --git a/game/test_suite/tests/test_avatar_inventory.py b/game/test_suite/tests/test_avatar_inventory.py index 79a0fec..35ef57a 100644 --- a/game/test_suite/tests/test_avatar_inventory.py +++ b/game/test_suite/tests/test_avatar_inventory.py @@ -24,24 +24,28 @@ def test_avatar_set_inventory(self): # fails if inventory is not a list def test_avatar_set_inventory_fail_1(self): + value: str = 'Fail' with self.assertRaises(ValueError) as e: - self.avatar.inventory = 'Fail' - self.assertEqual(str(e.exception), 'Avatar.inventory must be a list of Items.') + self.avatar.inventory = value + self.assertEqual(str(e.exception), f'Avatar.inventory must be a list of Items. It is a(n) {value.__class__.__name__} and has the value of {value}') # fails if inventory size is greater than the max_inventory_size def test_avatar_set_inventory_fail_2(self): + value: list = [Item(1,1), Item(4,2)] with self.assertRaises(ValueError) as e: - self.avatar.inventory = [Item(1, 1), Item(4, 2)] - self.assertEqual(str(e.exception), 'Avatar.inventory size must be less than or equal to max_inventory_size') + self.avatar.inventory = value + self.assertEqual(str(e.exception), 'Avatar.inventory size must be less than or equal to ' + f'max_inventory_size. It has the value of {len(value)}') def test_avatar_set_max_inventory_size(self): self.avatar.max_inventory_size = 10 self.assertEqual(str(self.avatar.max_inventory_size), str(10)) def test_avatar_set_max_inventory_size_fail(self): + value: str = 'Fail' with self.assertRaises(ValueError) as e: - self.avatar.max_inventory_size = 'Fail' - self.assertEqual(str(e.exception), 'Avatar.max_inventory_size must be an int.') + self.avatar.max_inventory_size = value + self.assertEqual(str(e.exception), f'Avatar.max_inventory_size must be an int. It is a(n) {value.__class__.__name__} and has the value of {value}') # Tests picking up an item def test_avatar_pick_up(self): @@ -114,9 +118,11 @@ def test_take_fail(self): self.avatar: Avatar = Avatar(None, 3) self.avatar.inventory = [Item(quantity=5, stack_size=5), Item(quantity=7, stack_size=7), Item(quantity=10, stack_size=10)] + value: str = 'wow' with self.assertRaises(ValueError) as e: - taken = self.avatar.take('') - self.assertEqual(str(e.exception), 'str is not of type Item.') + taken = self.avatar.take(value) + self.assertEqual(str(e.exception), f'str.item must be an item.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') # Tests picking up an item and failing def test_avatar_pick_up_full_inventory(self): diff --git a/game/test_suite/tests/test_game_board_no_gen.py b/game/test_suite/tests/test_game_board_no_gen.py index 754cb05..7d9d6cd 100644 --- a/game/test_suite/tests/test_game_board_no_gen.py +++ b/game/test_suite/tests/test_game_board_no_gen.py @@ -23,6 +23,7 @@ class TestGameBoard(unittest.TestCase): This class tests the different methods in the Avatar class. """ + def setUp(self) -> None: self.item: Item = Item(10, None) self.wall: Wall = Wall() @@ -41,9 +42,12 @@ def test_seed(self): self.assertEqual(self.game_board.seed, 2) def test_seed_fail(self): + value: str = 'False' with self.assertRaises(ValueError) as e: - self.game_board.seed = "False" - self.assertEqual(str(e.exception), 'GameBoard.seed must be an integer or None.') + self.game_board.seed = value + self.assertEqual(str(e.exception), + f'GameBoard.seed must be an int. ' + f'It is a(n) {value.__class__.__name__} with the value of {value}.') # test map_size def test_map_size(self): @@ -51,9 +55,12 @@ def test_map_size(self): self.assertEqual(str(self.game_board.map_size), str(Vector(12, 12))) def test_map_size_fail(self): + value: str = 'wow' with self.assertRaises(ValueError) as e: - self.game_board.map_size = "wow" - self.assertEqual(str(e.exception), 'GameBoard.map_size must be a Vector.') + self.game_board.map_size = value + self.assertEqual(str(e.exception), + f'GameBoard.map_size must be a Vector.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') # test locations def test_locations(self): @@ -67,10 +74,13 @@ def test_locations(self): self.assertEqual(str(self.game_board.locations), str(self.locations)) def test_locations_fail_type(self): + value: str = 'wow' with self.assertRaises(ValueError) as e: - self.game_board.locations = "wow" - self.assertEqual(str(e.exception), 'Locations must be a dict. The key must be a tuple of Vector Objects, ' - 'and the value a list of GameObject.') + self.game_board.locations = value + self.assertEqual(str(e.exception), + f'Locations must be a dict. The key must be a tuple of Vector Objects,' + f' and the value a list of GameObject. ' + f'It is a(n) {value.__class__.__name__} with the value of {value}.') # test walled def test_walled(self): @@ -78,9 +88,12 @@ def test_walled(self): self.assertEqual(self.game_board.walled, True) def test_walled_fail(self): + value: str = 'wow' with self.assertRaises(ValueError) as e: - self.game_board.walled = "wow" - self.assertEqual(str(e.exception), 'GameBoard.walled must be a bool.') + self.game_board.walled = value + self.assertEqual(str(e.exception), + f'GameBoard.walled must be a bool.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') # test json method def test_game_board_json(self): diff --git a/game/test_suite/tests/test_item.py b/game/test_suite/tests/test_item.py index ef9e4ce..3bd20f4 100644 --- a/game/test_suite/tests/test_item.py +++ b/game/test_suite/tests/test_item.py @@ -26,15 +26,20 @@ def test_set_durability_none(self): self.assertEqual(self.item.durability, None) def test_set_durability_fail(self): + value: str = 'fail' with self.assertRaises(ValueError) as e: - self.item.durability = 'fail' - self.assertEqual(str(e.exception), 'Item.durability must be an int or None.') + self.item.durability = value + self.assertEqual(str(e.exception), f'Item.durability must be an int. It is a(n) {value.__class__.__name__} with the value of {value}.') def test_set_durability_stack_size_fail(self): + value: list = Item(10,None,10,10) + value2: int = 10 with self.assertRaises(ValueError) as e: - self.item = Item(10, None, 10, 10) - self.item.durability = 19 - self.assertEqual(str(e.exception), 'Item.durability must be set to None if stack_size is not equal to 1.') + self.item = value + self.item.durability = value2 + self.assertEqual(str(e.exception), f'Item.durability must be set to None if stack_size is not equal to 1.' + f' {value.__class__.__name__}.' + f'durability has the value of {value2}.') # test set value def test_set_value(self): @@ -42,9 +47,11 @@ def test_set_value(self): self.assertEqual(self.item.value, 10) def test_set_value_fail(self): + value: str = 'fail' with self.assertRaises(ValueError) as e: - self.item.value = 'fail' - self.assertEqual(str(e.exception), 'Item.value must be an int.') + self.item.value = value + self.assertEqual(str(e.exception), f'Item.value must be an int.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') # test set quantity def test_set_quantity(self): @@ -53,36 +60,48 @@ def test_set_quantity(self): self.assertEqual(self.item.quantity, 5) def test_set_quantity_fail(self): + value: str = 'fail' with self.assertRaises(ValueError) as e: - self.item.quantity = 'fail' - self.assertEqual(str(e.exception), 'Item.quantity must be an int.') + self.item.quantity = value + self.assertEqual(str(e.exception), f'Item.quantity must be an int.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') def test_set_quantity_fail_greater_than_0(self): + value: Item = -1 with self.assertRaises(ValueError) as e: - self.item.quantity = -1 - self.assertEqual(str(e.exception), 'Item.quantity must be greater than or equal to 0.') + self.item.quantity = value + self.assertEqual(str(e.exception), f'Item.quantity must be greater than or ' + f'equal to 0. {value.__class__.__name__}.quantity ' + f'has the value of {value}.') def test_set_quantity_fail_stack_size(self): + value: Item = 10 + value2: Item = 1 with self.assertRaises(ValueError) as e: - self.item.quantity = 10 - self.item.stack_size = 1 - self.assertEqual(str(e.exception), 'Item.quantity cannot be greater than Item.stack_size') + self.item.quantity = value + self.item.stack_size = value2 + self.assertEqual(str(e.exception), f'Item.quantity cannot be greater than ' + f'{value2.__class__.__name__}.stack_size. {value.__class__.__name__}.quantity has the value of {value}.') def test_stack_size(self): self.item = Item(10, None, 10, 10) self.assertEqual(self.item.quantity, 10) def test_stack_size_fail(self): + value: str = 'fail' with self.assertRaises(ValueError) as e: - self.item.stack_size = 'fail' - self.assertEqual(str(e.exception), 'Item.stack_size must be an int.') + self.item.stack_size = value + self.assertEqual(str(e.exception), f'Item.stack_size must be an int.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') def test_stack_size_fail_quantity(self): # value, durability, quantity, stack size + value: Item = 5 with self.assertRaises(ValueError) as e: item: Item = Item(10, None, 10, 10) - item.stack_size = 5 - self.assertEqual(str(e.exception), 'Item.stack_size must be greater than or equal to the quantity.') + item.stack_size = value + self.assertEqual(str(e.exception), f'Item.stack_size must be greater than or equal to the quantity.' + f' {value.__class__.__name__}.stack_size has the value of {value}.') def test_pick_up(self): # value, durability, quantity, stack size diff --git a/game/test_suite/tests/test_occupiable_station.py b/game/test_suite/tests/test_occupiable_station.py index 9e5a55e..c967e55 100644 --- a/game/test_suite/tests/test_occupiable_station.py +++ b/game/test_suite/tests/test_occupiable_station.py @@ -48,9 +48,12 @@ def test_item_occ(self): # test cannot add item to occupied_by def test_fail_item_occ(self): + value: Item = self.item with self.assertRaises(ValueError) as e: - self.occupiable_station.occupied_by = self.item - self.assertEqual(str(e.exception), 'OccupiableStation.occupied_by cannot be an Item.') + self.occupiable_station.occupied_by = value + self.assertEqual(str(e.exception), + f'OccupiableStation.occupied_by must be a GameObject.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') # test json method def test_occ_json(self): diff --git a/game/test_suite/tests/test_station.py b/game/test_suite/tests/test_station.py index e59b511..0a290da 100644 --- a/game/test_suite/tests/test_station.py +++ b/game/test_suite/tests/test_station.py @@ -38,9 +38,10 @@ def test_item_occ(self): # test adding something not an item def test_item_occ_fail(self): + value: str = 'wow' with self.assertRaises(ValueError) as e: - self.station.held_item = 'wow' - self.assertEqual(str(e.exception), 'Station.held_item must be an Item or None, not wow.') + self.station.held_item = value + self.assertEqual(str(e.exception), f'Station.held_item must be an Item or None, not {value}.') # test base take action method works def test_take_action(self): From 08ef01b1554f620fe9d42a6bcc9555310ccbe6c8 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 25 Nov 2023 23:42:05 -0600 Subject: [PATCH 08/10] Edited test files in occupiable_station.py, test_avatar.py, test_avatar_inventory.py, test_game_board_no_gen.py, test_item.py, test_occupiable_station.py, and test_station.py so that their error messages matched in both their main file and test file. Still need to fix OccupiableStation test_fail_item_occ, test_set_quantity_fail_greater_than_0, test_set_quantity_fail_stack_size, and test_stack_size_fail_quantity --- game/common/items/item.py | 29 ++++++++++++------ game/common/map/game_board.py | 29 ++++++++++++------ game/common/player.py | 10 +++--- game/test_suite/tests/test_player.py | 46 ++++++++++++++++++---------- 4 files changed, 74 insertions(+), 40 deletions(-) diff --git a/game/common/items/item.py b/game/common/items/item.py index a09716d..2fe4858 100644 --- a/game/common/items/item.py +++ b/game/common/items/item.py @@ -94,52 +94,60 @@ def stack_size(self) -> int: def durability(self, durability: int | None) -> None: if durability is not None and not isinstance(durability, int): raise ValueError( - f'{self.__class__.__name__}.durability must be an int. It is a(n) {type(durability)} with the value of {durability}.') + f'{self.__class__.__name__}.durability must be an int. It is a(n) {durability.__class__.__name__} with the value of {durability}.') if durability is not None and self.stack_size != 1: raise ValueError( - f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1. {self.__class__.__name__}.durability has the value of {durability}.') + f'{self.__class__.__name__}.durability must be set to None if stack_size is not equal to 1.' + f' {self.__class__.__name__}.durability has the value of {durability}.') self.__durability = durability @value.setter def value(self, value: int) -> None: if value is None or not isinstance(value, int): raise ValueError( - f'{self.__class__.__name__}.value must be an int. It is a(n) {type(value)} with the value of {value}.') + f'{self.__class__.__name__}.value must be an int.' + f' It is a(n) {value.__class__.__name__} with the value of {value}.') self.__value: int = value @quantity.setter def quantity(self, quantity: int) -> None: if quantity is None or not isinstance(quantity, int): raise ValueError( - f'{self.__class__.__name__}.quantity must be an int. It is a(n) {type(quantity)} with the value of {quantity}.') + f'{self.__class__.__name__}.quantity must be an int.' + f' It is a(n) {quantity.__class__.__name__} with the value of {quantity}.') if quantity < 0: raise ValueError( - f'{self.__class__.__name__}.quantity must be greater than or equal to 0. {self.__class__.__name__}.quantity has the value of {quantity}.') + f'{self.__class__.__name__}.quantity must be greater than or equal to 0.' + f' {self.__class__.__name__}.quantity has the value of {quantity}.') # The self.quantity is set to the lower value between stack_size and the given quantity # The remaining given quantity is returned if it's larger than self.quantity if quantity > self.stack_size: raise ValueError(f'{self.__class__.__name__}.quantity cannot be greater than ' - f'{self.__class__.__name__}.stack_size. {self.__class__.__name__}.quantity has the value of {quantity}.') + f'{self.__class__.__name__}.stack_size.' + f' {self.__class__.__name__}.quantity has the value of {quantity}.') self.__quantity: int = quantity @stack_size.setter def stack_size(self, stack_size: int) -> None: if stack_size is None or not isinstance(stack_size, int): raise ValueError( - f'{self.__class__.__name__}.stack_size must be an int. It is a(n) {type(stack_size)} with the value of {stack_size}.') + f'{self.__class__.__name__}.stack_size must be an int.' + f' It is a(n) {stack_size.__class__.__name__} with the value of {stack_size}.') if self.durability is not None and stack_size != 1: raise ValueError(f'{self.__class__.__name__}.stack_size must be 1 if {self.__class__.__name__}.durability ' f'is not None. {self.__class__.__name__}.stack_size has the value of {stack_size}.') if self.__quantity is not None and stack_size < self.__quantity: raise ValueError( - f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity. {self.__class__.__name__}.stack_size has the value of {stack_size}.') + f'{self.__class__.__name__}.stack_size must be greater than or equal to the quantity.' + f' {self.__class__.__name__}.stack_size has the value of {stack_size}.') self.__stack_size: int = stack_size def take(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): raise ValueError( - f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}.') + f'{item.__class__.__name__}.item must be an item.' + f' It is a(n) {item.__class__.__name__} with the value of {item}.') # If the item is None, just return None if item is None: @@ -164,7 +172,8 @@ def take(self, item: Self) -> Self | None: def pick_up(self, item: Self) -> Self | None: if item is not None and not isinstance(item, Item): raise ValueError( - f'{item.__class__.__name__}.item must be an item. It is a(n) {type(item)} with the value of {item}.') + f'{item.__class__.__name__}.item must be an item.' + f' It is a(n) {item.__class__.__name__} with the value of {item}.') # If the item is None, just return None if item is None: diff --git a/game/common/map/game_board.py b/game/common/map/game_board.py index b122072..60ad2af 100644 --- a/game/common/map/game_board.py +++ b/game/common/map/game_board.py @@ -137,7 +137,8 @@ def seed(self, seed: int | None) -> None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if seed is not None and not isinstance(seed, int): raise ValueError( - f'{self.__class__.__name__}.seed must be an int. It is a(n) {type(seed)} with the value of {seed}.') + f'{self.__class__.__name__}.seed must be an int. ' + f'It is a(n) {seed.__class__.__name__} with the value of {seed}.') self.__seed = seed @property @@ -151,7 +152,8 @@ def game_map(self, game_map: list[list[Tile]]) -> None: any([any(map(lambda g: not isinstance(g, Tile), tile_list)) for tile_list in game_map])): raise ValueError( - f'{self.__class__.__name__}.game_map must be a list[list[Tile]]. It is a(n) {type(game_map)} with the value of {game_map}.') + f'{self.__class__.__name__}.game_map must be a list[list[Tile]]. ' + f'It is a(n) {game_map.__class__.__name__} with the value of {game_map}.') self.__game_map = game_map @property @@ -164,7 +166,8 @@ def map_size(self, map_size: Vector) -> None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if map_size is None or not isinstance(map_size, Vector): raise ValueError( - f'{self.__class__.__name__}.map_size must be a Vector. It is a(n) {type(map_size)} with the value of {map_size}.') + f'{self.__class__.__name__}.map_size must be a Vector. ' + f'It is a(n) {map_size.__class__.__name__} with the value of {map_size}.') self.__map_size = map_size @property @@ -177,7 +180,9 @@ def locations(self, locations: dict[tuple[Vector]:list[GameObject]] | None) -> N raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if locations is not None and not isinstance(locations, dict): raise ValueError( - f'Locations must be a dict. The key must be a tuple of Vector Objects, and the value a list of GameObject. It is a(n) {type(locations)} with the value of {locations}.') + f'Locations must be a dict. The key must be a tuple of Vector Objects, ' + f'and the value a list of GameObject. ' + f'It is a(n) {locations.__class__.__name__} with the value of {locations}.') self.__locations = locations @@ -191,7 +196,8 @@ def walled(self, walled: bool) -> None: raise RuntimeError(f'{self.__class__.__name__} variables cannot be changed once generate_map is run.') if walled is None or not isinstance(walled, bool): raise ValueError( - f'{self.__class__.__name__}.walled must be a bool. It is a(n) {type(walled)} with the value of {walled}.') + f'{self.__class__.__name__}.walled must be a bool. ' + f'It is a(n) {walled.__class__.__name__} with the value of {walled}.') self.__walled = walled @@ -213,7 +219,8 @@ def __populate_map(self) -> None: for k, v in self.locations.items(): if len(k) == 0 or len(v) == 0: # Key-Value lengths must be > 0 and equal raise ValueError( - f'A key-value pair from game_board.locations has a length of 0. The length of the keys is {len(k)} and the length of the values is {len(v)}.') + f'A key-value pair from game_board.locations has a length of 0. ' + f'The length of the keys is {len(k)} and the length of the values is {len(v)}.') # random.sample returns a randomized list which is used in __help_populate() j = random.sample(k, k=len(k)) @@ -254,7 +261,8 @@ def __help_populate(self, vector_list: list[Vector], game_object_list: list[Game if temp_tile.occupied_by is not None: raise ValueError( - f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute. It is a(n) {type(temp_tile.occupied_by)}.') + f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute. ' + f'It is a(n) {temp_tile.occupied_by.__class__.__name__} with the value of {temp_tile.occupied_by}.') temp_tile.occupied_by = game_object @@ -269,7 +277,9 @@ def __help_populate(self, vector_list: list[Vector], game_object_list: list[Game for game_object in remaining_objects: if not hasattr(temp_tile, 'occupied_by') or temp_tile.occupied_by is not None: - raise ValueError(f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute. It is a(n) {type(temp_tile.occupied_by)}.') + raise ValueError( + f'Last item on the given tile doesn\'t have the \'occupied_by\' attribute.' + f' It is a(n) {temp_tile.occupied_by.__class__.__name__} with the value of {temp_tile.occupied_by}.') temp_tile.occupied_by = game_object temp_tile = temp_tile.occupied_by @@ -328,7 +338,8 @@ def __from_json_helper(self, data: dict) -> GameObject: return Avatar().from_json(data) # If adding more ObjectTypes that can be placed on the game_board, specify here case _: - raise ValueError(f'The object type of the object is not handled properly. The object type passed in is {temp}.') + raise ValueError( + f'The object type of the object is not handled properly. The object type passed in is {temp}.') def from_json(self, data: dict) -> Self: super().from_json(data) diff --git a/game/common/player.py b/game/common/player.py index ba3ff45..a5df4b4 100644 --- a/game/common/player.py +++ b/game/common/player.py @@ -41,7 +41,7 @@ def actions(self, actions: list[ActionType] | list) -> None: # showing it retur or (len(actions) > 0 and any(map(lambda action_type: not isinstance(action_type, ActionType), actions))): raise ValueError( - f'{self.__class__.__name__}.action must be an empty list or a list of action types. It is a(n) {type(actions)} and has the value of {actions}.') + f'{self.__class__.__name__}.action must be an empty list or a list of action types. It is a(n) {actions.__class__.__name__} and has the value of {actions}.') # ^if it's not either throw an error self.__actions = actions @@ -53,7 +53,7 @@ def functional(self) -> bool: def functional(self, functional: bool) -> None: # this enforces the type hinting if functional is None or not isinstance(functional, bool): # if this statement is true throw an error raise ValueError( - f'{self.__class__.__name__}.functional must be a boolean. It is a(n) {type(functional)} and has the value of {functional}.') + f'{self.__class__.__name__}.functional must be a boolean. It is a(n) {functional.__class__.__name__} and has the value of {functional}.') self.__functional = functional @property @@ -64,7 +64,7 @@ def team_name(self) -> str: def team_name(self, team_name: str) -> None: if team_name is not None and not isinstance(team_name, str): raise ValueError( - f'{self.__class__.__name__}.team_name must be a String or None. It is a(n) {type(team_name)} and has the value of {team_name}.') + f'{self.__class__.__name__}.team_name must be a String or None. It is a(n) {team_name.__class__.__name__} and has the value of {team_name}.') self.__team_name = team_name @property @@ -75,7 +75,7 @@ def avatar(self) -> Avatar: def avatar(self, avatar: Avatar) -> None: if avatar is not None and not isinstance(avatar, Avatar): raise ValueError( - f'{self.__class__.__name__}.avatar must be Avatar or None. It is a(n) {type(avatar)} and has the value of {avatar}.') + f'{self.__class__.__name__}.avatar must be Avatar or None. It is a(n) {avatar.__class__.__name__} and has the value of {avatar}.') self.__avatar = avatar @property @@ -86,7 +86,7 @@ def object_type(self) -> ObjectType: def object_type(self, object_type: ObjectType) -> None: if object_type is None or not isinstance(object_type, ObjectType): raise ValueError( - f'{self.__class__.__name__}.object_type must be ObjectType. It is a(n) {type(object_type)} and has the value of {object_type}.') + f'{self.__class__.__name__}.object_type must be ObjectType. It is a(n) {object_type.__class__.__name__} and has the value of {object_type}.') self.__object_type = object_type def to_json(self): diff --git a/game/test_suite/tests/test_player.py b/game/test_suite/tests/test_player.py index 389a352..b98c1f9 100644 --- a/game/test_suite/tests/test_player.py +++ b/game/test_suite/tests/test_player.py @@ -35,14 +35,21 @@ def test_actions_empty_list(self): self.assertEqual(self.player.actions, self.actions) def test_actions_fail_none(self): + value: list = None with self.assertRaises(ValueError) as e: - self.player.actions = None - self.assertEqual(str(e.exception), 'Player.action must be an empty list or a list of action types') + self.player.actions = value + self.assertEqual(str(e.exception), f'Player.action must be an empty list or a list ' + f'of action types.' + f' It is a(n) {value.__class__.__name__} and has the value of {value}.') - def test_actions_fail_not_action_type(self): - with self.assertRaises(ValueError) as e: - self.player.actions = 10 - self.assertEqual(str(e.exception), 'Player.action must be an empty list or a list of action types') + def test_actions_fail_not_action_type(self): + value: int = 10 + with self.assertRaises(ValueError) as e: + self.player.actions = value + + self.assertEqual(str(e.exception), f'Player.action must be an empty list or a list ' + f'of action types.' + f' It is a(n) {value.__class__.__name__} and has the value of {value}.') # test functional def test_functional_true(self): @@ -58,9 +65,11 @@ def test_functional_false(self): self.assertEqual(self.player.functional, self.functional) def test_functional_fail_int(self): + value: str = 'Strig' with self.assertRaises(ValueError) as e: - self.player.functional = "Strig" - self.assertEqual(str(e.exception), 'Player.functional must be a boolean') + self.player.functional = value + self.assertEqual(str(e.exception), f'Player.functional must be a boolean.' + f' It is a(n) {value.__class__.__name__} and has the value of {value}.') # team name def test_team_name(self): @@ -76,9 +85,11 @@ def test_team_name_none(self): def test_team_name_fail_int(self): # if it is not a string it fails + value: int = 1 with self.assertRaises(ValueError) as e: - self.player.team_name = 1 - self.assertEqual(str(e.exception), 'Player.team_name must be a String or None') + self.player.team_name = value + self.assertEqual(str(e.exception), f'Player.team_name must be a String or None.' + f' It is a(n) {value.__class__.__name__} and has the value of {value}.') # test avatar def test_avatar(self): @@ -91,9 +102,10 @@ def test_avatar_none(self): self.assertEqual(self.player.avatar, self.avatar) def test_avatar_fail_string(self): + value: int = 10 with self.assertRaises(ValueError) as e: - self.player.avatar = 10 - self.assertEqual(str(e.exception), 'Player.avatar must be Avatar or None') + self.player.avatar = value + self.assertEqual(str(e.exception), f'Player.avatar must be Avatar or None. It is a(n) {value.__class__.__name__} and has the value of {value}.') # test object type def test_object_type(self): @@ -103,14 +115,16 @@ def test_object_type(self): self.assertEqual(self.player.object_type, self.object_type) def test_object_type_fail_none(self): + value: ObjectType = None with self.assertRaises(ValueError) as e: - self.player.object_type = None - self.assertEqual(str(e.exception), 'Player.object_type must be ObjectType') + self.player.object_type = value + self.assertEqual(str(e.exception), f'Player.object_type must be ObjectType. It is a(n) {value.__class__.__name__} and has the value of {value}.') def test_object_type_fail_int(self): + value: int = 10 with self.assertRaises(ValueError) as e: - self.player.object_type = 10 - self.assertEqual(str(e.exception), 'Player.object_type must be ObjectType') + self.player.object_type = value + self.assertEqual(str(e.exception), f'Player.object_type must be ObjectType. It is a(n) {value.__class__.__name__} and has the value of {value}.') # test to json def test_player_json(self): From 612c6db7fe31412921410f0e4169a4688a9f4da3 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sat, 25 Nov 2023 23:42:40 -0600 Subject: [PATCH 09/10] Changes by ianth --- game/common/avatar.py | 15 ++++++++++----- game/test_suite/tests/test_avatar.py | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/game/common/avatar.py b/game/common/avatar.py index dc32930..f888a46 100644 --- a/game/common/avatar.py +++ b/game/common/avatar.py @@ -182,7 +182,8 @@ def held_item(self, item: Item | None) -> None: # If it's not an item, and it's not None, raise the error if item is not None and not isinstance(item, Item): raise ValueError( - f'{self.__class__.__name__}.held_item must be an Item or None. It is a(n) {type(item)} and has the value of {item}') + f'{self.__class__.__name__}.held_item must be an Item or None. It is a(n) ' + f'{item.__class__.__name__} and has the value of {item}') # If the item is not contained in the inventory, the error will be raised. if not self.inventory.__contains__(item): @@ -196,14 +197,16 @@ def held_item(self, item: Item | None) -> None: def score(self, score: int) -> None: if score is None or not isinstance(score, int): raise ValueError( - f'{self.__class__.__name__}.score must be an int. It is a(n) {type(score)} and has the value of {score}') + f'{self.__class__.__name__}.score must be an int. It is a(n) {score.__class__.__name__} and has the value of ' + f'{score}') self.__score: int = score @position.setter def position(self, position: Vector | None) -> None: if position is not None and not isinstance(position, Vector): raise ValueError( - f'{self.__class__.__name__}.position must be a Vector or None. It is a(n) {type(position)} and has the value of {position}') + f'{self.__class__.__name__}.position must be a Vector or None. It is a(n) ' + f'{position.__class__.__name__} and has the value of {position}') self.__position: Vector | None = position @inventory.setter @@ -213,7 +216,8 @@ def inventory(self, inventory: list[Item | None]) -> None: or (len(inventory) > 0 and any(map(lambda item: item is not None and not isinstance(item, Item), inventory))): raise ValueError( - f'{self.__class__.__name__}.inventory must be a list of Items. It is a(n) {type(inventory)} and has the value of {inventory}') + f'{self.__class__.__name__}.inventory must be a list of Items. It is a(n) {inventory.__class__.__name__} ' + f'and has the value of {inventory}') if len(inventory) > self.max_inventory_size: raise ValueError(f'{self.__class__.__name__}.inventory size must be less than or equal to ' f'max_inventory_size. It has the value of {len(inventory)}') @@ -222,7 +226,8 @@ def inventory(self, inventory: list[Item | None]) -> None: @max_inventory_size.setter def max_inventory_size(self, size: int) -> None: if size is None or not isinstance(size, int): - raise ValueError(f'{self.__class__.__name__}.max_inventory_size must be an int. It is a(n) {type(size)} and has the value of {size}') + raise ValueError(f'{self.__class__.__name__}.max_inventory_size must be an int. It is a(n) {size.__class__.__name__} ' + f'and has the value of {size}') self.__max_inventory_size: int = size # Private helper method that cleans the inventory of items that have a quantity of 0. This is a safety check diff --git a/game/test_suite/tests/test_avatar.py b/game/test_suite/tests/test_avatar.py index 6446ee2..53692a0 100644 --- a/game/test_suite/tests/test_avatar.py +++ b/game/test_suite/tests/test_avatar.py @@ -22,6 +22,7 @@ def test_avatar_set_item(self): self.assertEqual(self.avatar.held_item, self.item) def test_avatar_set_item_fail(self): + value: int = 3 with self.assertRaises(ValueError) as e: self.avatar.held_item = value self.assertEqual(str(e.exception), f'Avatar.held_item must be an Item or None. It is a(n) ' @@ -50,6 +51,7 @@ def test_avatar_set_position_None(self): self.assertEqual(self.avatar.position, None) def test_avatar_set_position_fail(self): + value: int = 10 with self.assertRaises(ValueError) as e: self.avatar.position = value self.assertEqual(str(e.exception), f'Avatar.position must be a Vector or None. ' From 1869a3e323334d2dd860714037d33476a30b9dc8 Mon Sep 17 00:00:00 2001 From: CaitlinAzazel Date: Sun, 26 Nov 2023 16:40:41 -0600 Subject: [PATCH 10/10] fixed tests that were failing. --- game/common/map/occupiable.py | 4 ++-- game/common/stations/occupiable_station.py | 2 +- game/test_suite/tests/test_item.py | 6 +++--- game/test_suite/tests/test_occupiable_station.py | 7 +++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/game/common/map/occupiable.py b/game/common/map/occupiable.py index d6941ac..e41d405 100644 --- a/game/common/map/occupiable.py +++ b/game/common/map/occupiable.py @@ -29,10 +29,10 @@ def occupied_by(self) -> GameObject | None: def occupied_by(self, occupied_by: GameObject | None) -> None: if occupied_by is not None and isinstance(occupied_by, Item): raise ValueError( - f'{self.__class__.__name__}.occupied_by must be a GameObject. It is a(n) {type(occupied_by)} with the value of {occupied_by}') + f'{self.__class__.__name__}.occupied_by must be a GameObject. It is a(n) {occupied_by.__class__.__name__} with the value of {occupied_by}.') if occupied_by is not None and not isinstance(occupied_by, GameObject): raise ValueError( - f'{self.__class__.__name__}.occupied_by must be None or an instance of GameObject. It is a(n) {type(occupied_by)} with the value of {occupied_by}') + f'{self.__class__.__name__}.occupied_by must be None or an instance of GameObject. It is a(n) {occupied_by.__class__.__name__} with the value of {occupied_by}.') self.__occupied_by = occupied_by def to_json(self) -> dict: diff --git a/game/common/stations/occupiable_station.py b/game/common/stations/occupiable_station.py index c457523..42c6e54 100644 --- a/game/common/stations/occupiable_station.py +++ b/game/common/stations/occupiable_station.py @@ -43,5 +43,5 @@ def from_json(self, data: dict) -> Self: self.occupied_by: Station = Station().from_json(occupied_by) case _: raise ValueError(f'{self.__class__.__name__}.occupied_by must be a GameObject.' - f' It is a(n) {occupied_by.__class__.__name__} with the value of {occupied_by}') + f' It is a(n) {self.occupied_by.__class__.__name__} with the value of {occupied_by}') return self diff --git a/game/test_suite/tests/test_item.py b/game/test_suite/tests/test_item.py index 3bd20f4..659bdd3 100644 --- a/game/test_suite/tests/test_item.py +++ b/game/test_suite/tests/test_item.py @@ -71,7 +71,7 @@ def test_set_quantity_fail_greater_than_0(self): with self.assertRaises(ValueError) as e: self.item.quantity = value self.assertEqual(str(e.exception), f'Item.quantity must be greater than or ' - f'equal to 0. {value.__class__.__name__}.quantity ' + f'equal to 0. {self.item.__class__.__name__}.quantity ' f'has the value of {value}.') def test_set_quantity_fail_stack_size(self): @@ -81,7 +81,7 @@ def test_set_quantity_fail_stack_size(self): self.item.quantity = value self.item.stack_size = value2 self.assertEqual(str(e.exception), f'Item.quantity cannot be greater than ' - f'{value2.__class__.__name__}.stack_size. {value.__class__.__name__}.quantity has the value of {value}.') + f'{self.item.__class__.__name__}.stack_size. {self.item.__class__.__name__}.quantity has the value of {value}.') def test_stack_size(self): self.item = Item(10, None, 10, 10) @@ -101,7 +101,7 @@ def test_stack_size_fail_quantity(self): item: Item = Item(10, None, 10, 10) item.stack_size = value self.assertEqual(str(e.exception), f'Item.stack_size must be greater than or equal to the quantity.' - f' {value.__class__.__name__}.stack_size has the value of {value}.') + f' {self.item.__class__.__name__}.stack_size has the value of {value}.') def test_pick_up(self): # value, durability, quantity, stack size diff --git a/game/test_suite/tests/test_occupiable_station.py b/game/test_suite/tests/test_occupiable_station.py index c967e55..ecf22b0 100644 --- a/game/test_suite/tests/test_occupiable_station.py +++ b/game/test_suite/tests/test_occupiable_station.py @@ -48,12 +48,11 @@ def test_item_occ(self): # test cannot add item to occupied_by def test_fail_item_occ(self): - value: Item = self.item with self.assertRaises(ValueError) as e: - self.occupiable_station.occupied_by = value + self.occupiable_station.occupied_by = self.item self.assertEqual(str(e.exception), - f'OccupiableStation.occupied_by must be a GameObject.' - f' It is a(n) {value.__class__.__name__} with the value of {value}.') + f'{self.occupiable_station.__class__.__name__}.occupied_by must be a GameObject.' + f' It is a(n) {self.item.__class__.__name__} with the value of {self.item}.') # test json method def test_occ_json(self):