Skip to content

Commit

Permalink
Merge pull request #175 from szabopeter/fix-assertRaises-exception-us…
Browse files Browse the repository at this point in the history
…ages

Fix assertRaises exception usages
  • Loading branch information
arnauddupuis committed Oct 31, 2021
2 parents 4f2fb38 + d2f5bc3 commit 45f7b59
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
16 changes: 8 additions & 8 deletions tests/test_actuators.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ def test_pathfinder_bfs(self):
npc.actuator.actuated_object = None
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "actuated_object is not defined")
self.assertEqual(e.exception.error, "actuated_object is not defined")
npc.actuator.actuated_object = board_items.Door()
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "actuated_object not a Movable object")
self.assertEqual(e.exception.error, "actuated_object not a Movable object")
npc.actuator.actuated_object = board_items.Door()
npc.actuator.actuated_object = npc
npc.actuator.destination = None
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "destination is not defined")
self.assertEqual(e.exception.error, "destination is not defined")
b.place_item(board_items.Wall(), 2, 2)
npc.actuator.set_destination(2, 2)
self.assertEqual(npc.actuator.find_path(), [])
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_pathfinder_bfs(self):
npc.actuator.remove_waypoint("10", 10)
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.remove_waypoint(30, 30)
self.assertEqual(e.error, "invalid_waypoint")
self.assertEqual(e.exception.error, "invalid_waypoint")
self.assertIsNone(npc.actuator.remove_waypoint(10, 10))

def test_pathfinder_astar(self):
Expand Down Expand Up @@ -213,16 +213,16 @@ def test_pathfinder_astar(self):
npc.actuator.actuated_object = None
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "actuated_object is not defined")
self.assertEqual(e.exception.error, "actuated_object is not defined")
npc.actuator.actuated_object = board_items.Door()
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "actuated_object not a Movable object")
self.assertEqual(e.exception.error, "actuated_object not a Movable object")
npc.actuator.actuated_object = npc
npc.actuator.destination = None
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.find_path()
self.assertEqual(e.error, "destination is not defined")
self.assertEqual(e.exception.error, "destination is not defined")
b.place_item(board_items.Wall(), 2, 2)
npc.actuator.set_destination(2, 2)
self.assertEqual(npc.actuator.find_path(), [])
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_pathfinder_astar(self):
npc.actuator.remove_waypoint("10", 10)
with self.assertRaises(engine.base.PglException) as e:
npc.actuator.remove_waypoint(30, 30)
self.assertEqual(e.error, "invalid_waypoint")
self.assertEqual(e.exception.error, "invalid_waypoint")
self.assertIsNone(npc.actuator.remove_waypoint(10, 10))

def test_pathfinder_serialization(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_item(self):
j.store_position(2, 2)
with self.assertRaises(pgl_base.PglException) as e:
self.board.remove_item(j)
self.assertEqual(e.error, "invalid_item")
self.assertEqual(e.exception.error, "invalid_item")
self.assertTrue(self.board.remove_item(i))
b = pgl_engine.Board()
i = pgl_board_items.ComplexNPC(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_boardItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_movable(self):
def test_projectile(self):
with self.assertRaises(board_items.base.PglException) as e:
board_items.Projectile(range=6, step=4)
self.assertEqual(e.error, "incorrect_range_step")
self.assertEqual(e.exception.error, "incorrect_range_step")
p = board_items.Projectile()
self.assertFalse(p.has_inventory())
self.assertTrue(p.overlappable())
Expand Down
4 changes: 2 additions & 2 deletions tests/test_engine_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def test_search_get_delete(self):
self.assertEqual(self.inv.get_item("test").name, "test")
with self.assertRaises(engine.base.PglInventoryException) as e:
self.inv.get_item("crash")
self.assertEqual(e.error, "no_item_by_that_name")
self.assertEqual(e.exception.error, "no_item_by_that_name")
self.assertIsNone(self.inv.delete_item("test"))
with self.assertRaises(engine.base.PglInventoryException) as e:
self.inv.delete_item("test")
self.assertEqual(e.error, "no_item_by_that_name")
self.assertEqual(e.exception.error, "no_item_by_that_name")

def test_str(self):
self.inv.empty()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_menu(self):
)
with self.assertRaises(base.PglException) as e:
game.display_menu("main_menu_bork")
self.assertEqual(e.error, "invalid_menu_category")
self.assertEqual(e.exception.error, "invalid_menu_category")
self.assertIsNone(game.clear_screen())

def test_config(self):
Expand All @@ -77,7 +77,7 @@ def test_config(self):
g.save_config("high_scores", None)
with self.assertRaises(base.PglException) as e:
g.save_config("Unknown", "test-pygamelib.engine.Game.config.json")
self.assertEqual(e.error, "unknown section")
self.assertEqual(e.exception.error, "unknown section")
# Don't do that...
g._configuration = None
g._configuration_internals = None
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_board_management(self):
g.current_board()
with self.assertRaises(base.PglException) as e:
g.change_level(1)
self.assertEqual(e.error, "undefined_player")
self.assertEqual(e.exception.error, "undefined_player")
g.player = board_items.Player()
self.assertIsNone(g.change_level(1))
self.assertIsNone(g.add_board(2, engine.Board()))
Expand Down
14 changes: 7 additions & 7 deletions tests/test_gfx_core_sprite.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ def test_sprite_create_empty(self):
spr.sprixel(1, "crash")
with self.assertRaises(gfx_core.base.PglException) as e:
spr.sprixel(1, 10)
self.assertEqual(e.error, "out_of_sprite_boundaries")
self.assertEqual(e.exception.error, "out_of_sprite_boundaries")
self.assertTrue(type(spr.sprixel(1)) is list)
with self.assertRaises(gfx_core.base.PglException) as e:
spr.sprixel(10, 1)
self.assertEqual(e.error, "out_of_sprite_boundaries")
self.assertEqual(e.exception.error, "out_of_sprite_boundaries")
with self.assertRaises(gfx_core.base.PglInvalidTypeException):
spr.set_sprixel(1, "crash", "bork")
with self.assertRaises(gfx_core.base.PglException) as e:
spr.set_sprixel(1, 10, "bork")
self.assertEqual(e.error, "out_of_sprite_boundaries")
self.assertEqual(e.exception.error, "out_of_sprite_boundaries")
with self.assertRaises(gfx_core.base.PglInvalidTypeException):
spr.set_sprixel(1, 1, "bork")

Expand Down Expand Up @@ -132,7 +132,7 @@ def test_sprite_empty(self):
def test_load(self):
with self.assertRaises(gfx_core.base.PglException) as e:
gfx_core.Sprite.load_from_ansi_file("tests/house-red-borked.ans")
self.assertEqual(e.error, "sprite_file_format_not_supported")
self.assertEqual(e.exception.error, "sprite_file_format_not_supported")
spr = gfx_core.Sprite.load_from_ansi_file("tests/house-red-double.ans")
self.assertEqual(spr.width, 17)
gfx_core.Sprite.load_from_ansi_file("tests/house-red.ans")
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_load(self):
],
}
)
self.assertEqual(e.error, "invalid_sprite_size")
self.assertEqual(e.exception.error, "invalid_sprite_size")

def test_collection(self):
spr = gfx_core.Sprite(
Expand Down Expand Up @@ -218,10 +218,10 @@ def test_collection(self):
self.assertEqual(spr3.sprixel(1, 1), sc2.get(spr3.name).sprixel(1, 1))
with self.assertRaises(gfx_core.base.PglException) as e:
gfx_core.SpriteCollection.load({})
self.assertEqual(e.error, "invalid_sprite_data")
self.assertEqual(e.exception.error, "invalid_sprite_data")
with self.assertRaises(gfx_core.base.PglException) as e:
gfx_core.SpriteCollection.load({"sprites_count": 2, "sprites": {}})
self.assertEqual(e.error, "corrupted_sprite_data")
self.assertEqual(e.exception.error, "corrupted_sprite_data")

def test_scale(self):
spr = gfx_core.Sprite(
Expand Down

0 comments on commit 45f7b59

Please sign in to comment.