adding unit tests of streamer
This commit is contained in:
parent
a5cf97870b
commit
4ee4fb4a73
|
@ -33,6 +33,8 @@ class RequestHandler(socketserver.StreamRequestHandler):
|
||||||
"STFU": " - Terminate the Croaker server."
|
"STFU": " - Terminate the Croaker server."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
should_listen = True
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
"""
|
"""
|
||||||
Start a command and control session. Commands are read one line at a
|
Start a command and control session. Commands are read one line at a
|
||||||
|
@ -69,6 +71,8 @@ class RequestHandler(socketserver.StreamRequestHandler):
|
||||||
if not handler:
|
if not handler:
|
||||||
self.send(f"ERR No handler for {cmd}.")
|
self.send(f"ERR No handler for {cmd}.")
|
||||||
handler(args)
|
handler(args)
|
||||||
|
if not self.should_listen:
|
||||||
|
break
|
||||||
|
|
||||||
def send(self, msg):
|
def send(self, msg):
|
||||||
return self.wfile.write(msg.encode() + b"\n")
|
return self.wfile.write(msg.encode() + b"\n")
|
||||||
|
|
|
@ -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"}
|
s.audio_info = {shout.SHOUT_AI_BITRATE: "192", shout.SHOUT_AI_SAMPLERATE: "44100", shout.SHOUT_AI_CHANNELS: "5"}
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def run(self):
|
def run(self): # pragma: no cover
|
||||||
self._shout.open()
|
self._shout.open()
|
||||||
logger.debug(f"Connnected to shoutcast server at {self._shout.host}:{self._shout.port}")
|
logger.debug(f"Connnected to shoutcast server at {self._shout.host}:{self._shout.port}")
|
||||||
while True:
|
while True:
|
||||||
|
self.do_one_loop()
|
||||||
|
self._shout.close()
|
||||||
|
|
||||||
|
def do_one_loop(self):
|
||||||
|
|
||||||
# If the user said STOP, clear the queue.
|
# If the user said STOP, clear the queue.
|
||||||
if self.stop_requested.is_set():
|
if self.stop_requested.is_set():
|
||||||
|
@ -76,9 +80,8 @@ class AudioStreamer(threading.Thread):
|
||||||
self.silence.seek(0, 0)
|
self.silence.seek(0, 0)
|
||||||
self._shout.set_metadata({"song": '[NOTHING PLAYING]'})
|
self._shout.set_metadata({"song": '[NOTHING PLAYING]'})
|
||||||
self.play_from_stream(self.silence)
|
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)
|
logger.error("Caught exception trying to loop silence!", exc_info=exc)
|
||||||
self._shout.close()
|
|
||||||
|
|
||||||
def clear_queue(self):
|
def clear_queue(self):
|
||||||
logger.debug("Clearing queue...")
|
logger.debug("Clearing queue...")
|
||||||
|
|
|
@ -8,3 +8,9 @@ def mock_env(monkeypatch):
|
||||||
fixtures = Path(__file__).parent / 'fixtures'
|
fixtures = Path(__file__).parent / 'fixtures'
|
||||||
monkeypatch.setenv('CROAKER_ROOT', str(fixtures))
|
monkeypatch.setenv('CROAKER_ROOT', str(fixtures))
|
||||||
monkeypatch.setenv('MEDIA_GLOB', '*.mp3,*.foo,*.bar')
|
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')
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
_theme.mp3
|
|
@ -0,0 +1 @@
|
||||||
|
one.mp3
|
|
@ -0,0 +1 @@
|
||||||
|
two.mp3
|
Loading…
Reference in New Issue
Block a user