Skip to content

Commit

Permalink
added missing unittests for Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Aug 23, 2013
1 parent 47cec77 commit 811502e
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 41 deletions.
2 changes: 1 addition & 1 deletion python-api/Makefile
Expand Up @@ -9,7 +9,7 @@ lint:
coverage:
mkdir -p reports
mkdir -p reports/coverage
-py.test --cov-report html --cov gstswitch -v -s
-py.test --cov-report html --cov gstswitch tests/unittests/ -v -s
mv htmlcov/*.* reports/coverage
rmdir htmlcov
rm *.data
Expand Down
62 changes: 26 additions & 36 deletions python-api/gstswitch/helpers.py
Expand Up @@ -29,43 +29,35 @@ def video_port(self):

@video_port.setter
def video_port(self, video_port):
if not video_port:
raise ValueError("video_port: '{0}' cannot be blank"
.format(video_port))
else:
try:
i = int(video_port)
if i < 1 or i > 65535:
raise RangeError('video_port must be in range 1 to 65535')
else:
self._video_port = video_port
except TypeError:
raise TypeError("video_port must be a string or number,"
"not, '{0}'".format(type(video_port)))
except ValueError:
raise TypeError("Port must be a valid number")
try:
i = int(video_port)
if i < 1 or i > 65535:
raise RangeError('video_port must be in range 1 to 65535')
else:
self._video_port = video_port
except TypeError:
raise TypeError("video_port must be a string or number,"
"not, '{0}'".format(type(video_port)))
except ValueError:
raise TypeError("Port must be a valid number")

@property
def audio(self):
return self._video_port
def audio_port(self):
return self._audio_port

@audio.setter
def audio(self, audio):
if not audio:
raise ValueError("audio: '{0}' cannot be blank"
.format(audio))
else:
try:
i = int(audio)
if i < 1 or i > 65535:
raise RangeError('audio must be in range 1 to 65535')
else:
self._video_port = audio
except TypeError:
raise TypeError("audio must be a string or number,"
"not, '{0}'".format(type(audio)))
except ValueError:
raise TypeError("Port must be a valid number")
@audio_port.setter
def audio_port(self, audio_port):
try:
i = int(audio_port)
if i < 1 or i > 65535:
raise RangeError('audio must be in range 1 to 65535')
else:
self._audio_port = audio_port
except TypeError:
raise TypeError("audio must be a string or number,"
"not, '{0}'".format(type(audio_port)))
except ValueError:
raise TypeError("Port must be a valid number")

@property
def running_tests_video(self):
Expand Down Expand Up @@ -165,8 +157,6 @@ def new_test_audio(
wave)
testsrc.run()
# print testsrc
if testsrc is None:
raise Exception("fail")
self._running_tests_audio.append(testsrc)
# print self._running_tests_audio

Expand Down
89 changes: 85 additions & 4 deletions python-api/tests/unittests/test_helpers.py
Expand Up @@ -28,6 +28,27 @@ def test_normal(self):
src = TestSources(video_port=test)
assert src.video_port == test


class TestTestSourcesAudioPort(object):

def test_range(self):
tests = [-100, 1e7, 65536]
for test in tests:
with pytest.raises(RangeError):
TestSources(audio_port=test)

def test_invalid(self):
tests = [[1, 2, 3, 4], {1: 2, 2: 3}, '1e10']
for test in tests:
with pytest.raises(TypeError):
TestSources(audio_port=test)

def test_normal(self):
tests = [1, 65535, 1000]
for test in tests:
src = TestSources(audio_port=test)
assert src.audio_port == test

class TestTestSources(object):

class MockVideoSrc(object):
Expand Down Expand Up @@ -67,31 +88,91 @@ def test_get_test_video(self):
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.get_test_video()

def test_terminate_index_error(self):
def test_terminate_index_error_video(self):
testsrc = TestSources(video_port=3000)
testsrc.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
tests = [-100, 20, 1e10, "hi", [1, 2, 3]]
for test in tests:
with pytest.raises(InvalidIndexError):
testsrc.terminate_index_video(test)

def test_terminate_index_normal(self):
def test_terminate_index_normal_video(self):
test = TestSources(video_port=3000)
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate_index_video(0)


def test_terminate1(self):
def test_terminate1_video(self):
test = TestSources(video_port=3000)
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate_video()

def test_terminate2(self):
def test_terminate2_audio(self):
test = TestSources(video_port=3000)
test.running_tests_video = []
test.terminate_video()



class MockAudioSrc(object):

def __init__(
self,
port,
freq=110,
wave=None):
pass

def run(self):
pass


def test_new_test_audio(self, monkeypatch):
test = TestSources(audio_port=3000)
monkeypatch.setattr(gstswitch.testsource, 'AudioSrc', self.MockAudioSrc)
test.new_test_audio()
assert test.running_tests_audio[0] is not None
assert len(test.running_tests_audio) != 0

class MockTest2(object):

def __init__(self, wave):
self.wave = wave

def end(self):
pass

def test_get_test_audio(self):

test = TestSources(audio_port=4000)
test.running_tests_audio = [self.MockTest2(1), self.MockTest2(2), self.MockTest2(3), self.MockTest2(10)]
test.get_test_audio()

def test_terminate_index_error_audio(self):
testsrc = TestSources(audio_port=4000)
testsrc.running_tests_audio = [self.MockTest2(1), self.MockTest2(2), self.MockTest2(3), self.MockTest2(10)]
tests = [-100, 20, 1e10, "hi", [1, 2, 3]]
for test in tests:
with pytest.raises(InvalidIndexError):
testsrc.terminate_index_audio(test)

def test_terminate_index_normal_audio(self):
test = TestSources(audio_port=4000)
test.running_tests_audio = [self.MockTest2(1), self.MockTest2(2), self.MockTest2(3), self.MockTest2(10)]
test.terminate_index_audio(0)


def test_terminate1_audio(self):
test = TestSources(audio_port=4000)
test.running_tests_audio = [self.MockTest2(1), self.MockTest2(2), self.MockTest2(3), self.MockTest2(10)]
test.terminate_audio()

def test_terminate2_audio(self):
test = TestSources(audio_port=4000)
test.running_tests_audio = []
test.terminate_audio()


class TestPreviewSinksPreviewPort(object):

def test_blank(self):
Expand Down

0 comments on commit 811502e

Please sign in to comment.