Esempio n. 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')
Esempio n. 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')
Esempio n. 3
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")
Esempio n. 4
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")
Esempio n. 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')
Esempio n. 6
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")
Esempio n. 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')
Esempio n. 8
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")
Esempio n. 9
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')
Esempio n. 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')
Esempio n. 11
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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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]
Esempio n. 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]
Esempio n. 17
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]
Esempio n. 18
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]
Esempio n. 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()
Esempio n. 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"]
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 25
0
    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()
        )
Esempio n. 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()
Esempio n. 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()
Esempio n. 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')
Esempio n. 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')
Esempio n. 30
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")
Esempio n. 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')