Skip to content

Commit ea4dead

Browse files
committed
Fix types for test folder
1 parent e4f7670 commit ea4dead

16 files changed

+121
-105
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ allow_split_before_dict_value = false
9696
project_includes = [
9797
"sc2",
9898
"examples",
99-
# "test"
99+
"test"
100100
]
101101
project-excludes = [
102102
# Disable for those files and folders

test/autotest_bot.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ async def test_botai_actions4(self):
216216
async def test_botai_actions5(self):
217217
# Test BotAI action: self.expand_now() which tests for get_next_expansion, select_build_worker, can_place, find_placement, build and can_afford
218218
# Wait till worker has started construction of CC
219-
while 1:
219+
while True:
220220
if self.can_afford(UnitTypeId.COMMANDCENTER):
221221
await self.get_next_expansion()
222222
await self.expand_now()
@@ -241,9 +241,9 @@ async def test_botai_actions6(self):
241241
# Test if reaper grenade shows up in effects
242242
center = self.game_info.map_center
243243

244-
while 1:
244+
while True:
245245
if self.units(UnitTypeId.REAPER).amount < 10:
246-
await self.client.debug_create_unit([[UnitTypeId.REAPER, 10, center, 1]])
246+
await self.client.debug_create_unit([(UnitTypeId.REAPER, 10, center, 1)])
247247

248248
for reaper in self.units(UnitTypeId.REAPER):
249249
reaper(AbilityId.KD8CHARGE_KD8CHARGE, center)
@@ -266,9 +266,9 @@ async def test_botai_actions6(self):
266266
async def test_botai_actions7(self):
267267
# Test ravager effects
268268
center = self.game_info.map_center
269-
while 1:
269+
while True:
270270
if self.units(UnitTypeId.RAVAGER).amount < 10:
271-
await self.client.debug_create_unit([[UnitTypeId.RAVAGER, 10, center, 1]])
271+
await self.client.debug_create_unit([(UnitTypeId.RAVAGER, 10, center, 1)])
272272
for ravager in self.units(UnitTypeId.RAVAGER):
273273
ravager(AbilityId.EFFECT_CORROSIVEBILE, center)
274274

@@ -291,15 +291,15 @@ async def test_botai_actions8(self):
291291
# Test if train function works on hatchery, lair, hive
292292
center = self.game_info.map_center
293293
if not self.structures(UnitTypeId.HIVE):
294-
await self.client.debug_create_unit([[UnitTypeId.HIVE, 1, center, 1]])
294+
await self.client.debug_create_unit([(UnitTypeId.HIVE, 1, center, 1)])
295295
if not self.structures(UnitTypeId.LAIR):
296-
await self.client.debug_create_unit([[UnitTypeId.LAIR, 1, center, 1]])
296+
await self.client.debug_create_unit([(UnitTypeId.LAIR, 1, center, 1)])
297297
if not self.structures(UnitTypeId.HATCHERY):
298-
await self.client.debug_create_unit([[UnitTypeId.HATCHERY, 1, center, 1]])
298+
await self.client.debug_create_unit([(UnitTypeId.HATCHERY, 1, center, 1)])
299299
if not self.structures(UnitTypeId.SPAWNINGPOOL):
300-
await self.client.debug_create_unit([[UnitTypeId.SPAWNINGPOOL, 1, center, 1]])
300+
await self.client.debug_create_unit([(UnitTypeId.SPAWNINGPOOL, 1, center, 1)])
301301

302-
while 1:
302+
while True:
303303
townhalls = self.structures.of_type({UnitTypeId.HIVE, UnitTypeId.LAIR, UnitTypeId.HATCHERY})
304304
if townhalls.amount == 3 and self.minerals >= 450 and not self.already_pending(UnitTypeId.QUEEN):
305305
self.train(UnitTypeId.QUEEN, amount=3)
@@ -324,14 +324,14 @@ async def test_botai_actions9(self):
324324
center = self.game_info.map_center
325325
await self.client.debug_create_unit(
326326
[
327-
[UnitTypeId.HIGHTEMPLAR, 1, center, 1],
328-
[UnitTypeId.DARKTEMPLAR, 1, center + Point2((5, 0)), 1],
327+
(UnitTypeId.HIGHTEMPLAR, 1, center, 1),
328+
(UnitTypeId.DARKTEMPLAR, 1, center + Point2((5, 0)), 1),
329329
]
330330
)
331331
await self._advance_steps(4)
332332
assert self.already_pending(UnitTypeId.ARCHON) == 0
333333

334-
while 1:
334+
while True:
335335
for templar in self.units.of_type({UnitTypeId.HIGHTEMPLAR, UnitTypeId.DARKTEMPLAR}):
336336
templar(AbilityId.MORPH_ARCHON)
337337

@@ -365,7 +365,7 @@ async def test_botai_actions10(self):
365365
center = self.game_info.map_center
366366

367367
target_amount = 400
368-
while 1:
368+
while True:
369369
bane_nests = self.structures(UnitTypeId.BANELINGNEST)
370370
lings = self.units(UnitTypeId.ZERGLING)
371371
banes = self.units(UnitTypeId.BANELING)
@@ -377,10 +377,10 @@ async def test_botai_actions10(self):
377377

378378
# Spawn units
379379
if not bane_nests:
380-
await self.client.debug_create_unit([[UnitTypeId.BANELINGNEST, 1, center, 1]])
380+
await self.client.debug_create_unit([(UnitTypeId.BANELINGNEST, 1, center, 1)])
381381
current_amount = banes.amount + bane_cocoons.amount + lings.amount
382382
if current_amount < target_amount:
383-
await self.client.debug_create_unit([[UnitTypeId.ZERGLING, target_amount - current_amount, center, 1]])
383+
await self.client.debug_create_unit([(UnitTypeId.ZERGLING, target_amount - current_amount, center, 1)])
384384

385385
if lings.amount >= target_amount and self.minerals >= 10_000 and self.vespene >= 10_000:
386386
for ling in lings:
@@ -408,11 +408,11 @@ async def test_botai_actions11(self):
408408
map_center = self.game_info.map_center
409409

410410
while not self.units(UnitTypeId.RAVEN):
411-
await self.client.debug_create_unit([[UnitTypeId.RAVEN, 1, map_center, 1]])
411+
await self.client.debug_create_unit([(UnitTypeId.RAVEN, 1, map_center, 1)])
412412
await self._advance_steps(2)
413413

414414
while not self.enemy_units(UnitTypeId.INFESTOR):
415-
await self.client.debug_create_unit([[UnitTypeId.INFESTOR, 1, map_center, 2]])
415+
await self.client.debug_create_unit([(UnitTypeId.INFESTOR, 1, map_center, 2)])
416416
await self._advance_steps(2)
417417

418418
raven = self.units(UnitTypeId.RAVEN)[0]
@@ -421,7 +421,7 @@ async def test_botai_actions11(self):
421421
await self._advance_steps(4)
422422

423423
enemy = self.enemy_units(UnitTypeId.INFESTOR)[0]
424-
while 1:
424+
while True:
425425
raven = self.units(UnitTypeId.RAVEN)[0]
426426
raven(AbilityId.EFFECT_ANTIARMORMISSILE, enemy)
427427
await self._advance_steps(2)
@@ -440,7 +440,7 @@ async def test_botai_actions12(self):
440440
await self.client.debug_all_resources()
441441
await self._advance_steps(2)
442442

443-
while 1:
443+
while True:
444444
# Once depot is under construction: debug kill scv -> advance simulation: should now match the test case
445445
if self.structures(UnitTypeId.SUPPLYDEPOT).not_ready.amount == 1:
446446
construction_scvs: Units = self.workers.filter(lambda worker: worker.is_constructing_scv)

test/battery_overcharge_bot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ async def on_start(self):
1818
"""Spawn requires structures."""
1919
await self.client.debug_create_unit(
2020
[
21-
[UnitTypeId.PYLON, 1, self.start_location.towards(self.game_info.map_center, 5), 1],
22-
[UnitTypeId.SHIELDBATTERY, 1, self.start_location.towards(self.game_info.map_center, 5), 1],
23-
[UnitTypeId.CYBERNETICSCORE, 1, self.start_location.towards(self.game_info.map_center, 5), 1],
21+
(UnitTypeId.PYLON, 1, self.start_location.towards(self.game_info.map_center, 5), 1),
22+
(UnitTypeId.SHIELDBATTERY, 1, self.start_location.towards(self.game_info.map_center, 5), 1),
23+
(UnitTypeId.CYBERNETICSCORE, 1, self.start_location.towards(self.game_info.map_center, 5), 1),
2424
]
2525
)
2626

test/benchmark_distance_two_points.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def distance_numpy_linalg_norm(p1, p2):
4646

4747
def distance_sum_squared_sqrt(p1, p2) -> int | float:
4848
"""Distance calculation using numpy"""
49-
return np.sqrt(np.sum((p1 - p2) ** 2))
49+
return np.sqrt(np.sum((p1 - p2) ** 2)) # pyrefly: ignore
5050

5151

5252
def distance_sum_squared(p1, p2) -> int | float:

test/benchmark_distances_cdist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def distance_matrix_scipy_cdist_mahalanobis(ps):
5656

5757
def distance_matrix_scipy_cdist_matching(ps):
5858
# Calculate distances between each of the points
59-
return cdist(ps, ps, "matching")
59+
return cdist(ps, ps, "matching") # pyrefly: ignore
6060

6161

6262
# def distance_matrix_scipy_cdist_minkowski(ps):

test/damagetest_bot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,6 @@ def do_some_unit_property_tests(attacker: Unit, defender: Unit):
231231

232232
await self.clean_up_center()
233233

234-
attacker: Unit
235-
defender: Unit
236234
for upgrade_level in upgrade_levels:
237235
if upgrade_level != 0:
238236
await self.client.debug_upgrade()
@@ -252,7 +250,7 @@ def do_some_unit_property_tests(attacker: Unit, defender: Unit):
252250

253251
# Spawn units
254252
await self.client.debug_create_unit(
255-
[[attacker_type, 1, map_center, 1], [defender_type, 1, map_center, 2]]
253+
[(attacker_type, 1, map_center, 1), (defender_type, 1, map_center, 2)]
256254
)
257255
await self._advance_steps(1)
258256

@@ -292,8 +290,10 @@ def do_some_unit_property_tests(attacker: Unit, defender: Unit):
292290
await self._advance_steps(1)
293291
# Unsure why I have to recalculate this here again but it prevents a bug
294292
attacker, defender = get_attacker_and_defender()
293+
# pyrefly: ignore
295294
expected_damage: float = max(expected_damage, attacker.calculate_damage_vs_target(defender)[0])
296295
real_damage = math.ceil(
296+
# pyrefly: ignore
297297
defender.health_max + defender.shield_max - defender.health - defender.shield
298298
)
299299
# logger.info(
@@ -304,6 +304,7 @@ def do_some_unit_property_tests(attacker: Unit, defender: Unit):
304304
f"Step limit reached. Test timed out for attacker {attacker_type} and defender {defender_type}"
305305
)
306306
assert expected_damage == real_damage, (
307+
# pyrefly: ignore
307308
f"Expected damage does not match real damage: Unit type {attacker_type} (attack upgrade: {attacker.attack_upgrade_level}) deals {real_damage} damage against {defender_type} (armor upgrade: {defender.armor_upgrade_level} and shield upgrade: {defender.shield_upgrade_level}) but calculated damage was {expected_damage}, attacker weapons: \n{attacker._weapons}"
308309
)
309310

test/generate_pickle_files_bot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class ExporterBot(BotAI):
2626
def __init__(self):
2727
BotAI.__init__(self)
28-
self.map_name: str = None
28+
self.map_name: str = None # pyrefly: ignore
2929

3030
async def on_step(self, iteration):
3131
pass
@@ -44,7 +44,7 @@ def get_combat_file_path(self) -> Path:
4444
file_path = folder_path / subfolder_name / file_name
4545
return file_path
4646

47-
async def store_data_to_file(self, file_path: str):
47+
async def store_data_to_file(self, file_path: Path):
4848
# Grab all raw data from observation
4949
raw_game_data = await self.client._execute(
5050
data=sc_pb.RequestData(ability_id=True, unit_type_id=True, upgrade_id=True, buff_id=True, effect_id=True)
@@ -86,10 +86,10 @@ async def on_start(self):
8686
}
8787

8888
# Create units for self
89-
await self.client.debug_create_unit([[valid_unit, 1, self.start_location, 1] for valid_unit in valid_units])
89+
await self.client.debug_create_unit([(valid_unit, 1, self.start_location, 1) for valid_unit in valid_units])
9090
# Create units for enemy
9191
await self.client.debug_create_unit(
92-
[[valid_unit, 1, self.enemy_start_locations[0], 2] for valid_unit in valid_units]
92+
[(valid_unit, 1, self.enemy_start_locations[0], 2) for valid_unit in valid_units]
9393
)
9494

9595
await self._advance_steps(2)

test/queries_test_bot.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def clear_map_center(self):
4747
map_center = self.game_info.map_center
4848

4949
# Spawn observer to be able to see enemy invisible units
50-
await self.client.debug_create_unit([[UnitTypeId.OBSERVER, 1, map_center, 1]])
50+
await self.client.debug_create_unit([(UnitTypeId.OBSERVER, 1, map_center, 1)])
5151
await self._advance_steps(10)
5252

5353
# Remove everything close to map center
@@ -71,17 +71,17 @@ async def spawn_unit(self, unit_type: UnitTypeId | list[UnitTypeId]):
7171
if not isinstance(unit_type, list):
7272
unit_type = [unit_type]
7373
for i in unit_type:
74-
await self.client.debug_create_unit([[i, 1, self.game_info.map_center, 1]])
74+
await self.client.debug_create_unit([(i, 1, self.game_info.map_center, 1)])
7575

7676
async def spawn_unit_enemy(self, unit_type: UnitTypeId | list[UnitTypeId]):
7777
await self._advance_steps(10)
7878
if not isinstance(unit_type, list):
7979
unit_type = [unit_type]
8080
for i in unit_type:
8181
if i == UnitTypeId.CREEPTUMOR:
82-
await self.client.debug_create_unit([[i, 1, self.game_info.map_center + Point2((5, 5)), 2]])
82+
await self.client.debug_create_unit([(i, 1, self.game_info.map_center + Point2((5, 5)), 2)])
8383
else:
84-
await self.client.debug_create_unit([[i, 1, self.game_info.map_center, 2]])
84+
await self.client.debug_create_unit([(i, 1, self.game_info.map_center, 2)])
8585

8686
async def run_can_place(self) -> bool:
8787
result = await self.can_place(AbilityId.TERRANBUILD_COMMANDCENTER, [self.game_info.map_center])
@@ -194,7 +194,7 @@ async def test_rally_points_with_rally_ability(self):
194194
map_center = self.game_info.map_center
195195
barracks_spawn_point = map_center.offset(Point2((10, 10)))
196196
await self.client.debug_create_unit(
197-
[[UnitTypeId.BARRACKS, 2, barracks_spawn_point, 1], [UnitTypeId.FACTORY, 2, barracks_spawn_point, 1]]
197+
[(UnitTypeId.BARRACKS, 2, barracks_spawn_point, 1), (UnitTypeId.FACTORY, 2, barracks_spawn_point, 1)]
198198
)
199199
await self._advance_steps(10)
200200

@@ -220,7 +220,7 @@ async def test_rally_points_with_smart_ability(self):
220220
map_center = self.game_info.map_center
221221
barracks_spawn_point = map_center.offset(Point2((10, 10)))
222222
await self.client.debug_create_unit(
223-
[[UnitTypeId.BARRACKS, 2, barracks_spawn_point, 1], [UnitTypeId.FACTORY, 2, barracks_spawn_point, 1]]
223+
[(UnitTypeId.BARRACKS, 2, barracks_spawn_point, 1), (UnitTypeId.FACTORY, 2, barracks_spawn_point, 1)]
224224
)
225225
await self._advance_steps(10)
226226

test/real_time_worker_production.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ async def on_step(self, iteration):
6868
continue
6969
if self.enemy_structures.closer_than(10, expansion_location):
7070
continue
71-
await self.client.debug_create_unit([[UnitTypeId.NEXUS, 1, expansion_location, 1]])
71+
await self.client.debug_create_unit([(UnitTypeId.NEXUS, 1, expansion_location, 1)])
7272
logger.info(
7373
f"{self.time_formatted} {self.state.game_loop} Spawning a nexus {self.supply_used} / {self.supply_cap}"
7474
)
7575
made_nexus = True
76-
break
76+
continue
7777

7878
# Spawn new pylon in map center if no more expansions are available
7979
if self.supply_left == 0 and not made_nexus:
80-
await self.client.debug_create_unit([[UnitTypeId.PYLON, 1, self.game_info.map_center, 1]])
80+
await self.client.debug_create_unit([(UnitTypeId.PYLON, 1, self.game_info.map_center, 1)])
8181

8282
# Don't get disturbed during this test
8383
if self.enemy_units:

test/run_example_bots_vs_computer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@
114114

115115
# Run example bots
116116
for bot_info in bot_infos:
117-
bot_race: Race = bot_info["race"]
118-
bot_path: str = bot_info["path"]
119-
bot_class_name: str = bot_info["bot_class_name"]
117+
bot_race: Race = bot_info["race"] # pyrefly: ignore
118+
bot_path: str = bot_info["path"] # pyrefly: ignore
119+
bot_class_name: str = bot_info["bot_class_name"] # pyrefly: ignore
120120
module = import_module(bot_path)
121121
bot_class: type[BotAI] = getattr(module, bot_class_name)
122122

0 commit comments

Comments
 (0)