cleaning up a little
This commit is contained in:
@@ -1,35 +1,46 @@
|
||||
from copy import deepcopy
|
||||
import math
|
||||
from typing import Iterator
|
||||
import pytest
|
||||
from pojagi_dsp.channel import ASignal, Constantly, Filter, FilterFunction, SignalFunction, IllegalStateError, Map
|
||||
from pojagi_dsp.channel import (
|
||||
ASignal,
|
||||
Constantly,
|
||||
Filter,
|
||||
FilterFunction,
|
||||
SignalFunction,
|
||||
IllegalStateException,
|
||||
Reduce,
|
||||
)
|
||||
from pojagi_dsp.channel.generator.sine import SineWave
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def srate(): return 44100
|
||||
def srate():
|
||||
return 44100
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def freq(): return 440
|
||||
def freq():
|
||||
return 440
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def const(srate): return Constantly(42, srate=srate)
|
||||
def const(srate):
|
||||
return Constantly(42, srate=srate)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sine(srate, freq): return SineWave(freq, srate=srate)
|
||||
def sine(srate, freq):
|
||||
return SineWave(freq, srate=srate)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sine_generator_factory(srate, freq):
|
||||
def sine():
|
||||
phase = 0.0
|
||||
inc = (2 * math.pi * freq)/srate
|
||||
inc = (2 * math.pi * freq) / srate
|
||||
while True:
|
||||
yield math.sin(phase)
|
||||
phase += inc
|
||||
|
||||
return sine
|
||||
|
||||
|
||||
@@ -73,14 +84,14 @@ def test_filter_nested_expression(const: Constantly):
|
||||
|
||||
def test_reader(const: Constantly):
|
||||
filter = Filter()
|
||||
with pytest.raises(IllegalStateError, match=".reader. is None"):
|
||||
with pytest.raises(IllegalStateException, match=".reader. is None"):
|
||||
filter.reader
|
||||
assert (const | filter).reader == const
|
||||
|
||||
|
||||
def test_pipeline_missing_reader(const: ASignal):
|
||||
pipeline = Filter | Filter | Filter
|
||||
with pytest.raises(IllegalStateError, match=".reader. is None"):
|
||||
with pytest.raises(IllegalStateException, match=".reader. is None"):
|
||||
next(pipeline)
|
||||
assert next(const | pipeline)
|
||||
|
||||
@@ -94,13 +105,13 @@ def test_filter_can_only_be_assigned_one_generator(const: Constantly):
|
||||
|
||||
def test_add_tuple(const: Constantly):
|
||||
pipeline = const + (100, 200, 300)
|
||||
assert isinstance(pipeline, Map)
|
||||
assert isinstance(pipeline, Reduce)
|
||||
assert next(pipeline) == const.constant + (100 + 200 + 300)
|
||||
|
||||
|
||||
def test_mul_tuple(const: Constantly):
|
||||
pipeline = const * (100, 200, 300)
|
||||
assert isinstance(pipeline, Map)
|
||||
assert isinstance(pipeline, Reduce)
|
||||
assert next(pipeline) == const.constant * (100 * 200 * 300)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user