diff --git a/tests/test_pysoundio.py b/tests/test_pysoundio.py index b34a91d..19a88ea 100644 --- a/tests/test_pysoundio.py +++ b/tests/test_pysoundio.py @@ -3,7 +3,6 @@ PySoundIo Test Suite """ -import os import unittest import pysoundio import _soundiox @@ -32,8 +31,6 @@ def setUp(self): self.callback_called = False self.error_callback_called = False - self.is_travis = 'TRAVIS' in os.environ - # - Device API def test_backend_count(self): @@ -107,6 +104,11 @@ def test_bytes_per_second(self): # - Input Stream API + def fill_input_buffer(self): + data = bytearray(b'\x00' * 4096 * 8) + _soundiox.ring_buffer_write_ptr(self.sio.input_buffer, data, len(data)) + _soundiox.ring_buffer_advance_write_ptr(self.sio.input_buffer, len(data)) + def test__create_input_ring_buffer(self): capacity = 44100 * 8 self.assertIsNotNone(self.sio._create_input_ring_buffer(capacity)) @@ -115,25 +117,19 @@ def test__create_input_stream(self): self.sio.get_default_input_device() stream = self.sio._create_input_stream() self.assertIsNotNone(stream) - self.sio.input_stream = None def test__create_input_stream_blocksize(self): self.sio.block_size = 4096 self.sio.get_default_input_device() stream = self.sio._create_input_stream() self.assertIsNotNone(stream) - self.sio.input_stream = None - - def test__open_input_stream(self): - self.sio.get_default_input_device() - self.sio._create_input_stream() - self.sio._open_input_stream() def test_get_input_latency(self): self.sio.start_input_stream( sample_rate=44100, dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) + self.fill_input_buffer() self.assertIsInstance(self.sio.get_input_latency(0.2), int) def overflow_callback(self, stream): @@ -157,14 +153,16 @@ def test_start_input_stream(self): sample_rate=44100, dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) + self.fill_input_buffer() self.assertIsNotNone(self.sio.input_stream) - # def test_pause_input_stream(self): - # self.sio.start_input_stream( - # sample_rate=44100, - # dtype=pysoundio.SoundIoFormatFloat32LE, - # channels=2) - # self.sio.pause_input_stream(True) + def test_pause_input_stream(self): + self.sio.start_input_stream( + sample_rate=44100, + dtype=pysoundio.SoundIoFormatFloat32LE, + channels=2) + self.fill_input_buffer() + self.sio.pause_input_stream(True) def test_start_input_stream_device(self): self.sio.start_input_stream( @@ -172,6 +170,7 @@ def test_start_input_stream_device(self): sample_rate=44100, dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) + self.fill_input_buffer() self.assertIsNotNone(self.sio.input_stream) def test_start_input_invalid_rate(self): @@ -185,6 +184,7 @@ def test_start_input_default_rate(self): self.sio.start_input_stream( dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) + self.fill_input_buffer() self.assertIsNotNone(self.sio.input_stream) self.assertIsInstance(self.sio.sample_rate, int) @@ -199,43 +199,32 @@ def test_start_input_default_format(self): self.sio.start_input_stream( sample_rate=44100, channels=2) + self.fill_input_buffer() self.assertIsNotNone(self.sio.input_stream) self.assertIsInstance(self.sio.format, int) # -- Output Stream API - def fill_output_buffer(self): - self.sio._create_output_ring_buffer(44100 * 8) - data = bytearray(b'\x00' * 4096 * 8) - _soundiox.ring_buffer_write_ptr(self.sio.output_buffer, data, len(data)) - _soundiox.ring_buffer_advance_write_ptr(self.sio.output_buffer, len(data)) - def test__create_output_ring_buffer(self): capacity = 44100 * 8 self.assertIsNotNone(self.sio._create_output_ring_buffer(capacity)) def test__create_output_stream(self): self.sio.get_default_output_device() - self.fill_output_buffer() stream = self.sio._create_output_stream() self.assertIsNotNone(stream) - self.sio.output_stream = None def test__create_output_stream_blocksize(self): self.sio.block_size = 4096 self.sio.get_default_output_device() - self.fill_output_buffer() stream = self.sio._create_output_stream() self.assertIsNotNone(stream) - self.sio.output_stream = None def test__open_output_stream(self): self.sio.get_default_output_device() - self.fill_output_buffer() self.sio._create_output_stream() self.sio._open_output_stream() self.assertIsNotNone(self.sio.block_size) - self.sio.output_stream = None def test_clear_output_buffer(self): capacity = 44100 * 8 @@ -256,7 +245,6 @@ def test_get_output_latency(self): dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) self.assertIsInstance(self.sio.get_output_latency(0.2), int) - self.sio.output_stream = None # def test_pause_output_stream(self): # self.sio.start_output_stream( @@ -271,7 +259,6 @@ def test_start_output_stream(self): dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) self.assertIsNotNone(self.sio.output_stream) - self.sio.output_stream = None def test_start_output_stream_device(self): self.sio.start_output_stream( @@ -280,7 +267,6 @@ def test_start_output_stream_device(self): dtype=pysoundio.SoundIoFormatFloat32LE, channels=2) self.assertIsNotNone(self.sio.output_stream) - self.sio.output_stream = None def test_start_output_invalid_rate(self): with self.assertRaises(pysoundio.PySoundIoError): @@ -295,7 +281,6 @@ def test_start_output_default_rate(self): channels=2) self.assertIsNotNone(self.sio.output_stream) self.assertIsInstance(self.sio.sample_rate, int) - self.sio.output_stream = None def test_start_output_invalid_format(self): with self.assertRaises(pysoundio.PySoundIoError): @@ -310,7 +295,6 @@ def test_start_output_default_format(self): channels=2) self.assertIsNotNone(self.sio.output_stream) self.assertIsInstance(self.sio.format, int) - self.sio.output_stream = None class TestInputProcessing(unittest.TestCase): @@ -352,9 +336,6 @@ def setUp(self): self.sio.testing = True self.callback_called = False - def tearDown(self): - self.sio.close() - def callback(self, data, length): self.callback_called = True @@ -369,4 +350,3 @@ def test_write_callback(self): thread = pysoundio.pysoundio._OutputProcessingThread(parent=self.sio, block_size=4096) thread.run() self.assertTrue(self.callback_called) - self.sio.output_stream = None