Skip to content

Commit

Permalink
Fix pyre issues for test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnySc2 committed Dec 17, 2024
1 parent d46b590 commit 2b1079c
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .pyre_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{
"import_root": ".",
"source": "examples"
},
{
"import_root": ".",
"source": "test"
}
]
}
2 changes: 2 additions & 0 deletions test/autotest_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)

from loguru import logger
Expand Down Expand Up @@ -487,6 +488,7 @@ async def on_start(self):
await self.client.debug_kill_unit(self.units)

async def on_step(self, iteration: int):
# pyre-ignore[16]
map_center = self.game_info.map_center
enemies = self.enemy_units | self.enemy_structures
if enemies:
Expand Down
1 change: 1 addition & 0 deletions test/benchmark_distance_two_points.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[21]
import math
import platform
import random
Expand Down
1 change: 1 addition & 0 deletions test/benchmark_distances_cdist.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[21]
import random

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions test/benchmark_distances_points_to_point.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[21]
from __future__ import annotations

import math
Expand Down
1 change: 1 addition & 0 deletions test/benchmark_distances_units.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[21]
import math
import random

Expand Down
2 changes: 2 additions & 0 deletions test/damagetest_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)
import math

Expand Down Expand Up @@ -323,6 +324,7 @@ async def on_start(self):
await self.client.debug_kill_unit(self.units)

async def on_step(self, iteration: int):
# pyre-ignore[16]
map_center = self.game_info.map_center
enemies = self.enemy_units | self.enemy_structures
if enemies:
Expand Down
6 changes: 4 additions & 2 deletions test/generate_pickle_files_bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[16]
"""
This "bot" will loop over several available ladder maps and generate the pickle file in the "/test/pickle_data/" subfolder.
These will then be used to run tests from the test script "test_pickled_data.py"
Expand All @@ -8,6 +9,7 @@
from pathlib import Path

from loguru import logger
# pyre-ignore[21]
from s2clientprotocol import sc2api_pb2 as sc_pb

from sc2 import maps
Expand All @@ -30,14 +32,14 @@ def __init__(self):
async def on_step(self, iteration):
pass

def get_pickle_file_path(self) -> str:
def get_pickle_file_path(self) -> Path:
folder_path = Path(__file__).parent
subfolder_name = "pickle_data"
file_name = f"{self.map_name}.xz"
file_path = folder_path / subfolder_name / file_name
return file_path

def get_combat_file_path(self) -> str:
def get_combat_file_path(self) -> Path:
folder_path = Path(__file__).parent
subfolder_name = "combat_data"
file_name = f"{self.map_name}.xz"
Expand Down
2 changes: 2 additions & 0 deletions test/queries_test_bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[16]
"""
This testbot's purpose is to test the query behavior of the API.
These query functions are:
Expand All @@ -10,6 +11,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)


Expand Down
2 changes: 2 additions & 0 deletions test/real_time_worker_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)
import asyncio

Expand Down Expand Up @@ -94,6 +95,7 @@ async def on_building_construction_complete(self, unit: Unit):
if unit.is_structure:
unit(AbilityId.RALLY_WORKERS, self.mineral_field.closest_to(unit))

# pyre-ignore[11]
async def on_end(self, game_result: Result):
global on_end_was_called
on_end_was_called = True
Expand Down
3 changes: 3 additions & 0 deletions test/run_example_bots_vs_computer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[16]
"""
This script makes sure to run all bots in the examples folder to check if they can launch.
"""
Expand All @@ -7,6 +8,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)
import asyncio
from importlib import import_module
Expand Down Expand Up @@ -118,6 +120,7 @@

# Run example bots
for bot_info in bot_infos:
# pyre-ignore[11]
bot_race: Race = bot_info["race"]
bot_path: str = bot_info["path"]
bot_class_name: str = bot_info["bot_class_name"]
Expand Down
3 changes: 3 additions & 0 deletions test/run_example_bots_vs_each_other.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pyre-ignore-all-errors[16]
"""
This script makes sure to run all bots in the examples folder to check if they can launch against each other.
"""
Expand All @@ -7,6 +8,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)
import asyncio
from importlib import import_module
Expand Down Expand Up @@ -99,6 +101,7 @@

# Run bots against each other
for bot_info1, bot_info2 in combinations(bot_infos, 2):
# pyre-ignore[11]
bot_race1: Race = bot_info1["race"]
bot_path: str = bot_info1["path"]
bot_class_name: str = bot_info1["bot_class_name"]
Expand Down
3 changes: 3 additions & 0 deletions test/test_pickled_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pathlib import Path
from typing import Any

# pyre-ignore[21]
from google.protobuf.internal import api_implementation
from hypothesis import given, settings
from hypothesis import strategies as st
Expand Down Expand Up @@ -292,12 +293,14 @@ def test_bot_ai():

def calc_cost(item_id) -> Cost:
if isinstance(item_id, AbilityId):
# pyre-ignore[16]
return bot.game_data.calculate_ability_cost(item_id)
elif isinstance(item_id, UpgradeId):
return bot.game_data.upgrades[item_id.value].cost
elif isinstance(item_id, UnitTypeId):
creation_ability: AbilityId = bot.game_data.units[item_id.value].creation_ability.exact_id
return bot.game_data.calculate_ability_cost(creation_ability)
return Cost(0, 0)

def assert_cost(item_id, real_cost: Cost):
assert calc_cost(item_id) == real_cost, f"Cost of {item_id} should be {real_cost} but is {calc_cost(item_id)}"
Expand Down
3 changes: 3 additions & 0 deletions test/test_pickled_ramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TestClass:

def test_main_base_ramp(self, map_path: Path):
bot = get_map_specific_bot(map_path)
# pyre-ignore[16]
bot.game_info.map_ramps, bot.game_info.vision_blockers = bot.game_info._find_ramps_and_vision_blockers()

# Test if main ramp works for all spawns
Expand Down Expand Up @@ -103,6 +104,7 @@ def test_bot_ai(self, map_path: Path):
), f"Too many expansions found: {len(bot.expansion_locations_list)}"
# On N player maps, it is expected that there are N*X bases because of symmetry, at least for maps designed for 1vs1
# Those maps in the list have an un-even expansion count
# pyre-ignore[16]
expect_even_expansion_count = 1 if bot.game_info.map_name in ["StargazersAIE", "Stasis LE"] else 0
assert (
len(bot.expansion_locations_list) % (len(bot.enemy_start_locations) + 1) == expect_even_expansion_count
Expand All @@ -115,6 +117,7 @@ def test_bot_ai(self, map_path: Path):
for location in bot.enemy_start_locations:
assert location in set(bot.expansion_locations_list), f"{location}, {bot.expansion_locations_list}"
# Each expansion is supposed to have at least one geysir and 6-12 minerals
# pyre-ignore[16]
for expansion, resource_positions in bot.expansion_locations_dict.items():
assert isinstance(expansion, Point2)
assert isinstance(resource_positions, Units)
Expand Down
6 changes: 5 additions & 1 deletion test/travis_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,20 @@
# Break as the bot run was successful
break

# pyre-ignore[16]
if process.returncode is not None:
# Reformat the output into a list
logger.info_output: str = result
# pyre-ignore[16]
logger.info_output = result
linebreaks = [
# pyre-ignore[16]
["\r\n", logger.info_output.count("\r\n")],
["\r", logger.info_output.count("\r")],
["\n", logger.info_output.count("\n")],
]
most_linebreaks_type = max(linebreaks, key=lambda x: x[1])
linebreak_type, linebreak_count = most_linebreaks_type
# pyre-ignore[16]
output_as_list = logger.info_output.split(linebreak_type)
logger.info("Travis test script, bot output:\r\n{}\r\nEnd of bot output".format("\r\n".join(output_as_list)))

Expand Down
2 changes: 2 additions & 0 deletions test/upgradestest_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from pathlib import Path

# pyre-ignore[6]
sys.path.append(Path(__file__).parent)

from loguru import logger
Expand Down Expand Up @@ -179,6 +180,7 @@ async def on_start(self):
await self.client.debug_kill_unit(self.units)

async def on_step(self, iteration: int):
# pyre-ignore[16]
map_center = self.game_info.map_center
enemies = self.enemy_units | self.enemy_structures
if enemies:
Expand Down

0 comments on commit 2b1079c

Please sign in to comment.