Skip to content

Commit

Permalink
Added unittest for BaseServer.get_video_port
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 16, 2013
1 parent a403b96 commit 9335989
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 24 deletions.
8 changes: 7 additions & 1 deletion python-api/gstswitch/server.py
Expand Up @@ -64,7 +64,7 @@ def set_control_port(self, control_port):
raise ValueError('control port not in range')

def set_record_file(self, record_file):
"""Sets the record file name format - [name-date-time.datas]
"""Sets the record file name format - [name-date-time.data]
:param record_file: The record file name
:returns: nothing
Expand All @@ -84,6 +84,12 @@ def get_video_port(self):
:param: None
:returns: Video port
"""
if type(self.VIDEO_PORT) != str:
raise TypeError("Video port: " + self.VIDEO_PORT + " should be a string")
try:
int(self.VIDEO_PORT)
except:
raise ValueError("Video port: " + self.VIDEO_PORT + " should have integral value")
return self.VIDEO_PORT

def get_audio_port(self):
Expand Down
109 changes: 86 additions & 23 deletions python-api/gstswitch/test_BaseServer.py
Expand Up @@ -8,37 +8,43 @@ def test_negative(self):
port = -3
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_video_port(port)
res = instance.set_video_port(port)
assert res is None

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

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

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

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

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

def test_normal(self):
port = 3000
Expand All @@ -53,37 +59,43 @@ def test_negative(self):
port = -3
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_audio_port(port)
res = instance.set_audio_port(port)
assert res is None

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

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

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

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

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

def test_normal(self):
port = 3000
Expand All @@ -98,37 +110,43 @@ def test_negative(self):
port = -3
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_control_port(port)
res = instance.set_control_port(port)
assert res is None

def test_zero(self):
port = 0
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_control_port(port)
res = instance.set_control_port(port)
assert res is None

def test_huge(self):
port = 1e6
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_control_port(port)
res = instance.set_control_port(port)
assert res is None

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

def test_string(self):
port = ""
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_control_port(port)
res = instance.set_control_port(port)
assert res is None

def test_dict(self):
port = {}
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_control_port(port)
res = instance.set_control_port(port)
assert res is None

def test_normal(self):
port = 3000
Expand All @@ -143,35 +161,80 @@ def test_int(self):
name = 1234
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_record_file(name)
res = instance.set_record_file(name)
assert res is None

def test_dict(self):
name = {1: 5, 2: 7}
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_record_file(name)
res = instance.set_record_file(name)
assert res is None

def test_none(self):
name = None
instance = BaseServer()
with pytest.raises(TypeError):
instance.set_record_file(name)
res = instance.set_record_file(name)
assert res is None

def test_zero_length(self):
name = ''
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_record_file(name)
res = instance.set_record_file(name)
assert res is None

def test_forward_slash(self):
name = 'abcd/xyz'
instance = BaseServer()
with pytest.raises(ValueError):
instance.set_record_file(name)
res = instance.set_record_file(name)
assert res is None

def test_normal(self):
name = "record1234"
instance = BaseServer()
instance.set_record_file(name)
assert name == instance.RECORD_FILE


class TestGetVideoPort(object):

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

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

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

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

def test_normal(self):
port = '3000'
instance = BaseServer()
instance.VIDEO_PORT = port
assert port == instance.get_video_port()

0 comments on commit 9335989

Please sign in to comment.