Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove assertEqual(s) #1628

Merged
merged 7 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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"
)
37 changes: 16 additions & 21 deletions aimmo-game-creator/tests/test_game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,45 @@ 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 str(i) in self.game_manager.final_games
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)
with HTTMock(mocker):
self.game_manager.update()
del mocker.value["1"]
self.game_manager.update()
self.assertNotIn(1, self.game_manager.final_games)
assert 1 not in self.game_manager.final_games

def test_added_games_given_correct_url(self):
mocker = RequestMock(3)
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()
self.assertTrue(isinstance(token, str))
self.assertLessEqual(len(token), TOKEN_MAX_LENGTH)
assert isinstance(token, str)
assert len(token) <= TOKEN_MAX_LENGTH

def test_adding_a_game_creates_game_allocation(self):
game_manager = KubernetesGameManager("http://test/*")
Expand Down
10 changes: 5 additions & 5 deletions aimmo-game-creator/tests/test_kube_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_secret_is_loaded_and_data_is_added_correctly(self):
"""
Ensures the secret object is created correctly with the correct data filled in.
"""
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 is not None
assert self.secret.string_data is not None
assert self.secret.metadata.name == "game-1-token"
assert self.secret.metadata.namespace == "default"
assert self.secret.string_data["token"] == "TEST_TOKEN"
10 changes: 5 additions & 5 deletions aimmo-game/tests/test_simulation/test_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ 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)
cell2 = Cell(2)
self.assertNotEqual(cell1, cell2)
assert cell1 != cell2

def _create_full_cell(self):
cell = Cell(serializer("location"), False)
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
6 changes: 3 additions & 3 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 Expand Up @@ -40,4 +40,4 @@ def test_repr(self):
def test_incorrect_equality(self):
d1 = Direction(0, 1)
l1 = Location(0, 1)
self.assertFalse(d1 == l1)
assert d1 != l1
12 changes: 6 additions & 6 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 @@ -33,19 +33,19 @@ def test_effect_removed(self):
def test_effect_expires(self):
for _ in range(10):
self.effect.on_turn()
self.assertTrue(self.effect.is_expired)
assert self.effect.is_expired


class TestInvulnerabilityEffect(_BaseCases.BaseEffectTestCase):
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
17 changes: 7 additions & 10 deletions aimmo-game/tests/test_simulation/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,38 @@ class TestLocation(TestCase):
def test_equal(self):
loc_1 = Location(3, 3)
loc_2 = Location(3, 3)
self.assertEqual(loc_1, loc_2)
self.assertFalse(loc_1 != loc_2)
assert loc_1 == loc_2

def test_x_not_equal(self):
loc_1 = Location(3, 3)
loc_2 = Location(4, 3)
self.assertNotEqual(loc_1, loc_2)
self.assertFalse(loc_1 == loc_2)
assert loc_1 != loc_2

def test_y_not_equal(self):
loc_1 = Location(4, 4)
loc_2 = Location(4, 3)
self.assertNotEqual(loc_1, loc_2)
self.assertFalse(loc_1 == loc_2)
assert loc_1 != loc_2

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
30 changes: 15 additions & 15 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,22 +74,22 @@ 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)
self.assertGreaterEqual(c.location.x, -1)
self.assertGreaterEqual(c.location.y, -1)
assert c.location.x <= 1
assert c.location.y <= 2
assert c.location.x >= -1
assert c.location.y >= -1

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()
obstacle_cells = [cell for cell in m.all_cells() if not cell.habitable]
self.assertGreaterEqual(len(obstacle_cells), 1)
assert len(obstacle_cells) >= 1

def test_map_contains_some_habitable_cell_on_border(self):
m = self.get_map(START_WIDTH=4)
Expand All @@ -110,7 +110,7 @@ def test_map_contains_some_habitable_cell_on_border(self):
edge_cells = (m.get_cell_by_coords(x, y) for (x, y) in edge_coordinates)
habitable_edge_cells = [cell for cell in edge_cells if cell.habitable]

self.assertGreaterEqual(len(habitable_edge_cells), 1)
assert len(habitable_edge_cells) >= 1

def test_shortest_path(self):
m = self.get_map(START_WIDTH=4)
Loading