adding unit tests of streamer

This commit is contained in:
evilchili 2024-03-17 14:44:36 -07:00
parent a5cf97870b
commit 4ee4fb4a73
6 changed files with 46 additions and 30 deletions

View File

@ -33,6 +33,8 @@ class RequestHandler(socketserver.StreamRequestHandler):
"STFU": " - Terminate the Croaker server."
}
should_listen = True
def handle(self):
"""
Start a command and control session. Commands are read one line at a
@ -69,6 +71,8 @@ class RequestHandler(socketserver.StreamRequestHandler):
if not handler:
self.send(f"ERR No handler for {cmd}.")
handler(args)
if not self.should_listen:
break
def send(self, msg):
return self.wfile.write(msg.encode() + b"\n")

View File

@ -45,10 +45,14 @@ class AudioStreamer(threading.Thread):
s.audio_info = {shout.SHOUT_AI_BITRATE: "192", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "5"}
return s
def run(self):
def run(self): # pragma: no cover
self._shout.open()
logger.debug(f"Connnected to shoutcast server at {self._shout.host}:{self._shout.port}")
while True:
self.do_one_loop()
self._shout.close()
def do_one_loop(self):
# If the user said STOP, clear the queue.
if self.stop_requested.is_set():
@ -76,9 +80,8 @@ class AudioStreamer(threading.Thread):
self.silence.seek(0, 0)
self._shout.set_metadata({"song": '[NOTHING PLAYING]'})
self.play_from_stream(self.silence)
except Exception as exc:
except Exception as exc: # pragma: no cover
logger.error("Caught exception trying to loop silence!", exc_info=exc)
self._shout.close()
def clear_queue(self):
logger.debug("Clearing queue...")

View File

@ -8,3 +8,9 @@ def mock_env(monkeypatch):
fixtures = Path(__file__).parent / 'fixtures'
monkeypatch.setenv('CROAKER_ROOT', str(fixtures))
monkeypatch.setenv('MEDIA_GLOB', '*.mp3,*.foo,*.bar')
monkeypatch.setenv('ICECAST_URL', 'http://127.0.0.1')
monkeypatch.setenv('ICECAST_HOST', 'localhost')
monkeypatch.setenv('ICECAST_MOUNT', 'mount')
monkeypatch.setenv('ICECAST_PORT', '6523')
monkeypatch.setenv('ICECAST_PASSWORD', 'password')
monkeypatch.setenv('DEBUG', '1')

View File

@ -0,0 +1 @@
_theme.mp3

View File

@ -0,0 +1 @@
one.mp3

View File

@ -0,0 +1 @@
two.mp3