Exemple #1
0
    def mark_tracking(self, faces, index, generate_frames=False):
        """Create Controller object and call mark_tracking method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000)
                preview = PreviewSinks()
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(3001, out_file)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                controller = Controller()
                time.sleep(1)
                res = controller.mark_tracking(faces)
                print(res)
                time.sleep(1)
                sources.terminate_video()
                preview.terminate()
                video_sink.terminate()
                serv.terminate(1)
                if not generate_frames:
                    assert res is not None
                    assert self.verify_output(index, out_file) is True

            finally:
                serv.terminate_and_output_status(cov=True)
Exemple #2
0
    def switch(self, channel, port, index):
        """Create Controller object and call switch method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()

                sources = TestSources(3000)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                preview = PreviewSinks(3001)
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(3001, out_file)
                time.sleep(3)
                controller = Controller()
                res = controller.switch(channel, port)
                print(res)
                time.sleep(3)
                video_sink.terminate()
                sources.terminate_video()
                preview.terminate()
                serv.terminate(1)

            finally:
                serv.terminate_and_output_status(cov=True)
Exemple #3
0
    def test_on_preview_port_added(self):
        """Create a Controller object, call add a source method and
        check that the callback fires
        """
        serv = Server(path=PATH, video_port=3000)
        try:
            serv.run()

            controller = Controller()
            controller.establish_connection()

            test_cb = Mock(side_effect=lambda mode, serve, type:
                           self.quit_mainloop_after(2))
            controller.on_preview_port_added(test_cb)

            sources = TestSources(video_port=3000)
            sources.new_test_video()
            sources.new_test_video()

            GLib.timeout_add_seconds(5, self.quit_mainloop)
            self.run_mainloop()

            print(test_cb.call_args_list)
            test_cb.assert_any_call(3003, 1, 7)
            test_cb.assert_any_call(3004, 1, 8)
            assert test_cb.call_count == 2

            serv.terminate(1)
        finally:
            serv.terminate_and_output_status(cov=True)
Exemple #4
0
    def adjust_pip(self,
                   xpos,
                   ypos,
                   width,
                   heigth,
                   index,
                   generate_frames=False):
        """Create Controller object and call adjust_pip"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000)
                preview = PreviewSinks()
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(3001, out_file)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                controller = Controller()
                controller.set_composite_mode(Controller.COMPOSITE_PIP)
                time.sleep(3)
                res = controller.adjust_pip(xpos, ypos, width, heigth)
                time.sleep(3)
                sources.terminate_video()
                preview.terminate()
                video_sink.terminate()
                serv.terminate(1)
                if not generate_frames:
                    assert res is not None
                    assert self.verify_output(index, out_file) is True

            finally:
                serv.terminate_and_output_status(cov=True)
Exemple #5
0
 def test_establish(self):
     """Test for establish_connection"""
     serv = Server(path=PATH, video_format="debug")
     try:
         serv.run()
         for i in range(self.NUM):
             print(i)
             self.establish_connection()
         serv.terminate(1)
     finally:
         serv.terminate_and_output_status(cov=True)
Exemple #6
0
    def set_composite_mode(self, mode, generate_frames=False):
        """Create Controller object and call set_composite_mode method"""
        for _ in range(self.NUM):

            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()

                preview = PreviewSinks()
                preview.run()

                out_file = 'output-{0}.data'.format(mode)
                video_sink = VideoFileSink(serv.video_port + 1, out_file)

                sources = TestSources(video_port=3000)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)

                time.sleep(3)
                # expected_result = [mode != 3] * self.FACTOR
                # print(mode, expected_result)
                controller = Controller()
                res = controller.set_composite_mode(mode)
                print(res)
                time.sleep(3)
                video_sink.terminate()
                preview.terminate()
                sources.terminate_video()
                serv.terminate(1)
                if not generate_frames:
                    controller = Controller()
                    if mode == Controller.COMPOSITE_DUAL_EQUAL:
                        assert res is False
                    else:
                        assert res is True
                    assert self.verify_output(mode, out_file) is True
                # assert expected_result == res

            finally:
                serv.terminate_and_output_status(cov=True)
Exemple #7
0
    def test_compose_ports(self):
        """Test get_compose_port"""
        res = []
        expected_result = []
        for i in range(self.NUM):
            video_port = (i + 7) * 1000
            expected_result.append([video_port + 1] * self.NUM * self.FACTOR)
            serv = Server(path=PATH, video_port=video_port)
            try:
                serv.run()
                sources = TestSources(video_port=video_port)
                sources.new_test_video()
                sources.new_test_video()

                res.append(self.get_compose_port())
                sources.terminate_video()
                serv.terminate(1)
            finally:
                serv.terminate_and_output_status(cov=True)

        set_expected = [tuple(i) for i in expected_result]
        set_res = [tuple(i) for i in res]
        assert set(set_expected) == set(set_res)
Exemple #8
0
    def test_new_record(self):
        """Test new_record"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, record_file="test-%Y.data",
                          video_format="debug")
            try:
                serv.run()

                sources = TestSources(video_port=3000)
                sources.new_test_video()
                sources.new_test_video()

                curr_time = datetime.datetime.now()
                time_str = curr_time.strftime('%Y')
                test_filename = "test-{0}.data".format(time_str)

                res = self.new_record()
                print(res)
                sources.terminate_video()
                serv.terminate(1)
                assert os.path.exists(test_filename) is True
            finally:
                serv.terminate_and_output_status(cov=True)
Exemple #9
0
    def test_on_new_mode_online(self):
        """Create a Controller object, call on_new_mode_online method and
        check that the callback fires
        """
        serv = Server(path=PATH)
        try:
            serv.run()

            controller = Controller()
            controller.establish_connection()

            test_cb = Mock(side_effect=self.quit_mainloop)
            controller.on_new_mode_online(test_cb)
            controller.set_composite_mode(0)

            GLib.timeout_add_seconds(5, self.quit_mainloop)
            self.run_mainloop()

            test_cb.assert_called_once_with(0)

            serv.terminate(1)
        finally:
            serv.terminate_and_output_status(cov=True)
Exemple #10
0
    def test_get_preview_ports(self):
        """Test get_preview_ports"""

        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=4000)
                for _ in range(self.NUM):
                    sources.new_test_audio()
                    sources.new_test_video()
                expected_result = map(
                    tuple,
                    [[x for x in range(3003, 3004 + self.NUM)]] *
                    self.NUM * self.FACTOR)
                res = map(tuple, self.get_preview_ports())
                print('\n', res, '\n')
                print(expected_result)
                assert set(expected_result) == set(res)
                sources.terminate_video()
                sources.terminate_audio()
                serv.terminate(1)
            finally:
                serv.terminate_and_output_status(cov=True)