Exemple #1
0
 def test_raises_oserror(self):
     """Test what happens when ProcessMonitor raises an OSError"""
     with patch('gstswitch.server.ProcessMonitor') as mock:
         mock.side_effect = OSError()
         serv = Server(path='abc')
         with pytest.raises(ServerProcessError):
             serv._start_process('cmd')
Exemple #2
0
 def test_log_to_stderr(self):
     """Test log_to_file=False property"""
     with patch('gstswitch.server.ProcessMonitor') as mock:
         serv = Server(path='abc')
         serv.log_to_file = False
         serv._start_process('cmd')
         mock.assert_called_with('cmd')
 def test_raises_enoent(self):
     """Test what happens when ProcessMonitor raises an OSError ENOENT"""
     with patch("gstswitch.server.ProcessMonitor") as mock:
         mock.side_effect = OSError(ENOENT, "not found")
         serv = Server(path="abc")
         with pytest.raises(PathError):
             serv._start_process("cmd")
 def test_start_process_error(self, monkeypatch):
     """Test _start_process method"""
     with patch("subprocess.Popen.__init__") as mock:
         mock.side_effect = OSError
         serv = Server(path="abc")
         with pytest.raises(ServerProcessError):
             serv._start_process("def")
Exemple #5
0
 def test_raises_enoent(self):
     """Test what happens when ProcessMonitor raises an OSError ENOENT"""
     with patch('gstswitch.server.ProcessMonitor') as mock:
         mock.side_effect = OSError(ENOENT, "not found")
         serv = Server(path='abc')
         with pytest.raises(PathError):
             serv._start_process('cmd')
 def test_raises_oserror(self):
     """Test what happens when ProcessMonitor raises an OSError"""
     with patch("gstswitch.server.ProcessMonitor") as mock:
         mock.side_effect = OSError()
         serv = Server(path="abc")
         with pytest.raises(ServerProcessError):
             serv._start_process("cmd")
Exemple #7
0
 def test_start_process_error(self, monkeypatch):
     """Test _start_process method"""
     with patch('subprocess.Popen.__init__') as mock:
         mock.side_effect = OSError
         serv = Server(path='abc')
         with pytest.raises(ServerProcessError):
             serv._start_process('def')
 def test_log_to_stderr(self):
     """Test log_to_file=False property"""
     with patch("gstswitch.server.ProcessMonitor") as mock:
         serv = Server(path="abc")
         serv.log_to_file = False
         serv._start_process("cmd")
         mock.assert_called_with("cmd")
 def test_start_process_normal(self, monkeypatch):
     """Test _start_process normally"""
     serv = Server(path='abc')
     monkeypatch.setattr(
         subprocess,
         'Popen',
         Mock(return_value=MockProcess()))
     serv._start_process('cmd')
Exemple #10
0
 def test_start_process_normal(self, monkeypatch):
     """Test _start_process normally"""
     serv = Server(path='abc')
     monkeypatch.setattr(
         subprocess,
         'Popen',
         Mock(return_value=MockProcess()))
     serv._start_process('cmd')
 def test_log_to_file(self):
     """Test log_to_file=True property"""
     with patch("gstswitch.server.open", create=True) as mock_open:
         mock_open.return_value = 123
         with patch("gstswitch.server.ProcessMonitor") as mock:
             serv = Server(path="abc")
             serv.log_to_file = True
             serv._start_process("cmd")
             mock.assert_called_with("cmd", 123)
Exemple #12
0
 def test_log_to_file(self):
     """Test log_to_file=True property"""
     with patch('gstswitch.server.open', create=True) as mock_open:
         mock_open.return_value = 123
         with patch('gstswitch.server.ProcessMonitor') as mock:
             serv = Server(path='abc')
             serv.log_to_file = True
             serv._start_process('cmd')
             mock.assert_called_with('cmd', 123)
Exemple #13
0
 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
Exemple #14
0
 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
Exemple #15
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]
Exemple #16
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_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_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]
Exemple #19
0
    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()
Exemple #20
0
    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"]
Exemple #21
0
    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()
Exemple #22
0
    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()
Exemple #23
0
    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()
Exemple #24
0
    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()
        )
Exemple #26
0
    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()
Exemple #27
0
    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()
Exemple #28
0
 def test_start_process_error(self, monkeypatch):
     """Test _start_process method"""
     serv = Server(path='abc')
     monkeypatch.setattr(subprocess, 'Popen', Mock(side_effect=OSError))
     with pytest.raises(ServerProcessError):
         serv._start_process('cmd')
Exemple #29
0
 def test_start_process_error(self, monkeypatch):
     """Test _start_process method"""
     serv = Server(path='abc')
     monkeypatch.setattr(subprocess, 'Popen', Mock(side_effect=OSError))
     with pytest.raises(ServerProcessError):
         serv._start_process('cmd')
 def test_start_process_normal(self, monkeypatch):
     """Test _start_process normally"""
     with patch("subprocess.Popen.__init__") as mock:
         mock.return_value = MockProcess()
         serv = Server(path="abc")
         serv._start_process("def")
Exemple #31
0
 def test_start_process_normal(self, monkeypatch):
     """Test _start_process normally"""
     with patch('subprocess.Popen.__init__') as mock:
         mock.return_value = MockProcess()
         serv = Server(path='abc')
         serv._start_process('def')