Skip to content

Commit

Permalink
Added unittest for BaseServer.get_control_port
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 16, 2013
1 parent c8f2ccd commit f4ce165
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python-api/gstswitch/server.py
Expand Up @@ -112,6 +112,12 @@ def get_control_port(self):
:param: None

This comment has been minimized.

Copy link
@mithro

mithro Jul 18, 2013

Collaborator

You shouldn't be doing these checks in get_control_port.....

:returns: Control port
"""
if type(self.CONTROL_PORT) != str:

This comment has been minimized.

Copy link
@mithro

mithro Jul 18, 2013

Collaborator

Please don't check for type. Just check you can do the int() below.

raise TypeError("Control port: " + self.CONTROL_PORT + " should be a string")
try:
int(self.CONTROL_PORT)
except:
raise ValueError("Control port: " + self.CONTROL_PORT + " should have integral value")
return self.CONTROL_PORT

def get_record_file(self):
Expand Down
43 changes: 42 additions & 1 deletion python-api/gstswitch/test_BaseServer.py
Expand Up @@ -240,7 +240,7 @@ def test_normal(self):
assert port == instance.get_video_port()


class TestGetaudioPort(object):
class TestGetAudioPort(object):

def test_non_string(self):
port = 1234
Expand Down Expand Up @@ -279,3 +279,44 @@ def test_normal(self):
instance = BaseServer()
instance.AUDIO_PORT = port
assert port == instance.get_audio_port()


class TestGetControlPort(object):

def test_non_string(self):
port = 1234
instance = BaseServer()
instance.CONTROL_PORT = port
with pytest.raises(TypeError):
res = instance.get_control_port()
assert res is None

This comment has been minimized.

Copy link
@mithro

mithro Jul 18, 2013

Collaborator

Why does this fail? port=1234 looks perfectly reasonable.


def test_none(self):
port = None
instance = BaseServer()
instance.CONTROL_PORT = port
with pytest.raises(TypeError):
res = instance.get_control_port()
assert res is None

def test_zero_length_string(self):
port = ''
instance = BaseServer()
instance.CONTROL_PORT = port
with pytest.raises(ValueError):
res = instance.get_control_port()
assert res is None

def test_non_int_string(self):
port = 'abcd'
instance = BaseServer()
instance.CONTROL_PORT = port
with pytest.raises(ValueError):
res = instance.get_control_port()
assert res is None

def test_normal(self):
port = '3000'
instance = BaseServer()
instance.CONTROL_PORT = port
assert port == instance.get_control_port()

0 comments on commit f4ce165

Please sign in to comment.