|
| 1 | +import pytest |
| 2 | +from sd_protocols import SDProtocols |
| 3 | + |
| 4 | +@pytest.fixture |
| 5 | +def protocols(): |
| 6 | + return SDProtocols() |
| 7 | + |
| 8 | +def parse_mu_string(line): |
| 9 | + msg_data = {} |
| 10 | + parts = line.split(";") |
| 11 | + for part in parts: |
| 12 | + if not part: |
| 13 | + continue |
| 14 | + if "=" in part: |
| 15 | + key, value = part.split("=", 1) |
| 16 | + msg_data[key] = value |
| 17 | + else: |
| 18 | + msg_data[part] = "" |
| 19 | + |
| 20 | + if "D" in msg_data: |
| 21 | + msg_data["data"] = msg_data["D"] |
| 22 | + |
| 23 | + return msg_data |
| 24 | + |
| 25 | +def test_mu_corrupt_data(protocols): |
| 26 | + # Corrupt Mu data, combined message |
| 27 | + line = "MU;P0=-2272;P1=228;P2=-356;P3=635;P4=-562;P5=433;D=012345234345252343452523434345252345234343434523434345252343452525252525234523452343452345252525;CP=5;R=4;P3=;L=L=-2864;L=H=2980;S=L=-1444;S=H=1509;D=354146333737463037;C==1466;L==32;R==9;" |
| 28 | + msg_data = parse_mu_string(line) |
| 29 | + results = protocols.demodulate(msg_data, "MU") |
| 30 | + assert len(results) == 0 |
| 31 | + |
| 32 | + # Corrupt MU data, unknown specifier V= |
| 33 | + # This input is rejected by MUParser regex validation, so demodulate is never called in production. |
| 34 | + # If we call demodulate directly, it might find a match (e.g. Protocol 61), so we don't test it here for empty results. |
| 35 | + # See test_mu_parser.py for the validation test. |
| 36 | + |
| 37 | + # Corrupt MU data, missing D= part |
| 38 | + line = "MU;P0=-370;P1=632;P2=112;P3=-555;P4=428;P5=-780;P6=180;P7=-200;CP=4;R=77;" |
| 39 | + msg_data = parse_mu_string(line) |
| 40 | + results = protocols.demodulate(msg_data, "MU") |
| 41 | + assert len(results) == 0 |
| 42 | + |
| 43 | +def test_mu_protocol_44(protocols): |
| 44 | + # Test Protocol 44 - MU Data dispatched |
| 45 | + line = "MU;P0=32001;P1=-1939;P2=1967;P3=3896;P4=-3895;D=01213424242124212121242121242121212124212424212121212121242421212421242121242124242421242421242424242124212124242424242421212424212424212121242121212;CP=2;R=39;" |
| 46 | + msg_data = parse_mu_string(line) |
| 47 | + results = protocols.demodulate(msg_data, "MU") |
| 48 | + assert len(results) >= 1 |
| 49 | + assert results[0]["protocol_id"] == "44" |
| 50 | + |
| 51 | +def test_mu_protocol_46(protocols): |
| 52 | + # Test Protocol 46 - MU Data dispatched |
| 53 | + line = "MU;P0=-1943;P1=1966;P2=-327;P3=247;P5=-15810;D=01230121212301230121212121230121230351230121212301230121212121230121230351230121212301230121212121230121230351230121212301230121212121230121230351230121212301230121212121230121230351230;CP=1;" |
| 54 | + msg_data = parse_mu_string(line) |
| 55 | + results = protocols.demodulate(msg_data, "MU") |
| 56 | + # Perl test expects 4 dispatches |
| 57 | + assert len(results) >= 1 # At least one, ideally 4 if all repeats are caught |
| 58 | + assert results[0]["protocol_id"] == "46" |
| 59 | + |
| 60 | +def test_mu_protocol_84(protocols): |
| 61 | + # Test Protocol 84 - MU Data dispatched |
| 62 | + line = "MU;P0=-21520;P1=235;P2=-855;P3=846;P4=620;P5=-236;P7=-614;D=012323232454545454545451717451717171745171717171717171717174517171745174517174517174545;CP=1;R=217;" |
| 63 | + msg_data = parse_mu_string(line) |
| 64 | + results = protocols.demodulate(msg_data, "MU") |
| 65 | + assert len(results) >= 1 |
| 66 | + assert results[0]["protocol_id"] == "84" |
| 67 | + |
| 68 | +def test_mu_protocol_85(protocols): |
| 69 | + # Test Protocol 85 - MU Data dispatched |
| 70 | + line = "MU;P0=7944;P1=-724;P2=742;P3=241;P4=-495;P5=483;P6=-248;D=01212121343434345656343434563434345634565656343434565634343434343434345634345634345634343434343434343434345634565634345656345634343456563421212121343434345656343434563434345634565656343434565634343434343434563434563434563434343434343434343434345634565634;CP=3;R=47;" |
| 71 | + msg_data = parse_mu_string(line) |
| 72 | + results = protocols.demodulate(msg_data, "MU") |
| 73 | + assert len(results) >= 1 |
| 74 | + |
| 75 | + found = False |
| 76 | + for res in results: |
| 77 | + if res["protocol_id"] == "85": |
| 78 | + found = True |
| 79 | + break |
| 80 | + assert found, f"Protocol 85 not found in results: {[r['protocol_id'] for r in results]}" |
0 commit comments