From 49c88306a03494ee3c5a0f8233854b9d14f83545 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Oct 2025 19:08:15 +0000 Subject: [PATCH] Add tests and fix import issues for WSJT-X/JS8Call Co-authored-by: SpudGunMan <12676665+SpudGunMan@users.noreply.github.com> --- modules/radio.py | 8 ++++---- modules/test_bot.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/modules/radio.py b/modules/radio.py index 89350b6..6bc12c4 100644 --- a/modules/radio.py +++ b/modules/radio.py @@ -267,6 +267,10 @@ async def voxMonitor(): # Based on WSJT-X UDP protocol specification # Reference: https://github.com/ckuhtz/ham/blob/main/mcast/recv_decode.py +import socket +import struct +import json + wsjtx_enabled = False js8call_enabled = False wsjtx_udp_port = 2237 @@ -289,8 +293,6 @@ try: js8call_enabled = js8call_detection_enabled if wsjtx_enabled: - import socket - import struct # Parse UDP address if ':' in wsjtx_udp_server_address: wsjtx_udp_address, port_str = wsjtx_udp_server_address.split(':') @@ -298,8 +300,6 @@ try: watched_callsigns.extend(wsjtx_watched_callsigns.split(',') if wsjtx_watched_callsigns else []) if js8call_enabled: - import socket - import json # Parse TCP address for JS8Call if ':' in js8call_server_address: js8call_tcp_address, port_str = js8call_server_address.split(':') diff --git a/modules/test_bot.py b/modules/test_bot.py index 543edcd..75a1ecc 100644 --- a/modules/test_bot.py +++ b/modules/test_bot.py @@ -421,6 +421,29 @@ class TestBot(unittest.TestCase): flood_report = get_flood_openmeteo(lat, lon) self.assertIsInstance(flood_report, str) + def test_check_callsign_match(self): + # Test the callsign filtering function for WSJT-X/JS8Call + from radio import check_callsign_match + + # Test with empty filter (should match all) + self.assertTrue(check_callsign_match("CQ K7MHI CN87", [])) + + # Test exact match + self.assertTrue(check_callsign_match("CQ K7MHI CN87", ["K7MHI"])) + + # Test case insensitive match + self.assertTrue(check_callsign_match("CQ k7mhi CN87", ["K7MHI"])) + self.assertTrue(check_callsign_match("CQ K7MHI CN87", ["k7mhi"])) + + # Test no match + self.assertFalse(check_callsign_match("CQ W1AW FN31", ["K7MHI"])) + + # Test multiple callsigns + self.assertTrue(check_callsign_match("CQ W1AW FN31", ["K7MHI", "W1AW"])) + self.assertTrue(check_callsign_match("K7MHI DE W1AW", ["K7MHI", "W1AW"])) + + print("Callsign filtering tests passed") +