def test_video_format(self): """Test video_format property""" serv = Server(path='abc') serv._start_process = Mock() serv.video_format = 'ZZZ' serv._run_process() serv._start_process.assert_called_once() assert '--video-format=ZZZ' in serv._start_process.call_args[0][0]
def test_video_format(self): """Test video_format property""" serv = Server(path="abc") serv._start_process = Mock() serv.video_format = "ZZZ" serv._run_process() serv._start_process.assert_called_once() assert "--video-format=ZZZ" in serv._start_process.call_args[0][0]
def test_option_string(self): """Test option_string property""" serv = Server(path='abc') serv._start_process = Mock() serv.gst_option_string = '-ZZZ' serv._run_process() serv._start_process.assert_called_once() assert '-ZZZ' in serv._start_process.call_args[0][0]
def test_binary_not_found(self, monkeypatch): """Test that a PathError os raised when distutils.spawn.find_executable return nothing""" monkeypatch.setattr(spawn, "find_executable", Mock(return_value="")) with pytest.raises(PathError): serv = Server() serv._run_process()
def test_option_string(self): """Test option_string property""" serv = Server(path="abc") serv._start_process = Mock() serv.gst_option_string = "-ZZZ" serv._run_process() serv._start_process.assert_called_once() assert "-ZZZ" in serv._start_process.call_args[0][0]
def test_binary_not_found(self, monkeypatch): """Test that a PathError os raised when distutils.spawn.find_executable return nothing""" monkeypatch.setattr(spawn, 'find_executable', Mock(return_value='')) with pytest.raises(PathError): serv = Server() serv._run_process()
def test_run(self): """Test the run method""" serv = Server(path='abc') serv._run_process = Mock(return_value=MockProcess()) serv.run() assert serv.pid == 1 assert serv.proc is not None
def test_run_process(self): """Test _run_process method""" serv = Server(path='abc') serv._start_process = Mock(return_value=MockProcess()) serv.gst_option_string = '' ret = serv._run_process() assert ret is not None
def test_record_file_valid_space(self): """Test if record file is valid and has a space""" def mock_method(arg): """Mocking _start_process""" return arg path = '/usr' serv = Server(path=path, record_file='record 1.data') serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --control-port=5000".split() + ["--record=record 1.data"]
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() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --control-port=5000".split()
def test_record_file_true(self): """Test if record file is True""" def mock_method(arg): """Mocking _start_process""" return arg path = '/usr' serv = Server(path=path, record_file=True) serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --control-port=5000 -r".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() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=0.0.0.0,port=5000".split()
def test_record_file_valid(self): """Test if record file is valid""" def mock_method(arg): """Mocking _start_process""" return arg path = '/usr' serv = Server(path=path, record_file="record.data") serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=0.0.0.0,port=5000 --record=record.data".split()
def test_record_file_valid(self): """Test if record file is valid""" def mock_method(arg): """Mocking _start_process""" return arg path = '/usr' serv = Server(path=path, record_file="record.data") serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=::,port=5000 --record=record.data".split()
def test_record_file_false(self): """Test if record file is False""" def mock_method(arg): """Mocking _start_process""" return arg path = "/usr" serv = Server(path=path, record_file=False) serv._start_process = mock_method assert ( serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=::,port=5000".split() )
def test_path_empty(self, monkeypatch): """Test if null path is given""" 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: serv = Server(path=path) serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=0.0.0.0,port=5000".split()
def test_path_empty(self, monkeypatch): """Test if null path is given""" 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: serv = Server(path=path) serv._start_process = mock_method assert serv._run_process() == "/usr/gst-switch-srv \ --video-input-port=3000 --audio-input-port=4000 \ --controller-address=tcp:host=::,port=5000".split()