forked from rc/aircox
tests: playlist_import, log_archiver, sound_stats.SoxStats
This commit is contained in:
@ -1,30 +1,75 @@
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from aircox.controllers.sound_stats import SoxStats, SoundStats
|
||||
from aircox.test import Interface
|
||||
from aircox.controllers import sound_stats
|
||||
|
||||
|
||||
sox_output = """
|
||||
DC offset 0.000000\n
|
||||
Min level 0.000000\n
|
||||
Max level 0.000000\n
|
||||
Pk lev dB -inf\n
|
||||
RMS lev dB -inf\n
|
||||
RMS Pk dB -inf\n
|
||||
RMS Tr dB -inf\n
|
||||
Crest factor 1.00\n
|
||||
Flat factor 179.37\n
|
||||
Pk count 1.86G\n
|
||||
Bit-depth 0/0\n
|
||||
Num samples 930M\n
|
||||
Length s 19383.312\n
|
||||
Scale max 1.000000\n
|
||||
Window s 0.050\n
|
||||
"""
|
||||
sox_values = {
|
||||
"DC offset": 0.0,
|
||||
"Min level": 0.0,
|
||||
"Max level": 0.0,
|
||||
"Pk lev dB": float("-inf"),
|
||||
"RMS lev dB": float("-inf"),
|
||||
"RMS Pk dB": float("-inf"),
|
||||
"RMS Tr dB": float("-inf"),
|
||||
"Flat factor": 179.37,
|
||||
"length": 19383.312,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sox_stats():
|
||||
return SoxStats()
|
||||
def sox_interfaces():
|
||||
process = Interface(
|
||||
None, {"communicate": ("", sox_output.encode("utf-8"))}
|
||||
)
|
||||
subprocess = Interface.inject(
|
||||
sound_stats, "subprocess", {"Popen": lambda *_, **__: process}
|
||||
)
|
||||
yield {"process": process, "subprocess": subprocess}
|
||||
subprocess._irelease()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sound_stats():
|
||||
return SoundStats()
|
||||
def sox_stats(sox_interfaces):
|
||||
return sound_stats.SoxStats()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stats():
|
||||
return sound_stats.SoundStats()
|
||||
|
||||
|
||||
class TestSoxStats:
|
||||
def test___init__(self):
|
||||
pass
|
||||
def test_parse(self, sox_stats):
|
||||
values = sox_stats.parse(sox_output)
|
||||
assert values == sox_values
|
||||
|
||||
def test_get(self):
|
||||
pass
|
||||
|
||||
def test_parse(self):
|
||||
pass
|
||||
|
||||
def test_analyse(self):
|
||||
pass
|
||||
def test_analyse(self, sox_stats, sox_interfaces):
|
||||
sox_stats.analyse("fake_path", 1, 2)
|
||||
assert sox_interfaces["subprocess"]._trace("Popen") == (
|
||||
(["sox", "fake_path", "-n", "trim", "1", "2", "stats"],),
|
||||
{"stdout": subprocess.PIPE, "stderr": subprocess.PIPE},
|
||||
)
|
||||
assert sox_stats.values == sox_values
|
||||
|
||||
|
||||
class TestSoundStats:
|
||||
|
Reference in New Issue
Block a user