Added testing
This commit is contained in:
parent
821251b77c
commit
56c1d5427a
8 changed files with 151 additions and 8 deletions
|
@ -32,3 +32,17 @@ jobs:
|
|||
run: |
|
||||
mypy --version
|
||||
mypy .
|
||||
|
||||
tests:
|
||||
runs-on: docker
|
||||
container: forgejo.neshweb.net/ci-docker-images/python-neshweb:3.11
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: https://code.forgejo.org/actions/checkout@v3
|
||||
- name: Install packages
|
||||
run: |
|
||||
pip install -e .[testing] --disable-pip-version-check --no-cache-dir -q
|
||||
python -m pip list --format=columns --disable-pip-version-check
|
||||
- name: Run pytest
|
||||
run: |
|
||||
pytest
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -8,3 +8,4 @@ assets/
|
|||
__pycache__/
|
||||
*.egg-info/
|
||||
.mypy_cache/
|
||||
.pytest_cache/
|
||||
|
|
|
@ -28,6 +28,9 @@ typing = [
|
|||
"types-tqdm~=4.66.0",
|
||||
"types-requests~=2.32.0",
|
||||
]
|
||||
testing = [
|
||||
"pytest~=8.3.3"
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
skyeweave = "skyeweave.cli:run"
|
||||
|
@ -35,6 +38,7 @@ skyeweave = "skyeweave.cli:run"
|
|||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
include = ["skyeweave*"]
|
||||
exclude = ["tests*"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
"*" = ["py.typed"]
|
||||
|
@ -55,6 +59,13 @@ warn_return_any = true
|
|||
warn_unused_configs = true
|
||||
exclude = [ "test" ]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "8.0"
|
||||
addopts = "-rA -v"
|
||||
testpaths = [
|
||||
"tests",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools >= 61.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
|
|
@ -15,7 +15,7 @@ class ExtendData(TypedDict):
|
|||
faceSizeRect: NotRequired[Annotated[List[int], 2]]
|
||||
faceSize: NotRequired[int]
|
||||
|
||||
def fetch_config(chara_id: str) -> SpritesheetData:
|
||||
def fetch_config(chara_id: int) -> SpritesheetData:
|
||||
url = f"https://api.atlasacademy.io/raw/JP/svtScript?charaId={chara_id}"
|
||||
|
||||
LOGGER.debug(f"Loading data for {url}")
|
||||
|
@ -62,7 +62,7 @@ def fetch_mstsvtjson():
|
|||
break
|
||||
handle.write(block)
|
||||
|
||||
def fetch_expression_sheets(tempfolder: pathlib.Path, imageid: str):
|
||||
def fetch_expression_sheets(tempfolder: pathlib.Path, imageid: int):
|
||||
atlasurl_base = f"https://static.atlasacademy.io/{AtlasAPIConfig.REGION}/CharaFigure/{imageid}"
|
||||
|
||||
savefolder = tempfolder / str(imageid)
|
||||
|
@ -106,7 +106,7 @@ def fetch_expression_sheets(tempfolder: pathlib.Path, imageid: str):
|
|||
return savefolder
|
||||
|
||||
|
||||
def fetch_data(servantid: int) -> List[str]:
|
||||
def fetch_data(servantid: int) -> List[int]:
|
||||
atlasurl = f"https://api.atlasacademy.io/nice/{AtlasAPIConfig.REGION}/servant/{servantid}?lore=false&lang=en"
|
||||
|
||||
LOGGER.debug(f"Loading data for {atlasurl}")
|
||||
|
@ -118,8 +118,8 @@ def fetch_data(servantid: int) -> List[str]:
|
|||
|
||||
responsedata = response.json()
|
||||
svtname = responsedata["name"]
|
||||
charascripts: List[dict[str, str]] = responsedata["charaScripts"]
|
||||
chara_ids: List[str] = [chara["id"] for chara in charascripts]
|
||||
charascripts: List[dict[str, int]] = responsedata["charaScripts"]
|
||||
chara_ids: List[int] = [chara["id"] for chara in charascripts]
|
||||
|
||||
LOGGER.debug(chara_ids)
|
||||
LOGGER.info(f"{svtname} ({servantid}) - {len(chara_ids)} charaIds")
|
||||
|
|
|
@ -18,10 +18,10 @@ class CharaInfos(TypedDict):
|
|||
class SkyeWeave:
|
||||
output_folder: pathlib.Path
|
||||
image_folder: pathlib.Path
|
||||
chara_ids: List[str]
|
||||
chara_ids: List[int]
|
||||
chara_infos: Dict[str, CharaInfos]
|
||||
|
||||
def __init__(self, input_id: int, filters: Optional[List[str]] = None, output: Optional[pathlib.Path] = None, assets: Optional[pathlib.Path] = None):
|
||||
def __init__(self, input_id: int, filters: Optional[List[int]] = None, output: Optional[pathlib.Path] = None, assets: Optional[pathlib.Path] = None):
|
||||
_output_folder = output or PathConfig.OUTPUT
|
||||
_image_folder = assets or PathConfig.IMAGES
|
||||
|
||||
|
@ -31,7 +31,7 @@ class SkyeWeave:
|
|||
self.image_folder = _image_folder / str(input_id)
|
||||
else:
|
||||
LOGGER.info(f"Processing manually uploaded charaId {input_id}")
|
||||
_chara_ids = [str(input_id)]
|
||||
_chara_ids = [input_id]
|
||||
self.output_folder = _output_folder / "manual"
|
||||
self.image_folder = _image_folder / "manual"
|
||||
|
||||
|
|
15
tests/conftest.py
Normal file
15
tests/conftest.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import pathlib
|
||||
import shutil
|
||||
import pytest
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def path_images():
|
||||
path = pathlib.Path(__file__).parent / "test_path_images"
|
||||
yield path
|
||||
shutil.rmtree(path)
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def path_output():
|
||||
path = pathlib.Path(__file__).parent / "test_path_output"
|
||||
yield path
|
||||
shutil.rmtree(path)
|
36
tests/test_01_class.py
Normal file
36
tests/test_01_class.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from pathlib import Path
|
||||
from skyeweave import SkyeWeave
|
||||
|
||||
def test_servantid_create(path_images: Path, path_output: Path):
|
||||
test_id = 70
|
||||
|
||||
test_weaver = SkyeWeave(
|
||||
test_id,
|
||||
output=path_output,
|
||||
assets=path_images
|
||||
)
|
||||
|
||||
assert test_weaver.output_folder == path_output / str(test_id)
|
||||
assert path_output.exists()
|
||||
assert (path_output / str(test_id)).exists()
|
||||
|
||||
assert test_weaver.image_folder == path_images / str(test_id)
|
||||
assert path_images.exists()
|
||||
assert (path_images / str(test_id)).exists()
|
||||
|
||||
def test_charaid_create(path_images: Path, path_output: Path):
|
||||
test_id = 3013002
|
||||
|
||||
test_weaver = SkyeWeave(
|
||||
test_id,
|
||||
output=path_output,
|
||||
assets=path_images
|
||||
)
|
||||
|
||||
assert test_weaver.output_folder == path_output / "manual"
|
||||
assert path_output.exists()
|
||||
assert (path_output / "manual").exists()
|
||||
|
||||
assert test_weaver.image_folder == path_images / "manual"
|
||||
assert path_images.exists()
|
||||
assert (path_images / "manual").exists()
|
66
tests/test_02_download.py
Normal file
66
tests/test_02_download.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
from pathlib import Path
|
||||
from skyeweave import SkyeWeave
|
||||
|
||||
def test_servantid_download(path_images: Path, path_output: Path):
|
||||
test_id = 70
|
||||
|
||||
test_weaver = SkyeWeave(
|
||||
test_id,
|
||||
output=path_output,
|
||||
assets=path_images
|
||||
)
|
||||
test_weaver.download()
|
||||
|
||||
expected_path = path_images / str(test_id)
|
||||
expected_dirs = [ "3013000", "3013001", "3013002", "3013300", "1098204200", "1098264100", "1098290800" ]
|
||||
|
||||
dirs = [f for f in expected_path.iterdir() if f.is_dir()]
|
||||
assert set([d.name for d in dirs]) == set(expected_dirs)
|
||||
|
||||
for d in dirs:
|
||||
expected_files = ["0.png", "1.png"]
|
||||
files = [f.name for f in d.iterdir() if f.is_file()]
|
||||
assert set(files) == set(expected_files)
|
||||
|
||||
def test_servantid_download_filter(path_images: Path, path_output: Path):
|
||||
test_id = 70
|
||||
|
||||
test_weaver = SkyeWeave(
|
||||
test_id,
|
||||
filters=[ 3013000, 3013001, 1098290800],
|
||||
output=path_output,
|
||||
assets=path_images
|
||||
)
|
||||
test_weaver.download()
|
||||
|
||||
expected_path = path_images / str(test_id)
|
||||
expected_dirs = [ "3013000", "3013001", "1098290800" ]
|
||||
|
||||
dirs =[f for f in expected_path.iterdir() if f.is_dir()]
|
||||
assert set([d.name for d in dirs]) == set(expected_dirs)
|
||||
|
||||
for d in dirs:
|
||||
expected_files = ["0.png", "1.png"]
|
||||
files = [f.name for f in d.iterdir() if f.is_file()]
|
||||
assert set(files) == set(expected_files)
|
||||
|
||||
def test_charaid_download(path_images: Path, path_output: Path):
|
||||
test_id = 3013000
|
||||
|
||||
test_weaver = SkyeWeave(
|
||||
test_id,
|
||||
output=path_output,
|
||||
assets=path_images
|
||||
)
|
||||
test_weaver.download()
|
||||
|
||||
expected_path = path_images / "manual"
|
||||
expected_dirs = [ "3013000" ]
|
||||
|
||||
dirs = [f for f in expected_path.iterdir() if f.is_dir()]
|
||||
assert set([d.name for d in dirs]) == set(expected_dirs)
|
||||
|
||||
for d in dirs:
|
||||
expected_files = ["0.png", "1.png"]
|
||||
files = [f.name for f in d.iterdir() if f.is_file()]
|
||||
assert set(files) == set(expected_files)
|
Loading…
Reference in a new issue