testing/
: Move convert()
into conftest.py
This commit is contained in:
parent
9a24b90618
commit
ca9b0d0332
@ -1,5 +1,13 @@
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError
|
||||
import traceback
|
||||
|
||||
import pytest
|
||||
|
||||
from tja2fumen import main as api_convert
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--entry-point", action="store", default="python-api")
|
||||
@ -8,3 +16,39 @@ def pytest_addoption(parser):
|
||||
@pytest.fixture
|
||||
def entry_point(request):
|
||||
return request.config.getoption("--entry-point")
|
||||
|
||||
|
||||
def convert(path_test, path_tja_tmp, entry_point, err_msg=None):
|
||||
tb = ''
|
||||
|
||||
if entry_point == "python-api":
|
||||
if not err_msg:
|
||||
api_convert(argv=[path_tja_tmp])
|
||||
else:
|
||||
with pytest.raises(ValueError) as e:
|
||||
api_convert(argv=[path_tja_tmp])
|
||||
tb = "".join(traceback.format_tb(e.tb))
|
||||
|
||||
elif entry_point == "python-cli":
|
||||
if not err_msg:
|
||||
subprocess.check_output(f"tja2fumen {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
else:
|
||||
with pytest.raises(CalledProcessError) as e:
|
||||
subprocess.check_output(f"tja2fumen {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
tb = e.value.output
|
||||
|
||||
elif entry_point == "exe":
|
||||
exe_glob = os.path.join(os.path.split(path_test)[0], "dist", "*.exe")
|
||||
exe = glob.glob(exe_glob)[0]
|
||||
if not err_msg:
|
||||
subprocess.check_output(f"{exe} {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
else:
|
||||
with pytest.raises(CalledProcessError) as e:
|
||||
subprocess.check_output(f"{exe} {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
tb = e.value.output
|
||||
|
||||
return tb
|
||||
|
@ -1,13 +1,9 @@
|
||||
import os
|
||||
import subprocess
|
||||
from subprocess import CalledProcessError
|
||||
import shutil
|
||||
import glob
|
||||
import traceback
|
||||
|
||||
import pytest
|
||||
|
||||
from tja2fumen import main as convert
|
||||
from conftest import convert
|
||||
|
||||
|
||||
@pytest.mark.parametrize('id_song,err_msg', [
|
||||
@ -27,44 +23,8 @@ def test_expected_errors(id_song, err_msg, tmp_path, entry_point):
|
||||
shutil.copy(path_tja, path_tja_tmp)
|
||||
|
||||
# Try to convert TJA file to fumen files, then check the error traceback
|
||||
tb = call_conversion_func(path_test, path_tja_tmp, err_msg, entry_point)
|
||||
tb = convert(path_test, path_tja_tmp, entry_point, err_msg)
|
||||
if err_msg:
|
||||
assert err_msg in tb
|
||||
else:
|
||||
assert tb == ''
|
||||
|
||||
|
||||
def call_conversion_func(path_test, path_tja_tmp, err_msg, entry_point):
|
||||
tb = ''
|
||||
|
||||
if entry_point == "python-api":
|
||||
if not err_msg:
|
||||
convert(argv=[path_tja_tmp])
|
||||
else:
|
||||
with pytest.raises(ValueError) as e:
|
||||
convert(argv=[path_tja_tmp])
|
||||
tb = "".join(traceback.format_tb(e.tb))
|
||||
|
||||
elif entry_point == "python-cli":
|
||||
if not err_msg:
|
||||
subprocess.check_output(f"tja2fumen {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
else:
|
||||
with pytest.raises(CalledProcessError) as e:
|
||||
subprocess.check_output(f"tja2fumen {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
tb = e.value.output
|
||||
|
||||
elif entry_point == "exe":
|
||||
exe_glob = os.path.join(os.path.split(path_test)[0], "dist", "*.exe")
|
||||
exe = glob.glob(exe_glob)[0]
|
||||
if not err_msg:
|
||||
subprocess.check_output(f"{exe} {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
else:
|
||||
with pytest.raises(CalledProcessError) as e:
|
||||
subprocess.check_output(f"{exe} {path_tja_tmp}", text=True,
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
tb = e.value.output
|
||||
|
||||
return tb
|
||||
|
@ -6,7 +6,7 @@ import glob
|
||||
|
||||
import pytest
|
||||
|
||||
from tja2fumen import main as convert
|
||||
from conftest import convert
|
||||
from tja2fumen.parsers import parse_fumen
|
||||
from tja2fumen.constants import COURSE_IDS, NORMALIZE_COURSE
|
||||
|
||||
@ -39,14 +39,7 @@ def test_converted_tja_vs_cached_fumen(id_song, tmp_path, entry_point):
|
||||
shutil.copy(path_tja, path_tja_tmp)
|
||||
|
||||
# Convert TJA file to fumen files
|
||||
if entry_point == "python-api":
|
||||
convert(argv=[path_tja_tmp])
|
||||
elif entry_point == "python-cli":
|
||||
os.system(f"tja2fumen {path_tja_tmp}")
|
||||
elif entry_point == "exe":
|
||||
exe_path = glob.glob(os.path.join(os.path.split(path_test)[0],
|
||||
"dist", "*.exe"))[0]
|
||||
os.system(f"{exe_path} {path_tja_tmp}")
|
||||
convert(path_test, path_tja_tmp, entry_point)
|
||||
|
||||
# Fetch output fumen paths
|
||||
paths_out = glob.glob(os.path.join(path_temp, "*.bin"))
|
||||
|
Loading…
Reference in New Issue
Block a user