Spaces:
Sleeping
Sleeping
File size: 1,197 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 46 47 |
import pytest
from webapp.services.parsing.ds_validator import validate_ds
def test_validate_ds_valid():
# Arrange
valid_ds = {
"ph_seq": "k d e",
"ph_num": "1 1 1",
"note_seq": "C4 D4 E4",
"note_dur": "1.0 0.5 0.75",
"note_slur": "0 0 0",
"input_type": "phoneme",
}
# Act + Assert (no exception means pass)
validate_ds(valid_ds)
def test_validate_ds_missing_field():
# Arrange
invalid_ds = {
"ph_seq": "k d e",
# "ph_num" missing
"note_seq": "C4 D4 E4",
"note_dur": "1.0 0.5 0.75",
"note_slur": "0 0 0",
"input_type": "phoneme",
}
# Act + Assert
with pytest.raises(ValueError, match="Missing required field 'ph_num'"):
validate_ds(invalid_ds)
def test_validate_ds_wrong_type():
# Arrange
invalid_ds = {
"ph_seq": "k d e",
"ph_num": 3, # should be a string!
"note_seq": "C4 D4 E4",
"note_dur": "1.0 0.5 0.75",
"note_slur": "0 0 0",
"input_type": "phoneme",
}
# Act + Assert
with pytest.raises(TypeError, match="Field 'ph_num' must be a string"):
validate_ds(invalid_ds)
|