Skip to content

Commit

Permalink
video_port unittests in helper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Aug 8, 2013
1 parent 919b186 commit 3ca96ed
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python-api/gstswitch/exception.py
@@ -1,4 +1,7 @@
__all__ = ['BaseError', 'PathError', 'ServerProcessError', 'ConnectionError']
__all__ = [
'BaseError', 'PathError', 'ServerProcessError', 'ConnectionError',
'ConnectionReturnError', 'RangeError',
]


class BaseError(Exception):
Expand Down
24 changes: 24 additions & 0 deletions python-api/gstswitch/helpers.py
@@ -1,4 +1,5 @@
from testsource import VideoSrc, Preview
from exception import RangeError

__all__ = ["TestSources", "PreviewSinks"]

Expand All @@ -18,6 +19,29 @@ def __init__(self, video_port):
self.running_tests = []
self.video_port = video_port

@property
def video_port(self):
return self._video_port

@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")


def new_test_video(self,
width=300,
height=200,
Expand Down
31 changes: 31 additions & 0 deletions python-api/gstswitch/test_helpers.py
@@ -0,0 +1,31 @@
from helpers import TestSources, PreviewSinks
from exception import RangeError
import pytest
from mock import Mock, patch


class TestTestSourcesVideoPort(object):

def test_blank(self):
tests = ['', None, [], {}]
for test in tests:
with pytest.raises(ValueError):
TestSources(video_port=test)

def test_range(self):
tests = [-100, 1e7, 65536]
for test in tests:
with pytest.raises(RangeError):
TestSources(video_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(video_port=test)

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

0 comments on commit 3ca96ed

Please sign in to comment.