Skip to content

Commit

Permalink
Added unittest for BaseServer.set_video_port
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 16, 2013
1 parent f78f8d1 commit 6963aa5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python-api/gstswitch/server.py
Expand Up @@ -17,11 +17,19 @@ def __init__(self):

def set_video_port(self, video_port):
"""Sets the server's video port
Should be between 1 and 65535
:param video_port: Video port
:returns: nothing
"""
self.VIDEO_PORT = str(video_port)
try:
video_port + 1
except TypeError:
raise TypeError
if video_port > 0 and video_port < 65536:
self.VIDEO_PORT = str(video_port)
else:
raise ValueError('video port not in range')

def set_audio_port(self, audio_port):
"""Sets the server's audio port
Expand Down Expand Up @@ -175,7 +183,7 @@ def set_executable_path(self, path):
class Server(BaseServer, ServerProcess):
"""Controls all Server operations
:param path: Path where all exceutables gst-switch-srv, gst-launch-1.0, wtc are located
:param path: Path where all exceutables gst-switch-srv, gst-launch-1.0, etc are located
:param video_port: The video port number - default = 3000
:param audio_port: The audio port number - default = 4000
:param control_port: The control port number - default = 5000
Expand Down
47 changes: 47 additions & 0 deletions python-api/gstswitch/test_BaseServer.py
@@ -0,0 +1,47 @@
from server import BaseServer
import pytest


class TestSetVideoPort(object):

def test_negative(self):
port = -3
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_video_port(port)

def test_zero(self):
port = 0
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_video_port(port)

def test_huge(self):
port = 1e6
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_video_port(port)

def test_none(self):
port = None
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_video_port(port)

def test_string(self):
port = ""
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_video_port(port)

def test_dict(self):
port = {}
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_video_port(port)

def test_normal(self):
port = 3000
instance = BaseServer()
instance.set_video_port(port)
assert port == int(instance.VIDEO_PORT)

0 comments on commit 6963aa5

Please sign in to comment.