dcs-retribution/tests/test_radios.py
Dan Albert 011d8a4e12 Export airfield data to yaml, switch to ID keys.
This exports all the old AIRFIELD_DATA to yaml files. It's easier for
users to send fixes if it's defined this way, and they can also fix it
in their install without having to wait for a new release.

This also switches the indexes from the unstable DCS airfield names to
airfield IDs, so this fixes another case of DCS updates occasionally
breaking Liberation.

I also ended up finding quite a few typos in airfield names, and
incorrect theater names in the process. Those have been fixed.
2022-02-11 01:39:57 -08:00

37 lines
1.5 KiB
Python

from typing import Callable
import pytest
from game.radio.radios import MHz, RadioFrequency, kHz
@pytest.mark.parametrize("units,factory", [("kHz", kHz), ("MHz", MHz)])
def test_radio_parsing(units: str, factory: Callable[..., RadioFrequency]) -> None:
assert RadioFrequency.parse(f"0 {units}") == factory(0)
assert RadioFrequency.parse(f"0.0 {units}") == factory(0)
assert RadioFrequency.parse(f"255 {units}") == factory(255)
assert RadioFrequency.parse(f"255.5 {units}") == factory(255, 500)
assert RadioFrequency.parse(f"255.500 {units}") == factory(255, 500)
assert RadioFrequency.parse(f"255.050 {units}") == factory(255, 50)
assert RadioFrequency.parse(f"255.005 {units}") == factory(255, 5)
assert RadioFrequency.parse(f"255.0 {units}") == factory(255)
with pytest.raises(ValueError):
RadioFrequency.parse("")
with pytest.raises(ValueError):
RadioFrequency.parse("255")
with pytest.raises(ValueError):
RadioFrequency.parse(f" 255 {units}")
with pytest.raises(ValueError):
RadioFrequency.parse(f"255 {units} ")
with pytest.raises(ValueError):
RadioFrequency.parse(f"255 {units.lower()}")
with pytest.raises(ValueError):
RadioFrequency.parse(f"255. {units}")
with pytest.raises(ValueError):
RadioFrequency.parse(f".0 {units}")
with pytest.raises(ValueError):
RadioFrequency.parse(f"0. {units}")
with pytest.raises(ValueError):
RadioFrequency.parse(f"255.5555 {units}")