-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_audio_utils.py
More file actions
32 lines (26 loc) · 1022 Bytes
/
test_audio_utils.py
File metadata and controls
32 lines (26 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
test_audio_utils.py
Unit tests for audio_utils.py helper functions.
"""
import unittest
import datetime
from audio_utils import rms_to_dbfs, create_audio_plot, list_devices
class TestAudioUtils(unittest.TestCase):
def test_rms_to_dbfs_zero(self):
self.assertAlmostEqual(rms_to_dbfs(0), -240.0, delta=1.0)
def test_rms_to_dbfs_typical(self):
self.assertAlmostEqual(rms_to_dbfs(1.0), 0.0, delta=0.01)
self.assertTrue(rms_to_dbfs(0.5) < 0.0)
def test_create_audio_plot_empty(self):
self.assertIsNone(create_audio_plot([]))
def test_create_audio_plot_valid(self):
now = datetime.datetime.now()
history = [(now, -10.0), (now, -20.0), (now, -30.0)]
img_bytes = create_audio_plot(history)
self.assertIsInstance(img_bytes, (bytes, type(None)))
def test_list_devices(self):
result = list_devices()
self.assertIsInstance(result, str)
self.assertTrue(len(result) > 0)
if __name__ == "__main__":
unittest.main()