Skip to content

Commit

Permalink
Added unittest for BaseServer.get_record_file
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 16, 2013
1 parent f4ce165 commit b5e4a40
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
16 changes: 10 additions & 6 deletions python-api/gstswitch/server.py
Expand Up @@ -85,11 +85,11 @@ def get_video_port(self):
:returns: Video port
"""
if type(self.VIDEO_PORT) != str:
raise TypeError("Video port: " + self.VIDEO_PORT + " should be a string")
raise TypeError("Video port: ", self.VIDEO_PORT, " should be a string")

This comment has been minimized.

Copy link
@mithro

mithro Jul 18, 2013

Collaborator

Your original code here was correct. TypeError/ValueError both should take a message string.

In [9]: a = ValueError("Hello")

In [10]: a.
a.args     a.message  

In [10]: a.args
Out[10]: ('Hello',)

In [10]: a.message
Out[10]: 'Hello'

In [11]: a = ValueError("Hello", "Testing")                                                                                                  

In [12]: a.message
Out[12]: ''

In [13]: a.args
Out[13]: ('Hello', 'Testing')

In [14]: 
try:
int(self.VIDEO_PORT)
except:
raise ValueError("Video port: " + self.VIDEO_PORT + " should have integral value")
raise ValueError("Video port: ", self.VIDEO_PORT, " should have integral value")
return self.VIDEO_PORT

def get_audio_port(self):
Expand All @@ -99,11 +99,11 @@ def get_audio_port(self):
:returns: Audio port
"""
if type(self.AUDIO_PORT) != str:
raise TypeError("audio port: " + self.AUDIO_PORT + " should be a string")
raise TypeError("audio port: ", self.AUDIO_PORT, " should be a string")
try:
int(self.AUDIO_PORT)
except:
raise ValueError("audio port: " + self.AUDIO_PORT + " should have integral value")
raise ValueError("audio port: ", self.AUDIO_PORT, " should have integral value")
return self.AUDIO_PORT

def get_control_port(self):
Expand All @@ -113,11 +113,11 @@ def get_control_port(self):
:returns: Control port
"""
if type(self.CONTROL_PORT) != str:
raise TypeError("Control port: " + self.CONTROL_PORT + " should be a string")
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")
raise ValueError("Control port: ", self.CONTROL_PORT, " should have integral value")
return self.CONTROL_PORT

def get_record_file(self):
Expand All @@ -126,6 +126,10 @@ def get_record_file(self):
:param: None
:returns: Record file format
"""
if type(self.RECORD_FILE) != str:
raise TypeError("Record File:", self.RECORD_FILE, "should be a string")
if self.RECORD_FILE.find('/') >= 0:
raise ValueError("Record file name should not have '/'")
return self.RECORD_FILE


Expand Down
33 changes: 33 additions & 0 deletions python-api/gstswitch/test_BaseServer.py
Expand Up @@ -320,3 +320,36 @@ def test_normal(self):
instance = BaseServer()
instance.CONTROL_PORT = port
assert port == instance.get_control_port()


class TestGetRecordFile(object):

def test_non_string(self):
name = 1234
instance = BaseServer()
instance.RECORD_FILE = name
with pytest.raises(TypeError):
res = instance.get_record_file()
assert res is None

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

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

def test_normal(self):
name = "recordFile"
instance = BaseServer()
instance.RECORD_FILE = name
assert name == instance.get_record_file()

0 comments on commit b5e4a40

Please sign in to comment.