From 6d1fb0f58897b1325b291b65535653561b4f5350 Mon Sep 17 00:00:00 2001 From: tarepan Date: Tue, 19 Mar 2024 02:22:54 +0900 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86:=20e2e=20single=20API=20?= =?UTF-8?q?=E3=82=B9=E3=83=8A=E3=83=83=E3=83=97=E3=82=B7=E3=83=A7=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=83=86=E3=82=B9=E3=83=88=20vol.1=20(#1117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add: e2e single API スナップショットテスト * fix: lint * fix: 過剰な `round_floats()` の削除 --- .../test_post_accent_phrases_200.json | 49 ++++++++++ ...test_post_audio_query_from_preset_422.json | 3 + .../test_post_mora_data_200.json | 33 +++++++ .../test_post_mora_length_200.json | 33 +++++++ .../test_post_mora_pitch_200.json | 33 +++++++ .../test_post_morphable_targets_200.json | 34 +++++++ .../test_post_sing_frame_audio_query_200.json | 97 +++++++++++++++++++ .../test_post_user_dict_word.json | 15 +++ test/e2e/single_api/test_accent_phrases.py | 8 +- .../test_audio_query_from_preset.py | 13 ++- test/e2e/single_api/test_mora_data.py | 7 +- test/e2e/single_api/test_mora_length.py | 7 +- test/e2e/single_api/test_mora_pitch.py | 7 +- test/e2e/single_api/test_morphable_targets.py | 6 +- .../single_api/test_sing_frame_audio_query.py | 8 +- test/e2e/single_api/test_user_dict_word.py | 6 +- 16 files changed, 350 insertions(+), 9 deletions(-) create mode 100644 test/e2e/single_api/__snapshots__/test_accent_phrases/test_post_accent_phrases_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_audio_query_from_preset/test_post_audio_query_from_preset_422.json create mode 100644 test/e2e/single_api/__snapshots__/test_mora_data/test_post_mora_data_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_mora_length/test_post_mora_length_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_mora_pitch/test_post_mora_pitch_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_morphable_targets/test_post_morphable_targets_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_sing_frame_audio_query/test_post_sing_frame_audio_query_200.json create mode 100644 test/e2e/single_api/__snapshots__/test_user_dict_word/test_post_user_dict_word.json diff --git a/test/e2e/single_api/__snapshots__/test_accent_phrases/test_post_accent_phrases_200.json b/test/e2e/single_api/__snapshots__/test_accent_phrases/test_post_accent_phrases_200.json new file mode 100644 index 000000000..9a61f7ac0 --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_accent_phrases/test_post_accent_phrases_200.json @@ -0,0 +1,49 @@ +[ + { + "accent": 1, + "is_interrogative": false, + "moras": [ + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 3.38, + "text": "テ", + "vowel": "e", + "vowel_length": 0.88 + }, + { + "consonant": "s", + "consonant_length": 2.19, + "pitch": 0.0, + "text": "ス", + "vowel": "U", + "vowel_length": 0.38 + }, + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 4.19, + "text": "ト", + "vowel": "o", + "vowel_length": 1.88 + }, + { + "consonant": "d", + "consonant_length": 0.75, + "pitch": 1.62, + "text": "デ", + "vowel": "e", + "vowel_length": 0.88 + }, + { + "consonant": "s", + "consonant_length": 2.19, + "pitch": 0.0, + "text": "ス", + "vowel": "U", + "vowel_length": 0.38 + } + ], + "pause_mora": null + } +] diff --git a/test/e2e/single_api/__snapshots__/test_audio_query_from_preset/test_post_audio_query_from_preset_422.json b/test/e2e/single_api/__snapshots__/test_audio_query_from_preset/test_post_audio_query_from_preset_422.json new file mode 100644 index 000000000..74d573c91 --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_audio_query_from_preset/test_post_audio_query_from_preset_422.json @@ -0,0 +1,3 @@ +{ + "detail": "該当するプリセットIDが見つかりません" +} diff --git a/test/e2e/single_api/__snapshots__/test_mora_data/test_post_mora_data_200.json b/test/e2e/single_api/__snapshots__/test_mora_data/test_post_mora_data_200.json new file mode 100644 index 000000000..8882a2dbb --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_mora_data/test_post_mora_data_200.json @@ -0,0 +1,33 @@ +[ + { + "accent": 1, + "is_interrogative": false, + "moras": [ + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 3.38, + "text": "テ", + "vowel": "e", + "vowel_length": 0.88 + }, + { + "consonant": "s", + "consonant_length": 2.19, + "pitch": 0.0, + "text": "ス", + "vowel": "U", + "vowel_length": 0.38 + }, + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 4.25, + "text": "ト", + "vowel": "o", + "vowel_length": 1.88 + } + ], + "pause_mora": null + } +] diff --git a/test/e2e/single_api/__snapshots__/test_mora_length/test_post_mora_length_200.json b/test/e2e/single_api/__snapshots__/test_mora_length/test_post_mora_length_200.json new file mode 100644 index 000000000..2fcfc63f0 --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_mora_length/test_post_mora_length_200.json @@ -0,0 +1,33 @@ +[ + { + "accent": 1, + "is_interrogative": false, + "moras": [ + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 3.3, + "text": "テ", + "vowel": "e", + "vowel_length": 0.88 + }, + { + "consonant": "s", + "consonant_length": 2.19, + "pitch": 0.0, + "text": "ス", + "vowel": "U", + "vowel_length": 0.38 + }, + { + "consonant": "t", + "consonant_length": 2.31, + "pitch": 4.1, + "text": "ト", + "vowel": "o", + "vowel_length": 1.88 + } + ], + "pause_mora": null + } +] diff --git a/test/e2e/single_api/__snapshots__/test_mora_pitch/test_post_mora_pitch_200.json b/test/e2e/single_api/__snapshots__/test_mora_pitch/test_post_mora_pitch_200.json new file mode 100644 index 000000000..075eac34d --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_mora_pitch/test_post_mora_pitch_200.json @@ -0,0 +1,33 @@ +[ + { + "accent": 1, + "is_interrogative": false, + "moras": [ + { + "consonant": "t", + "consonant_length": 2.3, + "pitch": 3.38, + "text": "テ", + "vowel": "e", + "vowel_length": 0.8 + }, + { + "consonant": "s", + "consonant_length": 2.1, + "pitch": 0.0, + "text": "ス", + "vowel": "U", + "vowel_length": 0.3 + }, + { + "consonant": "t", + "consonant_length": 2.3, + "pitch": 4.25, + "text": "ト", + "vowel": "o", + "vowel_length": 1.8 + } + ], + "pause_mora": null + } +] diff --git a/test/e2e/single_api/__snapshots__/test_morphable_targets/test_post_morphable_targets_200.json b/test/e2e/single_api/__snapshots__/test_morphable_targets/test_post_morphable_targets_200.json new file mode 100644 index 000000000..5e94662db --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_morphable_targets/test_post_morphable_targets_200.json @@ -0,0 +1,34 @@ +[ + { + "0": { + "is_morphable": true + }, + "1": { + "is_morphable": false + }, + "2": { + "is_morphable": true + }, + "3": { + "is_morphable": false + }, + "4": { + "is_morphable": true + }, + "5": { + "is_morphable": false + }, + "6": { + "is_morphable": true + }, + "7": { + "is_morphable": false + }, + "8": { + "is_morphable": false + }, + "9": { + "is_morphable": true + } + } +] diff --git a/test/e2e/single_api/__snapshots__/test_sing_frame_audio_query/test_post_sing_frame_audio_query_200.json b/test/e2e/single_api/__snapshots__/test_sing_frame_audio_query/test_post_sing_frame_audio_query_200.json new file mode 100644 index 000000000..4914aa6d9 --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_sing_frame_audio_query/test_post_sing_frame_audio_query_200.json @@ -0,0 +1,97 @@ +{ + "f0": [ + 0.0, + 0.0, + 46.64, + 46.64, + 46.64, + 46.64, + 46.64, + 46.64, + 46.64, + 46.64, + 46.4, + 46.4, + 46.62, + 46.67, + 83.1, + 83.1, + 82.97, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "outputSamplingRate": 24000, + "outputStereo": false, + "phonemes": [ + { + "frame_length": 2, + "phoneme": "pau" + }, + { + "frame_length": 8, + "phoneme": "t" + }, + { + "frame_length": 2, + "phoneme": "e" + }, + { + "frame_length": 1, + "phoneme": "s" + }, + { + "frame_length": 1, + "phoneme": "u" + }, + { + "frame_length": 2, + "phoneme": "t" + }, + { + "frame_length": 1, + "phoneme": "o" + }, + { + "frame_length": 10, + "phoneme": "pau" + } + ], + "volume": [ + 0.0, + 0.0, + 0.33, + 0.33, + 0.33, + 0.33, + 0.33, + 0.33, + 0.33, + 0.33, + 0.13, + 0.13, + 0.32, + 0.36, + 0.79, + 0.79, + 0.64, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0 + ], + "volumeScale": 1.0 +} diff --git a/test/e2e/single_api/__snapshots__/test_user_dict_word/test_post_user_dict_word.json b/test/e2e/single_api/__snapshots__/test_user_dict_word/test_post_user_dict_word.json new file mode 100644 index 000000000..edbf90748 --- /dev/null +++ b/test/e2e/single_api/__snapshots__/test_user_dict_word/test_post_user_dict_word.json @@ -0,0 +1,15 @@ +{ + "detail": [ + { + "ctx": { + "limit_value": 10 + }, + "loc": [ + "query", + "priority" + ], + "msg": "ensure this value is less than or equal to 10", + "type": "value_error.number.not_le" + } + ] +} diff --git a/test/e2e/single_api/test_accent_phrases.py b/test/e2e/single_api/test_accent_phrases.py index 96177c3cd..5b1d60001 100644 --- a/test/e2e/single_api/test_accent_phrases.py +++ b/test/e2e/single_api/test_accent_phrases.py @@ -2,11 +2,17 @@ /accent_phrases API のテスト """ +from test.utility import round_floats + from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_accent_phrases_200(client: TestClient) -> None: +def test_post_accent_phrases_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: response = client.post( "/accent_phrases", params={"text": "テストです", "speaker": 0} ) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) diff --git a/test/e2e/single_api/test_audio_query_from_preset.py b/test/e2e/single_api/test_audio_query_from_preset.py index e35779a70..ef5729ced 100644 --- a/test/e2e/single_api/test_audio_query_from_preset.py +++ b/test/e2e/single_api/test_audio_query_from_preset.py @@ -2,20 +2,29 @@ /audio_query_from_preset API のテスト """ +from test.utility import round_floats + import pytest from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion @pytest.mark.skip(reason="200の前提として別APIを要するプリセット登録が必要だから") -def test_post_audio_query_from_preset_200(client: TestClient) -> None: +def test_post_audio_query_from_preset_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: response = client.post( "/audio_query_from_preset", params={"text": "テストです", "preset_id": 0} ) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) -def test_post_audio_query_from_preset_422(client: TestClient) -> None: +def test_post_audio_query_from_preset_422( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: response = client.post( "/audio_query_from_preset", params={"text": "テストです", "preset_id": 404} ) assert response.status_code == 422 + assert snapshot_json == response.json() diff --git a/test/e2e/single_api/test_mora_data.py b/test/e2e/single_api/test_mora_data.py index 634d80be7..d5b97d7bc 100644 --- a/test/e2e/single_api/test_mora_data.py +++ b/test/e2e/single_api/test_mora_data.py @@ -3,11 +3,15 @@ """ from test.e2e.single_api.utils import gen_mora +from test.utility import round_floats from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_mora_data_200(client: TestClient) -> None: +def test_post_mora_data_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: accent_phrases = [ { "moras": [ @@ -22,3 +26,4 @@ def test_post_mora_data_200(client: TestClient) -> None: ] response = client.post("/mora_data", params={"speaker": 0}, json=accent_phrases) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) diff --git a/test/e2e/single_api/test_mora_length.py b/test/e2e/single_api/test_mora_length.py index 2d36ea874..33f6bb837 100644 --- a/test/e2e/single_api/test_mora_length.py +++ b/test/e2e/single_api/test_mora_length.py @@ -3,11 +3,15 @@ """ from test.e2e.single_api.utils import gen_mora +from test.utility import round_floats from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_mora_length_200(client: TestClient) -> None: +def test_post_mora_length_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: accent_phrases = [ { "moras": [ @@ -22,3 +26,4 @@ def test_post_mora_length_200(client: TestClient) -> None: ] response = client.post("/mora_length", params={"speaker": 0}, json=accent_phrases) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) diff --git a/test/e2e/single_api/test_mora_pitch.py b/test/e2e/single_api/test_mora_pitch.py index fea10bc96..c0fb5c9c9 100644 --- a/test/e2e/single_api/test_mora_pitch.py +++ b/test/e2e/single_api/test_mora_pitch.py @@ -3,11 +3,15 @@ """ from test.e2e.single_api.utils import gen_mora +from test.utility import round_floats from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_mora_pitch_200(client: TestClient) -> None: +def test_post_mora_pitch_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: accent_phrases = [ { "moras": [ @@ -22,3 +26,4 @@ def test_post_mora_pitch_200(client: TestClient) -> None: ] response = client.post("/mora_pitch", params={"speaker": 0}, json=accent_phrases) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) diff --git a/test/e2e/single_api/test_morphable_targets.py b/test/e2e/single_api/test_morphable_targets.py index 1b60cbcd8..d31cf594d 100644 --- a/test/e2e/single_api/test_morphable_targets.py +++ b/test/e2e/single_api/test_morphable_targets.py @@ -3,8 +3,12 @@ """ from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_morphable_targets_200(client: TestClient) -> None: +def test_post_morphable_targets_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: response = client.post("/morphable_targets", json=[0]) assert response.status_code == 200 + assert snapshot_json == response.json() diff --git a/test/e2e/single_api/test_sing_frame_audio_query.py b/test/e2e/single_api/test_sing_frame_audio_query.py index 8c74396f8..31ec684bd 100644 --- a/test/e2e/single_api/test_sing_frame_audio_query.py +++ b/test/e2e/single_api/test_sing_frame_audio_query.py @@ -2,10 +2,15 @@ /sing_frame_audio_query API のテスト """ +from test.utility import round_floats + from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_sing_frame_audio_query_200(client: TestClient) -> None: +def test_post_sing_frame_audio_query_200( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: score = { "notes": [ {"key": None, "frame_length": 10, "lyric": ""}, @@ -17,3 +22,4 @@ def test_post_sing_frame_audio_query_200(client: TestClient) -> None: } response = client.post("/sing_frame_audio_query", params={"speaker": 0}, json=score) assert response.status_code == 200 + assert snapshot_json == round_floats(response.json(), 2) diff --git a/test/e2e/single_api/test_user_dict_word.py b/test/e2e/single_api/test_user_dict_word.py index 192bfb579..492f3e915 100644 --- a/test/e2e/single_api/test_user_dict_word.py +++ b/test/e2e/single_api/test_user_dict_word.py @@ -3,9 +3,12 @@ """ from fastapi.testclient import TestClient +from syrupy.assertion import SnapshotAssertion -def test_post_user_dict_word(client: TestClient) -> None: +def test_post_user_dict_word( + client: TestClient, snapshot_json: SnapshotAssertion +) -> None: true_params: dict[str, str | int] = { "surface": "test", "pronunciation": "テスト", @@ -21,3 +24,4 @@ def test_post_user_dict_word(client: TestClient) -> None: # 範囲外の優先度はエラー response = client.post("/user_dict_word", params={**true_params, "priority": 100}) assert response.status_code == 422 + assert snapshot_json == response.json()