From b5e4a4002c33d9f9a2c97184e6d9eacbeaad06a3 Mon Sep 17 00:00:00 2001 From: hyades Date: Tue, 16 Jul 2013 23:30:25 +0530 Subject: [PATCH] Added unittest for BaseServer.get_record_file --- python-api/gstswitch/server.py | 16 +++++++----- python-api/gstswitch/test_BaseServer.py | 33 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index 607005a..035c031 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -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") 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): @@ -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): @@ -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): @@ -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 diff --git a/python-api/gstswitch/test_BaseServer.py b/python-api/gstswitch/test_BaseServer.py index b5f6b36..bb8b4bb 100644 --- a/python-api/gstswitch/test_BaseServer.py +++ b/python-api/gstswitch/test_BaseServer.py @@ -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() \ No newline at end of file