Skip to content

Commit

Permalink
Unittests reflect path option
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Dec 20, 2014
1 parent ab70651 commit aea7f1f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
9 changes: 3 additions & 6 deletions python-api/gstswitch/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
self._audio_port = None
self._control_port = None
self._record_file = None
self.gst_option_string = None
self.gst_option_string = ''

self.path = path
self.video_port = video_port
Expand All @@ -70,10 +70,7 @@ def path(self, path):
"""Set path
:raises ValueError: Path cannot be left blank
"""
if not path:
raise ValueError("Path '{0}' cannot be blank".format(path))
else:
self._path = path
self._path = path

@property
def video_port(self):
Expand Down Expand Up @@ -200,7 +197,7 @@ def _run_process(self):
"""Non-public method: Runs the gst-switch-srv process
"""
cmd = ''
if self.path is None:
if not self.path:
srv_location = spawn.find_executable('gst-switch-srv')
if srv_location:
cmd = '/'.join(srv_location.split('/')[:-1])
Expand Down
1 change: 0 additions & 1 deletion python-api/gstswitch/testsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def make_xvimagesink(self):
return element



class VideoSrc(object):

"""A Test Video Source
Expand Down
49 changes: 39 additions & 10 deletions python-api/tests/unittests/test_server_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from gstswitch.server import Server
import pytest
from gstswitch.exception import ServerProcessError, PathError
from gstswitch.exception import ServerProcessError
import subprocess
from distutils import spawn
from mock import Mock


Expand All @@ -18,23 +19,51 @@ class TestPath(object):
"""Test the path parameter"""
# Path Tests

def test_invalid_path(self):
"""Test if path specified does not have executables"""
def test_path_provided_slash(self):
"""Test if a path is provided"""
def mock_method(arg):
"""Mocking _start_process"""
return arg
path = '/usr/'
serv = Server(path=path)
with pytest.raises(PathError):
serv.run()
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()

def test_path_provided_no_slash(self):
"""Test if a path is provided"""
def mock_method(arg):
"""Mocking _start_process"""
return arg
path = '/usr'
serv = Server(path=path)
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()

def test_invalid_path_none(self):
def test_path_empty(self, monkeypatch):
"""Test if null path is given"""
paths = [None, '', [], {}]

def mock_method(arg):
"Mocking _start_process"
return arg

def mockreturn(path):
"Mocking distutils.spawn.find_executable"
return '/usr/gst-switch-srv'
monkeypatch.setattr(spawn, 'find_executable', mockreturn)
paths = [None, '']
for path in paths:
with pytest.raises(ValueError):
Server(path=path)
serv = Server(path=path)
serv._start_process = mock_method
assert serv._run_process().split() == "/usr/gst-switch-srv \
--video-input-port=3000 --audio-input-port=4000 \
--control-port=5000 --record=record.data".split()


class TestVideoPort(object):

"""Test for video_port parameter"""
# Video Port Tests

Expand Down

0 comments on commit aea7f1f

Please sign in to comment.