1
0
mirror of synced 2024-11-23 21:20:56 +01:00

Improve custom TJA testing

This commit is contained in:
Viv 2024-02-10 13:26:07 -05:00
parent 5474ad0baa
commit 1faaab9e9c
4 changed files with 56 additions and 34 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# Custom song directory
testing/data/custom_tjas/*
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]

View File

@ -25,8 +25,9 @@ dev = ["pytest", "build", "pyinstaller", "twine", "toml-cli",
where = ["src"] where = ["src"]
[tool.pytest.ini_options] [tool.pytest.ini_options]
addopts = "-vv --tb=short" addopts = "-vv --tb=short --color=yes"
console_output_style = "count" console_output_style = "count"
disable_test_id_escaping_and_forfeit_all_rights_to_community_support = "True"
[tool.flake8] [tool.flake8]
exclude = "venv/" exclude = "venv/"

View File

@ -10,39 +10,6 @@ from conftest import convert
from tja2fumen.parsers import parse_fumen from tja2fumen.parsers import parse_fumen
@pytest.mark.skipif("CI" in os.environ,
reason="Test is only for local debugging")
def test_converted_tja_no_comparison(tmp_path, entry_point):
"""
A test purely to aid with debugging. It lets me drop a .tja into a
pre-determined folder and run the conversion, allowing me to set
breakpoints and debug internal state without any tedious setup.
"""
# Define the testing directory
path_test = os.path.dirname(os.path.realpath(__file__))
path_test = os.path.join(path_test, "data", "unpaired_tjs")
for fname in os.listdir(path_test):
# Copy input TJA to working directory
path_tja = os.path.join(path_test, fname)
path_tja_tmp = os.path.join(tmp_path, fname)
shutil.copy(path_tja, path_tja_tmp)
# Convert TJA file to fumen files
convert(path_test, path_tja_tmp, entry_point)
# Fetch output fumen paths
paths_out = glob.glob(os.path.join(tmp_path, "*.bin"))
assert paths_out, f"No bin files generated in {tmp_path}"
order = "xmhne" # Ura Oni -> Oni -> Hard -> Normal -> Easy
paths_out = sorted(paths_out,
key=lambda s: [order.index(c) if c in order
else len(order) for c in s])
for path_out in paths_out:
difficulty = os.path.basename(path_out).split(".")[0].split("_")[1]
song = parse_fumen(path_out, exclude_empty_measures=False)
print(f"{difficulty}: {len(song.measures)}")
@pytest.mark.parametrize('id_song', [ @pytest.mark.parametrize('id_song', [
pytest.param('butou5'), pytest.param('butou5'),
pytest.param('shoto9', pytest.param('shoto9',

View File

@ -0,0 +1,51 @@
import os
import shutil
import glob
import pytest
from conftest import convert
from tja2fumen.parsers import parse_fumen
CUSTOM_TJA_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"data", "custom_tjas")
# CUSTOM_TJA_DIR = os.path.join("D:\\", "games", "TaikoTDM",
# "CustomSongSources", "ESE")
CUSTOM_TJAS = sum([
# For each file in the subfolder, keep only if it ends in `.tja`
[(root, f) for f in files if f.endswith(".tja")]
# Iterate through all subfolders in the "unpaired_tjas" folder
for root, _, files in os.walk(CUSTOM_TJA_DIR)
], []) # sum([list of lists], []) -> https://stackoverflow.com/a/716489
CUSTOM_TJA_PATHS = [os.path.join(root, f) for (root, f) in CUSTOM_TJAS]
CUSTOM_TJA_IDS = [f for (root, f) in CUSTOM_TJAS]
@pytest.mark.parametrize('path_tja', CUSTOM_TJA_PATHS, ids=CUSTOM_TJA_IDS)
@pytest.mark.skipif("CI" in os.environ,
reason="Test is only for local debugging")
def test_converted_custom_tjas(path_tja, tmp_path, entry_point):
"""
A test purely to aid with debugging. It lets me drop a .tja into a
pre-determined folder and run the conversion, allowing me to set
breakpoints and debug internal state without any tedious setup.
"""
# Define the testing directory
path_test = os.path.dirname(os.path.realpath(__file__))
# Copy input TJA to working directory
path_tja_tmp = str(tmp_path / "test.tja")
shutil.copy(path_tja, path_tja_tmp)
# Convert TJA file to fumen files
convert(path_test, path_tja_tmp, entry_point)
# Fetch output fumen paths
paths_out = glob.glob(os.path.join(tmp_path, "*.bin"))
assert paths_out, f"No bin files generated in {tmp_path}"
order = "xmhne" # Ura Oni -> Oni -> Hard -> Normal -> Easy
paths_out = sorted(paths_out,
key=lambda s: [order.index(c) if c in order
else len(order) for c in s])
for path_out in paths_out:
parse_fumen(path_out, exclude_empty_measures=False)