Skip to content

Commit

Permalink
Merge pull request #41 from Jylpah/dev
Browse files Browse the repository at this point in the history
version 1.2.12
  • Loading branch information
Jylpah authored Jan 21, 2024
2 parents a77d45f + ca91e97 commit c273117
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blitz-models"
version = "1.2.11"
version = "1.2.12"
authors = [{ name = "Jylpah", email = "[email protected]" }]
description = "Pydantic models for Wargaming's World of Tanks Blitz game "
readme = "README.md"
Expand Down
11 changes: 6 additions & 5 deletions src/blitzmodels/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Field,
# ValidationError,
)
from aiofiles import open
import aiofiles
from pathlib import Path
from re import Pattern, compile, Match
from yaml import safe_load # type: ignore
Expand Down Expand Up @@ -130,7 +130,7 @@ async def open_yaml(
Read Maps from Blitz game maps.yaml file
"""
try:
async with open(file=filename, mode="r", encoding="utf-8") as file:
async with aiofiles.open(file=filename, mode="r", encoding="utf-8") as file:
debug(f"yaml file opened: {str(filename)}")
return cls.load_yaml(await file.read())
except OSError as err:
Expand Down Expand Up @@ -178,11 +178,12 @@ def default_path(cls) -> Path:
return maps_fn

@classmethod
async def open_default(cls) -> Optional[Self]:
def open_default(cls) -> Optional[Self]:
"""
Open maps shipped with the package
"""
return await cls.open_json(cls.default_path())
with open(cls.default_path(), "r", encoding="utf-8") as file:
return cls.parse_str(file.read())

def get_by_key(self, key: str) -> Map | None:
"""A brute-force map search by key"""
Expand Down Expand Up @@ -226,7 +227,7 @@ def add_names(self, localization_strs: Dict[str, str]) -> int:
# warn("legacy JSON format is depreciated", category=DeprecationWarning)
# try:
# res = cls()
# async with open(filename, "r", encoding="utf8") as f:
# async with aiofiles.open(filename, "r", encoding="utf8") as f:
# objs: dict[str, Any] = json.loads(await f.read())
# for key, obj in objs.items():
# try:
Expand Down
5 changes: 3 additions & 2 deletions src/blitzmodels/wg_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,12 @@ def default_path(cls) -> Path:
return tankopedia_fn

@classmethod
async def open_default(cls) -> Optional[Self]:
def open_default(cls) -> Optional[Self]:
"""
Open Tankopedia shipped with the package
"""
return await cls.open_json(cls.default_path())
with open(cls.default_path(), "r", encoding="utf-8") as file:
return cls.parse_str(file.read())

def __len__(self) -> int:
return len(self.data)
Expand Down
7 changes: 2 additions & 5 deletions tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ async def test_4_open_yaml(
), f"incorrect number of names updated: {updated} != {maps_names_updated}"


@pytest.mark.asyncio
async def test_5_Maps_default() -> None:
assert (
maps := await Maps.open_default()
) is not None, "could not open packaged maps"
def test_5_Maps_default() -> None:
assert (maps := Maps.open_default()) is not None, "could not open packaged maps"
assert len(maps) > 0, "packaged maps file is empty"
assert len(maps) > 30, "packaged maps file does not have enough maps"
5 changes: 2 additions & 3 deletions tests/test_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,9 @@ async def test_12_WGApiTankopedia_sorted(
), f"tankopedia does not keep tanks sorted: {type(tankopedia.data)}, {type(tankopedia_shuffled.data)}"


@pytest.mark.asyncio
async def test_13_WGApiTankopedia_default() -> None:
def test_13_WGApiTankopedia_default() -> None:
assert (
tankopedia := await WGApiWoTBlitzTankopedia.open_default()
tankopedia := WGApiWoTBlitzTankopedia.open_default()
) is not None, "could not open packaged tankopedia"
assert len(tankopedia) > 0, "packaged tankopedia is empty"
assert len(tankopedia) > 500, "packaged tankopedia does not have enough tanks"

0 comments on commit c273117

Please sign in to comment.