Skip to content

Commit

Permalink
Added unittest for BaseServer.set_audio_port
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 16, 2013
1 parent 6963aa5 commit 761fd99
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python-api/gstswitch/server.py
Expand Up @@ -37,7 +37,14 @@ def set_audio_port(self, audio_port):
:param audio_port: Audio port
:returns: nothing
"""
self.AUDIO_PORT = str(audio_port)
try:
audio_port + 1
except TypeError:
raise TypeError
if audio_port > 0 and audio_port < 65536:
self.AUDIO_PORT = str(audio_port)
else:
raise ValueError('audio port not in range')

def set_control_port(self, control_port):
"""Sets the server's control port
Expand Down
45 changes: 45 additions & 0 deletions python-api/gstswitch/test_BaseServer.py
Expand Up @@ -45,3 +45,48 @@ def test_normal(self):
instance = BaseServer()
instance.set_video_port(port)
assert port == int(instance.VIDEO_PORT)


class TestSetAudioPort(object):

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

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

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

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

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

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

def test_normal(self):
port = 3000
instance = BaseServer()
instance.set_audio_port(port)
assert port == int(instance.AUDIO_PORT)

0 comments on commit 761fd99

Please sign in to comment.