File size: 1,348 Bytes
c42fe7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest
from pathlib import Path
from unittest.mock import patch

from webapp.services.parsing.mei_parser import parse_mei_for_editor

@patch("webapp.services.parsing.mei_parser._parse_mei_raw")
def test_parse_mei_for_editor_basic(mock_parse_mei_raw):
    # Arrange: mock what _parse_mei_raw would return
    mock_parse_mei_raw.return_value = {
        "notes": ["C4", "D4", "E4"],
        "durations": [1.0, 0.5, 0.75],
        "lyrics": "do re mi"
    }
    
    dummy_path = Path("/fake/path/to/file.mei")
    tempo = 120

    # Act
    result = parse_mei_for_editor(dummy_path, tempo)

    # Assert
    expected = [
        {"id": "note_0", "pitch": "C4", "duration": 1.0, "lyric": "do"},
        {"id": "note_1", "pitch": "D4", "duration": 0.5, "lyric": "re"},
        {"id": "note_2", "pitch": "E4", "duration": 0.75, "lyric": "mi"},
    ]
    assert result == expected

def test_parse_mei_for_editor_empty(monkeypatch):
    # Arrange: _parse_mei_raw returns empty
    def mock_parse_mei_raw(mei_path, tempo):
        return {"notes": [], "durations": [], "lyrics": ""}

    monkeypatch.setattr("webapp.services.parsing.mei_parser._parse_mei_raw", mock_parse_mei_raw)

    dummy_path = Path("/fake/path/to/empty.mei")
    tempo = 120

    # Act
    result = parse_mei_for_editor(dummy_path, tempo)

    # Assert
    assert result == []