Skip to content

Commit

Permalink
Expose is_playing; add tests around stop/start exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Nov 5, 2023
1 parent 67c1810 commit 53c5c49
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from signalflow import SineOscillator, AudioGraph, Line, SIGNALFLOW_MAX_CHANNELS
from signalflow import NodeAlreadyPlayingException, NodeNotPlayingException
import signalflow as sf
import numpy as np
from . import graph
Expand Down Expand Up @@ -137,3 +138,36 @@ def test_node_trigger(graph):
node.output_buffer[0][-1] = 0
graph.render()
assert np.all(env.output_buffer[0] < 1.0)

def test_node_play_stop_exceptions(graph):
node = SineOscillator(440)
node.play()
graph.render()
with pytest.raises(NodeAlreadyPlayingException):
node.play()
node.stop()
graph.render()
with pytest.raises(NodeNotPlayingException):
node.stop()

def test_node_is_playing(graph):
node = SineOscillator(440)
assert node.is_playing is False
node.play()
graph.render()
assert node.is_playing is True
node.stop()
# graph.render() is needed because node disconnection only happens
# during the render process
graph.render()
assert node.is_playing is False

def test_node_outputs(graph):
node = SineOscillator(440)
assert len(node.outputs) == 0
node.play()
graph.render()
assert len(node.outputs) == 1
node.stop()
graph.render()
assert len(node.outputs) == 0

0 comments on commit 53c5c49

Please sign in to comment.