Skip to content

Commit

Permalink
Merge 3d57c91 into 2d831a8
Browse files Browse the repository at this point in the history
  • Loading branch information
joextodd committed Apr 8, 2018
2 parents 2d831a8 + 3d57c91 commit 1af64f1
Showing 1 changed file with 17 additions and 37 deletions.
54 changes: 17 additions & 37 deletions tests/test_pysoundio.py
Expand Up @@ -3,7 +3,6 @@
PySoundIo Test Suite
"""
import os
import unittest
import pysoundio
import _soundiox
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand All @@ -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):
Expand All @@ -157,21 +153,24 @@ 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(
device_id=0,
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):
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit 1af64f1

Please sign in to comment.