summaryrefslogtreecommitdiff
path: root/tests/test_error_codes.py
diff options
context:
space:
mode:
authortanaka takashi <isazaka@gmail.com>2026-07-12 16:03:29 +0900
committertanaka takashi <isazaka@gmail.com>2026-07-12 16:03:29 +0900
commit22f96694a96ed9fba169e77bc27d19d00edca083 (patch)
tree8f59c1d3f211c296b005a3f6ede8206bc3675a68 /tests/test_error_codes.py
parent3bb311ad8e0f10617805c8737d92d13e6a627818 (diff)
MML構文解析処理を追加
Diffstat (limited to 'tests/test_error_codes.py')
-rw-r--r--tests/test_error_codes.py87
1 files changed, 43 insertions, 44 deletions
diff --git a/tests/test_error_codes.py b/tests/test_error_codes.py
index eca73ad..f9bd5bb 100644
--- a/tests/test_error_codes.py
+++ b/tests/test_error_codes.py
@@ -1,4 +1,4 @@
-"""Exhaustive tests for all error codes defined in Design_err.md."""
+"""Exhaustive tests for all error codes defined in Design.md."""
from unittest.mock import patch
@@ -33,44 +33,44 @@ def test_syntax_invalid_token_mode(compose_mml):
def test_syntax_invalid_number_at(compose_mml):
result = compose_mml(action="validate", mml="0: T120 L4 O4 @x\n C", mode="pyxel")
assert not result["valid"]
- # @x -> lexer emits TEXT, parser reports unexpected or invalid number
+ # @x -> lexer emits INVALID, parser reports invalid token
assert result["errors"]
-# --- SYNTAX_VALUE_OUT_OF_RANGE ---
-def test_syntax_value_out_of_range_octave_ppmck(compose_mml):
+# --- SEMANTIC_VALUE_OUT_OF_RANGE ---
+def test_semantic_value_out_of_range_octave_ppmck(compose_mml):
result = compose_mml(action="validate", mml="A t120 l4 o9\n c", mode="ppmck")
assert not result["valid"]
codes = [e["code"] for e in result["errors"]]
- assert ErrorCode.SYNTAX_VALUE_OUT_OF_RANGE.value in codes
+ assert ErrorCode.SEMANTIC_VALUE_OUT_OF_RANGE.value in codes
-def test_syntax_value_out_of_range_volume_ppmck(compose_mml):
+def test_semantic_value_out_of_range_volume_ppmck(compose_mml):
result = compose_mml(action="validate", mml="A t120 l4 o4 v20\n c", mode="ppmck")
assert not result["valid"]
codes = [e["code"] for e in result["errors"]]
- assert ErrorCode.SYNTAX_VALUE_OUT_OF_RANGE.value in codes
+ assert ErrorCode.SEMANTIC_VALUE_OUT_OF_RANGE.value in codes
-def test_syntax_value_out_of_range_volume_pyxel(compose_mml):
+def test_semantic_value_out_of_range_volume_pyxel(compose_mml):
result = compose_mml(action="validate", mml="0: T120 L4 O4 V200\n C", mode="pyxel")
assert not result["valid"]
codes = [e["code"] for e in result["errors"]]
- assert ErrorCode.SYNTAX_VALUE_OUT_OF_RANGE.value in codes
+ assert ErrorCode.SEMANTIC_VALUE_OUT_OF_RANGE.value in codes
-def test_syntax_value_out_of_range_length(compose_mml):
+def test_semantic_value_out_of_range_length(compose_mml):
result = compose_mml(action="validate", mml="A t120 l0\n c", mode="ppmck")
assert not result["valid"]
codes = [e["code"] for e in result["errors"]]
- assert ErrorCode.SYNTAX_VALUE_OUT_OF_RANGE.value in codes
+ assert ErrorCode.SEMANTIC_VALUE_OUT_OF_RANGE.value in codes
-def test_syntax_value_out_of_range_tempo(compose_mml):
+def test_semantic_value_out_of_range_tempo(compose_mml):
result = compose_mml(action="validate", mml="A t0\n c", mode="ppmck")
assert not result["valid"]
codes = [e["code"] for e in result["errors"]]
- assert ErrorCode.SYNTAX_VALUE_OUT_OF_RANGE.value in codes
+ assert ErrorCode.SEMANTIC_VALUE_OUT_OF_RANGE.value in codes
# --- SYNTAX_UNEXPECTED_TOKEN ---
@@ -82,17 +82,17 @@ def test_syntax_unexpected_token(compose_mml):
assert result["valid"] is True
-# --- SYNTAX_OUTSIDE_TRACK ---
-def test_syntax_outside_track_ppmck(compose_mml):
+# --- SEMANTIC_OUTSIDE_TRACK ---
+def test_semantic_outside_track_ppmck(compose_mml):
result = compose_mml(action="validate", mml="t120\nA l4\n c", mode="ppmck")
assert result["valid"] is True
- assert _find_code(result, ErrorCode.SYNTAX_OUTSIDE_TRACK.value, "warnings")
+ assert _find_code(result, ErrorCode.SEMANTIC_OUTSIDE_TRACK.value, "warnings")
-def test_syntax_outside_track_pyxel(compose_mml):
+def test_semantic_outside_track_pyxel(compose_mml):
result = compose_mml(action="validate", mml="T120\n0: L4\n C", mode="pyxel")
assert result["valid"] is True
- assert _find_code(result, ErrorCode.SYNTAX_OUTSIDE_TRACK.value, "warnings")
+ assert _find_code(result, ErrorCode.SEMANTIC_OUTSIDE_TRACK.value, "warnings")
# --- SYNTAX_UNTERMINATED_REPEAT ---
@@ -153,27 +153,26 @@ def test_syntax_duplicate_track_pyxel(compose_mml):
assert _find_code(result, ErrorCode.SYNTAX_DUPLICATE_TRACK.value)
-# --- SYNTAX_EMPTY_TRACK ---
-def test_syntax_empty_track_ppmck(compose_mml):
+# --- SEMANTIC_EMPTY_TRACK ---
+def test_semantic_empty_track_ppmck(compose_mml):
# B track header with no notes/rests -> empty track error
result = compose_mml(action="validate", mml="A t120 l4\n c\nB", mode="ppmck")
# B alone sets track but has no events; check for empty track or just verify no crash
- # The parser may or may not flag this; verify result is a dict
assert isinstance(result, dict)
if not result["valid"]:
- assert _find_code(result, ErrorCode.SYNTAX_EMPTY_TRACK.value)
+ assert _find_code(result, ErrorCode.SEMANTIC_EMPTY_TRACK.value)
-def test_syntax_empty_track_pyxel(compose_mml):
+def test_semantic_empty_track_pyxel(compose_mml):
# 1: track with only tempo, no notes -> may or may not be flagged as empty
result = compose_mml(action="validate", mml="0: T120\n C\n1: T120", mode="pyxel")
assert isinstance(result, dict)
if not result["valid"]:
- assert _find_code(result, ErrorCode.SYNTAX_EMPTY_TRACK.value)
+ assert _find_code(result, ErrorCode.SEMANTIC_EMPTY_TRACK.value)
-# --- SYNTAX_NOTE_OUT_OF_RANGE ---
-def test_syntax_note_out_of_range_ppmck(compose_mml):
+# --- SEMANTIC_NOTE_OUT_OF_RANGE ---
+def test_semantic_note_out_of_range_ppmck(compose_mml):
# o7 b = MIDI 95, need many octave ups to exceed 127
result = compose_mml(
action="validate", mml="A t120 l4 o7\n b > > > > > c", mode="ppmck"
@@ -183,7 +182,7 @@ def test_syntax_note_out_of_range_ppmck(compose_mml):
assert any(e["severity"] == "warning" for e in result["warnings"])
-def test_syntax_note_out_of_range_pyxel(compose_mml):
+def test_semantic_note_out_of_range_pyxel(compose_mml):
result = compose_mml(
action="validate", mml="0: T120 L4 O7\n B > > > > > C", mode="pyxel"
)
@@ -191,20 +190,20 @@ def test_syntax_note_out_of_range_pyxel(compose_mml):
assert any(e["severity"] == "warning" for e in result["warnings"])
-# --- SYNTAX_CHANNEL_MISMATCH ---
-def test_syntax_channel_mismatch_ppmck_triangle_duty(compose_mml):
+# --- SEMANTIC_CHANNEL_MISMATCH ---
+def test_semantic_channel_mismatch_ppmck_triangle_duty(compose_mml):
result = compose_mml(action="validate", mml="T t120 l4 q2\n c", mode="ppmck")
- assert _find_code(result, ErrorCode.SYNTAX_CHANNEL_MISMATCH.value, "warnings")
+ assert _find_code(result, ErrorCode.SEMANTIC_CHANNEL_MISMATCH.value, "warnings")
-def test_syntax_channel_mismatch_ppmck_noise_pitch(compose_mml):
+def test_semantic_channel_mismatch_ppmck_noise_pitch(compose_mml):
result = compose_mml(action="validate", mml="N t120 l4\n c", mode="ppmck")
- assert _find_code(result, ErrorCode.SYNTAX_CHANNEL_MISMATCH.value, "warnings")
+ assert _find_code(result, ErrorCode.SEMANTIC_CHANNEL_MISMATCH.value, "warnings")
-def test_syntax_channel_mismatch_pyxel_triangle_at(compose_mml):
+def test_semantic_channel_mismatch_pyxel_triangle_at(compose_mml):
result = compose_mml(action="validate", mml="2: T120 L4 @1\n C", mode="pyxel")
- assert _find_code(result, ErrorCode.SYNTAX_CHANNEL_MISMATCH.value, "warnings")
+ assert _find_code(result, ErrorCode.SEMANTIC_CHANNEL_MISMATCH.value, "warnings")
# --- SYNTAX_UNTERMINATED_HEADER ---
@@ -237,8 +236,8 @@ def test_validation_invalid_action(compose_mml):
assert _find_code(result, ErrorCode.VALIDATION_INVALID_ACTION.value)
-# --- SYSTEM_SYNTHESIS_FAILED ---
-def test_system_synthesis_failed(compose_mml):
+# --- RUNTIME_SYNTHESIS_FAILED ---
+def test_runtime_synthesis_failed(compose_mml):
with patch(
"mml_composemusic_mcp.server.synthesize",
side_effect=RuntimeError("overflow"),
@@ -249,11 +248,11 @@ def test_system_synthesis_failed(compose_mml):
mode="ppmck",
)
assert result["success"] is False
- assert _find_code(result, ErrorCode.SYSTEM_SYNTHESIS_FAILED.value)
+ assert _find_code(result, ErrorCode.RUNTIME_SYNTHESIS_FAILED.value)
-# --- SYSTEM_WAV_WRITE_FAILED ---
-def test_system_wav_write_failed(tmp_path):
+# --- RUNTIME_WAV_WRITE_FAILED ---
+def test_runtime_wav_write_failed(tmp_path):
bad_path = tmp_path / "nonexistent_dir" / "output.wav"
data = np.array([0.0, 0.1, -0.1], dtype=np.float64)
errors = write_wav(bad_path, data, 44100)
@@ -266,11 +265,11 @@ def test_system_wav_write_failed(tmp_path):
bad_path2 = blocker / "output.wav"
errors = write_wav(bad_path2, data, 44100)
if errors:
- assert errors[0].code == ErrorCode.SYSTEM_WAV_WRITE_FAILED
+ assert errors[0].code == ErrorCode.RUNTIME_WAV_WRITE_FAILED
-# --- SYSTEM_INTERNAL_ERROR ---
-def test_system_internal_error(compose_mml):
+# --- RUNTIME_INTERNAL_ERROR ---
+def test_runtime_internal_error(compose_mml):
with patch(
"mml_composemusic_mcp.server._parse_mml",
side_effect=RuntimeError("unexpected internal error"),
@@ -281,9 +280,9 @@ def test_system_internal_error(compose_mml):
mode="ppmck",
)
assert result["success"] is False
- assert _find_code(result, ErrorCode.SYSTEM_INTERNAL_ERROR.value)
+ assert _find_code(result, ErrorCode.RUNTIME_INTERNAL_ERROR.value)
-def test_system_internal_error_not_exposed(compose_mml):
+def test_runtime_internal_error_not_exposed(compose_mml):
result = compose_mml(action="compose", mml="A t120 l4 o4\n c", mode="ppmck")
assert isinstance(result, dict)