forked from rc/aircox
write tests for SoundStat
This commit is contained in:
@@ -55,7 +55,20 @@ def sox_stats(sox_interfaces):
|
||||
|
||||
@pytest.fixture
|
||||
def stats():
|
||||
return sound_stats.SoundStats()
|
||||
return sound_stats.SoundStats("/tmp/audio.wav", sample_length=10)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stats_interfaces(stats):
|
||||
def iw(path, **kw):
|
||||
kw["path"] = path
|
||||
kw.setdefault("length", stats.sample_length * 2)
|
||||
return kw
|
||||
|
||||
SxS = sound_stats.SoxStats
|
||||
sound_stats.SoxStats = iw
|
||||
yield iw
|
||||
sound_stats.SoxStats = SxS
|
||||
|
||||
|
||||
class TestSoxStats:
|
||||
@@ -73,20 +86,38 @@ class TestSoxStats:
|
||||
|
||||
|
||||
class TestSoundStats:
|
||||
def test___init__(self):
|
||||
pass
|
||||
def test_get_file_stats(self, stats):
|
||||
file_stats = {"a": 134}
|
||||
stats.stats = [file_stats]
|
||||
assert stats.get_file_stats() is file_stats
|
||||
|
||||
def test_get_file_stats(self):
|
||||
pass
|
||||
def test_get_file_stats_none(self, stats):
|
||||
stats.stats = []
|
||||
assert stats.get_file_stats() is None
|
||||
|
||||
def test_analyze(self):
|
||||
pass
|
||||
def test_analyse(self, stats, stats_interfaces):
|
||||
stats.analyse()
|
||||
assert stats.stats == [
|
||||
{"path": stats.path, "length": stats.sample_length * 2},
|
||||
{"path": stats.path, "at": 0, "length": stats.sample_length},
|
||||
{"path": stats.path, "at": 10, "length": stats.sample_length},
|
||||
]
|
||||
|
||||
def test_analyze_no_sample_length(self):
|
||||
pass
|
||||
def test_analyse_no_sample_length(self, stats, stats_interfaces):
|
||||
stats.sample_length = 0
|
||||
stats.analyse()
|
||||
assert stats.stats == [{"length": 0, "path": stats.path}]
|
||||
|
||||
def test_check(self):
|
||||
pass
|
||||
def test_check(self, stats):
|
||||
good = [{"val": i} for i in range(0, 11)]
|
||||
bad = [{"val": i} for i in range(-10, 0)] + [
|
||||
{"val": i} for i in range(11, 20)
|
||||
]
|
||||
stats.stats = good + bad
|
||||
calls = {}
|
||||
stats.resume = lambda *_: calls.setdefault("resume", True)
|
||||
stats.check("val", 0, 10)
|
||||
|
||||
def test_resume(self):
|
||||
pass
|
||||
assert calls == {"resume": True}
|
||||
assert all(i < len(good) for i in stats.good)
|
||||
assert all(i >= len(good) for i in stats.bad)
|
||||
|
||||
Reference in New Issue
Block a user