Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

fix: remove assertEqual(s) #1628

Merged
merged 7 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions aimmo-game-creator/tests/test_aimmo_game_creator_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_REPLACE_ME_string_exists(self):
"""
Ensures the yaml template contains the correct string to be replaced.
"""
self.assertEqual(
assert (
self.yaml_dict["spec"]["template"]["spec"]["containers"][0]["env"][1][
"value"
],
"REPLACE_ME",
]
== "REPLACE_ME"
)
29 changes: 12 additions & 17 deletions aimmo-game-creator/tests/test_game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,22 @@ def test_correct_url_requested(self):
mocker = RequestMock(0)
with HTTMock(mocker):
self.game_manager.update()
self.assertEqual(len(mocker.urls_requested), 1)
assert len(mocker.urls_requested) == 1
self.assertRegex(mocker.urls_requested[0], "http://test/*")

def test_games_added(self):
mocker = RequestMock(3)
with HTTMock(mocker):
self.game_manager.update()
self.assertEqual(len(self.game_manager.final_games), 3)
self.assertEqual(len(list(self.game_manager._data.get_games())), 3)
assert len(self.game_manager.final_games) == 3
assert len(list(self.game_manager._data.get_games())) == 3
for i in range(3):
self.assertIn(str(i), self.game_manager.final_games)
self.assertEqual(
self.game_manager.added_games[str(i)]["settings"],
{"test": i, "test2": "Settings {}".format(i)},
)
self.assertEqual(
self.game_manager.added_games[str(i)]["name"], "Game {}".format(i)
)
assert self.game_manager.added_games[str(i)]["settings"] == {
"test": i,
"test2": "Settings {}".format(i),
}
assert self.game_manager.added_games[str(i)]["name"] == "Game {}".format(i)

def test_remove_games(self):
mocker = RequestMock(3)
Expand All @@ -93,13 +91,10 @@ def test_added_games_given_correct_url(self):
with HTTMock(mocker):
self.game_manager.update()
for i in range(3):
self.assertEqual(
self.game_manager.added_games[str(i)]["GAME_API_URL"],
"http://test/{}/".format(i),
)
self.assertEqual(
self.game_manager.added_games[str(i)]["name"], "Game {}".format(i)
)
assert self.game_manager.added_games[str(i)][
"GAME_API_URL"
] == "http://test/{}/".format(i)
assert self.game_manager.added_games[str(i)]["name"] == "Game {}".format(i)

def test_token_generation(self):
token = self.game_manager._generate_game_token()
Expand Down
6 changes: 3 additions & 3 deletions aimmo-game-creator/tests/test_kube_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_secret_is_loaded_and_data_is_added_correctly(self):
"""
self.assertIsNotNone(self.secret.metadata)
self.assertIsNotNone(self.secret.string_data)
self.assertEqual(self.secret.metadata.name, "game-1-token")
self.assertEqual(self.secret.metadata.namespace, "default")
self.assertEqual(self.secret.string_data["token"], "TEST_TOKEN")
assert self.secret.metadata.name == "game-1-token"
assert self.secret.metadata.namespace == "default"
assert self.secret.string_data["token"] == "TEST_TOKEN"
8 changes: 4 additions & 4 deletions aimmo-game/tests/test_simulation/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCell(TestCase):
def test_equal(self):
cell1 = Cell(1)
cell2 = Cell(1)
self.assertEqual(cell1, cell2)
assert cell1 == cell2

def test_not_equal(self):
cell1 = Cell(1)
Expand All @@ -39,16 +39,16 @@ def _create_full_cell(self):

def test_serialize(self):
cell = self._create_full_cell()
self.assertEqual(cell.serialize(), self.expected)
assert cell.serialize() == self.expected

def test_serialize_no_avatar(self):
cell = self._create_full_cell()
cell.avatar = None
self.expected["avatar"] = None
self.assertEqual(cell.serialize(), self.expected)
assert cell.serialize() == self.expected

def test_serialize_no_pickup(self):
cell = self._create_full_cell()
cell.interactable = None
self.expected["interactable"] = None
self.assertEqual(cell.serialize(), self.expected)
assert cell.serialize() == self.expected
4 changes: 2 additions & 2 deletions aimmo-game/tests/test_simulation/test_direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class TestDirection(TestCase):
def test_good_data(self):
d = Direction(0, 1)
self.assertEqual(d.x, 0)
self.assertEqual(d.y, 1)
assert d.x == 0
assert d.y == 1

def test_high_x(self):
with self.assertRaises(ValueError):
Expand Down
10 changes: 5 additions & 5 deletions aimmo-game/tests/test_simulation/test_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
self.avatar.effects.add(self.effect)

def assertNoEffects(self):
self.assertEqual(len(list(self.avatar.effects)), 0)
assert len(list(self.avatar.effects)) == 0

def test_effect_removed(self):
self.effect.remove()
Expand All @@ -41,11 +41,11 @@ def make_effect(self, *args):
return effects.InvulnerabilityEffect(*args)

def test_resistance_increases(self):
self.assertEqual(self.avatar.resistance, 1000)
assert self.avatar.resistance == 1000

def test_resistance_decreases(self):
self.effect.remove()
self.assertEqual(self.avatar.resistance, 0)
assert self.avatar.resistance == 0

def test_resistance_cannot_be_removed_twice(self):
self.effect.remove()
Expand All @@ -57,11 +57,11 @@ def make_effect(self, *args):
return effects.DamageBoostEffect(*args)

def test_damage_increases(self):
self.assertEqual(self.avatar.attack_strength, 6)
assert self.avatar.attack_strength == 6

def test_damage_decreases(self):
self.effect.remove()
self.assertEqual(self.avatar.attack_strength, 1)
assert self.avatar.attack_strength == 1

def test_damage_cannot_be_removed_twice(self):
self.effect.remove()
Expand Down
10 changes: 5 additions & 5 deletions aimmo-game/tests/test_simulation/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestLocation(TestCase):
def test_equal(self):
loc_1 = Location(3, 3)
loc_2 = Location(3, 3)
self.assertEqual(loc_1, loc_2)
assert loc_1 == loc_2
self.assertFalse(loc_1 != loc_2)

def test_x_not_equal(self):
Expand All @@ -28,22 +28,22 @@ def test_add(self):
loc_1 = Location(1, 2)
loc_2 = Location(3, 4)
expected = Location(4, 6)
self.assertEqual(loc_1 + loc_2, expected)
assert loc_1 + loc_2 == expected

def test_sub(self):
loc_1 = Location(1, 2)
loc_2 = Location(3, 4)
expected = Location(-2, -2)
self.assertEqual(loc_1 - loc_2, expected)
assert loc_1 - loc_2 == expected

loc_2 = Location(0, 0)
expected = Location(1, 2)
self.assertEqual(loc_1 - loc_2, expected)
assert loc_1 - loc_2 == expected

def test_hash_equal(self):
loc_1 = Location(3, 3)
loc_2 = Location(3, 3)
self.assertEqual(hash(loc_1), hash(loc_2))
assert hash(loc_1) == hash(loc_2)

def test_location_raises_exception_with_floats(self):
self.assertRaises(TypeError, Location, 3.2, 3)
Expand Down
18 changes: 9 additions & 9 deletions aimmo-game/tests/test_simulation/test_map_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def randint(self, minimum, maximum):
class TestHelperFunctions(unittest.TestCase):
def test_get_random_edge_index(self):
map = WorldMap.generate_empty_map(3, 4, {})
self.assertEqual((0, -1), get_random_edge_index(map, rng=ConstantRng(0)))
self.assertEqual((1, -1), get_random_edge_index(map, rng=ConstantRng(1)))
self.assertEqual((0, 1), get_random_edge_index(map, rng=ConstantRng(2)))
self.assertEqual((1, 1), get_random_edge_index(map, rng=ConstantRng(3)))
self.assertEqual((-1, 0), get_random_edge_index(map, rng=ConstantRng(4)))
self.assertEqual((2, 0), get_random_edge_index(map, rng=ConstantRng(5)))
assert (0, -1) == get_random_edge_index(map, rng=ConstantRng(0)))
assert (1, -1) == get_random_edge_index(map, rng=ConstantRng(1)))
assert (0, 1) == get_random_edge_index(map, rng=ConstantRng(2)))
assert (1, 1) == get_random_edge_index(map, rng=ConstantRng(3)))
assert (-1, 0) == get_random_edge_index(map, rng=ConstantRng(4)))
assert (2, 0) == get_random_edge_index(map, rng=ConstantRng(5)))

# Verify no out of bounds
with self.assertRaisesRegex(ValueError, "Beyond range"):
Expand All @@ -46,7 +46,7 @@ def test_get_random_edge_index_can_give_all_possible(self):
actual = frozenset(
get_random_edge_index(map, rng=ConstantRng(i)) for i in range(6)
)
self.assertEqual(expected, actual)
assert expected == actual

def test_out_of_bounds_random_edge(self):
map = WorldMap.generate_empty_map(3, 4, {})
Expand Down Expand Up @@ -74,7 +74,7 @@ class TestMainGenerator(_BaseGeneratorTestCase):
def test_map_dimensions(self):
m = self.get_map()
grid = list(m.all_cells())
self.assertEqual(len(set(grid)), len(grid), "Repeats in list")
assert len(set(grid)) == len(grid), "Repeats in list"
for c in grid:
self.assertLessEqual(c.location.x, 1)
self.assertLessEqual(c.location.y, 2)
Expand All @@ -84,7 +84,7 @@ def test_map_dimensions(self):
def test_obstacle_ratio(self):
m = self.get_map(OBSTACLE_RATIO=0)
obstacle_cells = [cell for cell in m.all_cells() if not cell.habitable]
self.assertEqual(len(obstacle_cells), 0)
assert len(obstacle_cells) == 0

def test_map_contains_some_non_habitable_cell(self):
m = self.get_map()
Expand Down
36 changes: 17 additions & 19 deletions aimmo-game/tests/test_simulation/test_world_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@ def _grid_from_list(self, in_list):
def assertGridSize(self, world_map, expected_columns, expected_rows=None):
if expected_rows is None:
expected_rows = expected_columns
self.assertEqual(world_map.num_rows, expected_rows)
self.assertEqual(world_map.num_cols, expected_columns)
self.assertEqual(world_map.num_cells, expected_rows * expected_columns)
self.assertEqual(
len(list(world_map.all_cells())), expected_rows * expected_columns
)
assert world_map.num_rows == expected_rows
assert world_map.num_cols == expected_columns
assert world_map.num_cells == expected_rows * expected_columns
assert len(list(world_map.all_cells())) == expected_rows * expected_columns

def test_get_all_cells(self):
world_map = WorldMap(generate_grid(), self.settings)
cell_list = list(world_map.all_cells())

self.assertEqual(len(cell_list), 4)
assert len(cell_list) == 4
self.assertTrue(isinstance(cell_list[0], MockCell))

def test_get_all_interactables(self):
Expand All @@ -78,7 +76,7 @@ def test_get_all_interactables(self):
world_map = WorldMap(grid, self.settings)
interactable_list = list(world_map.interactable_cells())

self.assertEqual(len(interactable_list), 1)
assert len(interactable_list) == 1
self.assertTrue(isinstance(interactable_list[0].interactable, _Interactable))

def test_get_all_score_locations(self):
Expand All @@ -90,7 +88,7 @@ def test_get_all_score_locations(self):
world_map = WorldMap(grid, self.settings)
score_list = list(world_map.score_cells())

self.assertEqual(len(score_list), 1)
assert len(score_list) == 1
self.assertTrue(isinstance(score_list[0].interactable, ScoreLocation))

def test_get_all_pickup_locations(self):
Expand All @@ -102,7 +100,7 @@ def test_get_all_pickup_locations(self):
world_map = WorldMap(grid, self.settings)
pickup_list = list(world_map.pickup_cells())

self.assertEqual(len(pickup_list), 1)
assert len(pickup_list) == 1
self.assertTrue(isinstance(pickup_list[0].interactable, ALL_PICKUPS))

def test_grid_size(self):
Expand All @@ -120,7 +118,7 @@ def test_all_cells(self):
self.assertIn("B", cell_names)
self.assertIn("C", cell_names)
self.assertIn("D", cell_names)
self.assertEqual(len(cell_names), 4)
assert len(cell_names) == 4

def test_score_cells(self):
score_cell1 = MockCell()
Expand All @@ -135,7 +133,7 @@ def test_score_cells(self):
cells = list(world_map.score_cells())
self.assertIn(score_cell1, cells)
self.assertIn(score_cell2, cells)
self.assertEqual(len(cells), 2, "Non-scoring cells present")
assert len(cells) == 2, "Non-scoring cells present"

def test_potential_spawns(self):
spawnable1 = MockCell()
Expand All @@ -155,7 +153,7 @@ def test_potential_spawns(self):
self.assertNotIn(score_cell, cells, "Score cells should not be spawns")
self.assertNotIn(unhabitable, cells, "Unhabitable cells should not be spawns")
self.assertNotIn(filled, cells, "Cells with avatars should not be spawns")
self.assertEqual(len(cells), 2)
assert len(cells) == 2

def test_interactable_cells(self):
pickup_cell1 = MockCell(interactable=MockPickup())
Expand All @@ -168,7 +166,7 @@ def test_interactable_cells(self):
cells = list(world_map.interactable_cells())
self.assertIn(pickup_cell1, cells)
self.assertIn(pickup_cell2, cells)
self.assertEqual(len(cells), 2, "Non-pickup cells present")
assert len(cells) == 2, "Non-pickup cells present"

def test_location_on_map(self):
world_map = WorldMap(generate_grid(), self.settings)
Expand Down Expand Up @@ -196,7 +194,7 @@ def test_get_valid_cell(self):
for x in (0, 1):
for y in (0, 1):
location = Location(x, y)
self.assertEqual(world_map.get_cell(location).location, location)
assert world_map.get_cell(location).location == location

def test_get_x_off_map(self):
world_map = WorldMap(generate_grid(), self.settings)
Expand All @@ -217,7 +215,7 @@ def test_get_y_off_map(self):
def test_random_spawn_location_successful(self):
cell = MockCell()
world_map = WorldMap({Location(0, 0): cell}, self.settings)
self.assertEqual(world_map.get_random_spawn_location(), cell.location)
assert world_map.get_random_spawn_location() == cell.location

def test_random_spawn_location_with_no_candidates(self):
grid = generate_grid(1, 1)
Expand Down Expand Up @@ -272,7 +270,7 @@ def test_iter(self):
],
]
world_map = WorldMap(self._grid_from_list(grid), self.settings)
self.assertEqual([list(column) for column in world_map], grid)
assert [list(column) for column in world_map] == grid

def test_attackable_avatar_returns_none(self):
world_map = WorldMap(generate_grid(), self.settings)
Expand All @@ -284,7 +282,7 @@ def test_attackable_avatar_returns_avatar(self):
avatar = DummyAvatar()
world_map = AvatarMap(avatar)

self.assertEqual(world_map.attackable_avatar(Location(0, 0)), avatar)
assert world_map.attackable_avatar(Location(0, 0)) == avatar


class TestWorldMapWithOriginCentre(TestWorldMap):
Expand All @@ -308,4 +306,4 @@ class TestStaticSpawnDecorator(TestCase):
def test_spawn_is_static(self):
decorated_map = WorldMapStaticSpawnDecorator(WorldMap({}, {}), Location(3, 7))
for _ in range(5):
self.assertEqual(decorated_map.get_random_spawn_location(), Location(3, 7))
assert decorated_map.get_random_spawn_location() == Location(3, 7)
Loading