From 08abe364430d16a4a6785f22faa0c04c883b0a39 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 27 Sep 2022 18:08:49 -0700 Subject: [PATCH] Fix TACAN beacon type import. The dataclass contructor will not automatically convert the int in the JSON file to the enum type, so our enum equivalence check was not actually working, and could result in us re-allocating a TACAN channel that was used by the map. Fixing this problem surfaces a latent bug, where we can't actually treat duplicate map TACAN channels as a bug because some channels are used by multiple airports in PG. --- game/dcs/beacons.py | 8 +++++++- game/radio/tacan.py | 12 ------------ tests/test_tacan.py | 6 ++---- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/game/dcs/beacons.py b/game/dcs/beacons.py index 0335238f..04b96ddc 100644 --- a/game/dcs/beacons.py +++ b/game/dcs/beacons.py @@ -84,7 +84,13 @@ class Beacons: beacons = {} for bid, beacon in json.loads(beacons_file.read_text()).items(): - beacons[bid] = Beacon(**beacon) + beacons[bid] = Beacon( + name=beacon["name"], + callsign=beacon["callsign"], + beacon_type=BeaconType(beacon["beacon_type"]), + hertz=beacon["hertz"], + channel=beacon["channel"], + ) cls._by_terrain[theater.terrain.name] = beacons @classmethod diff --git a/game/radio/tacan.py b/game/radio/tacan.py index 07eca28c..fb7bd42f 100644 --- a/game/radio/tacan.py +++ b/game/radio/tacan.py @@ -66,13 +66,6 @@ class OutOfTacanChannelsError(RuntimeError): super().__init__(f"No available channels in TACAN {band.value} band") -class TacanChannelInUseError(RuntimeError): - """Raised when attempting to reserve an in-use channel.""" - - def __init__(self, channel: TacanChannel) -> None: - super().__init__(f"{channel} is already in use") - - class TacanRegistry: """Manages allocation of TACAN channels.""" @@ -116,10 +109,5 @@ class TacanRegistry: Args: channel: The channel to reserve. - - Raises: - TacanChannelInUseError: The given channel is already in use. """ - if channel in self.allocated_channels: - raise TacanChannelInUseError(channel) self.allocated_channels.add(channel) diff --git a/tests/test_tacan.py b/tests/test_tacan.py index 5f2179e4..0b1e4b23 100644 --- a/tests/test_tacan.py +++ b/tests/test_tacan.py @@ -4,7 +4,6 @@ from game.radio.tacan import ( OutOfTacanChannelsError, TacanBand, TacanChannel, - TacanChannelInUseError, TacanRegistry, TacanUsage, ) @@ -72,9 +71,8 @@ def test_reserve_all_valid_a2a() -> None: def test_reserve_again() -> None: registry = TacanRegistry() - with pytest.raises(TacanChannelInUseError): - registry.mark_unavailable(TacanChannel(1, TacanBand.X)) - registry.mark_unavailable(TacanChannel(1, TacanBand.X)) + registry.mark_unavailable(TacanChannel(1, TacanBand.X)) + registry.mark_unavailable(TacanChannel(1, TacanBand.X)) def test_tacan_parsing() -> None: