From 9a24b906187c9d4d1e65a4b24fb852628d1e0618 Mon Sep 17 00:00:00 2001 From: Viv Date: Sun, 23 Jul 2023 10:11:29 -0400 Subject: [PATCH] Add new test for checking dummy TJA errors --- testing/data/dummy_tjas/basic_song.tja | 17 +++++++ testing/test_command_support.py | 70 ++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 testing/data/dummy_tjas/basic_song.tja create mode 100644 testing/test_command_support.py diff --git a/testing/data/dummy_tjas/basic_song.tja b/testing/data/dummy_tjas/basic_song.tja new file mode 100644 index 0000000..7f6f820 --- /dev/null +++ b/testing/data/dummy_tjas/basic_song.tja @@ -0,0 +1,17 @@ +// This song contains only basic notes. +BPM:120 +OFFSET:-1.00 + +COURSE:Oni +LEVEL:10 +BALLOON:8,8 +SCOREINIT:400 +SCOREDIFF:100 + +#START +1020304, +5000008, +6000008, +7000008, +9000008, +#END diff --git a/testing/test_command_support.py b/testing/test_command_support.py new file mode 100644 index 0000000..ad94786 --- /dev/null +++ b/testing/test_command_support.py @@ -0,0 +1,70 @@ +import os +import subprocess +from subprocess import CalledProcessError +import shutil +import glob +import traceback + +import pytest + +from tja2fumen import main as convert + + +@pytest.mark.parametrize('id_song,err_msg', [ + ['basic_song', None] +]) +def test_expected_errors(id_song, err_msg, tmp_path, entry_point): + # Define the testing directory + path_test = os.path.dirname(os.path.realpath(__file__)) + + # Define the working directory + path_temp = os.path.join(tmp_path, id_song) + os.mkdir(path_temp) + + # Copy input TJA to working directory + path_tja = os.path.join(path_test, "data", "dummy_tjas", f"{id_song}.tja") + path_tja_tmp = os.path.join(path_temp, f"{id_song}.tja") + 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) + 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