Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: timvideos/gst-switch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9ad663c08de3
Choose a base ref
...
head repository: timvideos/gst-switch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ff7910f1d4d7
Choose a head ref
  • 6 commits
  • 3 files changed
  • 2 contributors

Commits on Dec 15, 2014

  1. Copy the full SHA
    c74f41e View commit details

Commits on Dec 16, 2014

  1. Copy the full SHA
    fa74128 View commit details

Commits on Dec 20, 2014

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    ab70651 View commit details
  2. Unittests reflect path option

    hyades committed Dec 20, 2014
    Copy the full SHA
    aea7f1f View commit details
  3. Copy the full SHA
    3228ec8 View commit details

Commits on Dec 25, 2014

  1. Merge pull request #67 from hyades/autopath

    Detecting the path variable
    mithro committed Dec 25, 2014
    Copy the full SHA
    ff7910f View commit details
Showing with 57 additions and 22 deletions.
  1. +18 −11 python-api/gstswitch/server.py
  2. +0 −1 python-api/gstswitch/testsource.py
  3. +39 −10 python-api/tests/unittests/test_server_unit.py
29 changes: 18 additions & 11 deletions python-api/gstswitch/server.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import os
import signal
import subprocess
from distutils import spawn

from errno import ENOENT
from .exception import PathError, ServerProcessError
@@ -22,8 +23,9 @@ class Server(object):

"""Control all server related operations
:param path: Path where all executables
gst-switch-srv, gst-launch-1.0, etc are located
:param path: Path where the executable gst-switch-srv
is located. Provide the full path.
By default looks in the current $PATH.
:param video_port: The video port number - default = 3000
:param audio_port: The audio port number - default = 4000
:param control_port: The control port number - default = 5000
@@ -34,7 +36,7 @@ class Server(object):

def __init__(
self,
path,
path=None,
video_port=3000,
audio_port=4000,
control_port=5000,
@@ -47,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
@@ -68,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):
@@ -197,9 +196,17 @@ def run(self, gst_option=''):
def _run_process(self):
"""Non-public method: Runs the gst-switch-srv process
"""
cmd = self.path
cmd += """gst-switch-srv \
{0} \
cmd = ''
if not self.path:
srv_location = spawn.find_executable('gst-switch-srv')
if srv_location:
cmd = srv_location
else:
raise PathError("Cannot find gst-switch-srv in $PATH.\
Please specify the path.")
else:
cmd += os.path.join(self.path, 'gst-switch-srv')
cmd += """ {0} \
--video-input-port={1} \
--audio-input-port={2} \
--control-port={3} \
1 change: 0 additions & 1 deletion python-api/gstswitch/testsource.py
Original file line number Diff line number Diff line change
@@ -295,7 +295,6 @@ def make_xvimagesink(self):
return element



class VideoSrc(object):

"""A Test Video Source
49 changes: 39 additions & 10 deletions python-api/tests/unittests/test_server_unit.py
Original file line number Diff line number Diff line change
@@ -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


@@ -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