import unittest from qlq import is_alive_reply, parse_rcon_status, humans # QL with sv_master 0 ignores getstatus/getinfo/A2S; it does answer getchallenge (real reply below). ALIVE = b"\xff\xff\xff\xffprint\nNo Steam auth token.\n" STATUS = """zmq RCON command from 3163ba8dd0fa4fab8164165fc9194153: status map: thunderstruck num score ping name lastmsg address qport rate steamid --- ----- ---- --------------- ------- --------------------- ----- ----- ----------------- 0 12 0 Hunter 0 bot 0 16384 0 1 7 48 player 0 100.64.1.2:27960 354 25000 76561198000000000 """ class Alive(unittest.TestCase): def test_challenge_reply_is_alive(self): self.assertTrue(is_alive_reply(ALIVE)) def test_garbage_is_not_alive(self): self.assertFalse(is_alive_reply(b"hello")) self.assertFalse(is_alive_reply(b"")) class RconStatus(unittest.TestCase): def test_map_and_players(self): mapname, players = parse_rcon_status(STATUS) self.assertEqual(mapname, "thunderstruck") self.assertEqual([p[2] for p in players], ["Hunter", "player"]) def test_bots_are_not_humans(self): _, players = parse_rcon_status(STATUS) self.assertEqual(humans(players), 1) def test_empty_server(self): mapname, players = parse_rcon_status(STATUS.split(" 0 12")[0]) self.assertEqual(mapname, "thunderstruck") self.assertEqual(players, []) self.assertEqual(humans(players), 0) def test_no_rcon_output_is_none(self): self.assertIsNone(parse_rcon_status("(no output: ok, or server down / map loading / wrong password)")) if __name__ == "__main__": unittest.main()