def test_action_fails(self): """Test what happens if the requested action fails""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection( return_variant=True, should_fail=True) assert controller.click_video(1, 2, 3, 4) is False
def test_action_fails(self): """Test what happens if the requested action fails""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection( return_variant=True, should_fail=True) assert controller.switch(Controller.VIDEO_CHANNEL_A, 2) is False
def switch(self, channel, port, index): """Create Controller object and call switch method""" for _ in range(self.NUM): serv = Server(path=PATH) 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: if serv.proc: poll = serv.proc.poll() print self.__class__ if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def test_normal(self): """Test if valid""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) face = [(1, 2, 3, 4), (1, 1, 1, 1)] controller.mark_tracking(face)
def permutate_adjust_pip(num, delay): """Adjust_pip num number of times""" import random video_port = 3000 serv = Server(path=PATH, video_port=video_port) try: serv.run() sources = TestSources(video_port=video_port) sources.new_test_video(pattern=6) sources.new_test_video(pattern=5) preview = PreviewSinks() preview.run() controller = Controller() for _ in range(num): xpos = random.randrange(-20, 20) ypos = random.randrange(-20, 20) res = controller.adjust_pip(xpos, ypos, 0, 0) time.sleep(delay) assert res is not None preview.terminate() sources.terminate_video() finally: if serv.proc: poll = serv.proc.poll() if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def get_encode_port(num): """Test get_encode_port - num times""" video_port = 3000 serv = Server(path=PATH, video_port=video_port) try: serv.run() sources = TestSources(video_port=video_port) sources.new_test_video() expected_res = [video_port + 2] * num controller = Controller() controller.establish_connection() res = [] for _ in range(num): res.append(controller.get_encode_port()) assert expected_res == res finally: if serv.proc: poll = serv.proc.poll() if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def test_unpack(self): """Test if unpack fails""" controller = Controller(address='unix:abstract=abcdefghijk') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) with pytest.raises(ConnectionReturnError): controller.set_composite_mode(1)
def test_unpack(self): """Test if unpack fails""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) with pytest.raises(ConnectionReturnError): controller.click_video(1, 2, 3, 4)
def get_preview_ports(num): """Get Preview Ports when num number of sources are added""" video_port = 3000 serv = Server(path=PATH, video_port=video_port) try: serv.run() sources = TestSources(video_port=video_port) expected_res = [ i for i in range(3003, 3003 + num)] controller = Controller() res = [] for _ in range(num): sources.new_test_video() controller.establish_connection() res = controller.get_preview_ports() print res assert expected_res == res finally: if serv.proc: poll = serv.proc.poll() if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def test_unpack(self): """Test if unpack fails""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) with pytest.raises(ConnectionReturnError): controller.switch(Controller.VIDEO_CHANNEL_A, 2)
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)
def test_unpack(self): """Test if unpack fails""" controller = Controller(address='unix:abstract=abcde') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(return_variant=False) with pytest.raises(ConnectionReturnError): controller.new_record()
def test_multiple_handler_calls(self, monkeypatch): """Test that the various Handler gets calles""" monkeypatch.setattr(Connection, 'connect_dbus', Mock()) controller = Controller(address='unix:abstract=abcd') signals = ('preview_port_added', 'preview_port_removed', 'new_mode_online', 'show_face_marker', 'show_track_marker', 'select_face') test_cbs = {} for signal in signals: test_cbs[signal] = Mock() getattr(controller, 'on_'+signal)(test_cbs[signal]) getattr(controller, 'on_'+signal)(test_cbs[signal]) getattr(controller, 'on_'+signal)(test_cbs[signal]) for signal in signals: controller.cb_signal_handler( None, ':0', '/us/timvideos/gstswitch/SwitchControllerInterface', 'us.timvideos.gstswitch.SwitchControllerInterface', signal, GLib.Variant('(i)', (123,)), None) for signal in signals: test_cbs[signal].assert_called_with(123) assert test_cbs[signal].call_count == 3
def test_normal(self, monkeypatch): """Test if the parameters are valid""" monkeypatch.setattr(Connection, 'connect_dbus', Mock()) monkeypatch.setattr(Connection, 'signal_subscribe', Mock()) controller = Controller(address='unix:abstract=abcd') controller.establish_connection() assert controller.connection is not None
def new_record(self): """Create a Controller object and call new_record method""" res = [] controller = Controller() for _ in range(self.NUM * self.FACTOR): res.append(controller.new_record()) return res
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)
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)
def get_audio_port(num): """Test get_audio_port""" audio_port = 8000 serv = Server(path=PATH, audio_port=audio_port) try: serv.run() sources = TestSources(audio_port=audio_port) sources.new_test_audio() expected_res = [3003] * num controller = Controller() controller.establish_connection() res = [] for _ in range(num): res.append(controller.get_audio_port()) assert expected_res == res finally: if serv.proc: poll = serv.proc.poll() if poll == -11: print("SEGMENTATION FAULT OCCURRED") print("ERROR CODE - {0}".format(poll)) serv.terminate(1) log = open('server.log') print(log.read())
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)
def do_adjust_pip(self, line): c = Controller() c.establish_connection() if len(line.split()) != 4: print "Inavlid number of arguments" return print c.adjust_pip(*map(int, line.split()))
def get_encode_port(self): """Create a Controller object and call get_encode_port method""" res = [] controller = Controller() controller.establish_connection() for _ in range(self.NUM * self.FACTOR): res.append(controller.get_encode_port()) return res
def do_switch(self, line): try: val = self.SWITCH_MAPPING[line.lower()] except KeyError: print "Invalid" return c = Controller() c.establish_connection() print c.switch(self.SWITCH_MAPPING[line.split()[0]], int(line.split()[1]))
def do_set_composite_mode(self, line): try: val = self.COMPOSITE_MAPPING[line.lower()] except KeyError: print "Invalid" return c = Controller() c.establish_connection() print c.set_composite_mode(val)
def test_signal_name_collision(self, monkeypatch): """Test that nothing happens when a signal is on the bus which name collides with an attribute also starting with 'callbacks_' """ monkeypatch.setattr(Connection, 'connect_dbus', Mock()) controller = Controller(address='unix:abstract=abcd') controller.callbacks_foobar = 123 controller.cb_signal_handler(None, ':0', '/foo/bar', 'foo.bar', 'foobar', None, None)
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) 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: if mode == 3: assert res is False else: assert res is True assert self.verify_output(mode, out_file) is True # assert expected_result == res finally: if serv.proc: poll = serv.proc.poll() print self.__class__ if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def click_video( self, xpos, ypos, width, heigth, index, generate_frames=False): """Create Controller object and call click_video method""" for _ in range(self.NUM): serv = Server(path=PATH) try: serv.run() sources = TestSources(video_port=3000) preview = PreviewSinks() preview.run() out_file = "output-{0}.data".format(index) video_sink = VideoFileSink(PATH, 3001, out_file) sources.new_test_video(pattern=4) sources.new_test_video(pattern=5) controller = Controller() time.sleep(1) res = controller.click_video(xpos, ypos, width, heigth) 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: if serv.proc: poll = serv.proc.poll() print self.__class__ if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def setup_controller(self): """Create Controller object and call setup_controller.""" self.log.info("setting up Controller") self.controller = Controller() self.log.info("connecting Controller to Server") self.controller.establish_connection() self.serv.wait_for_output('registered: ') assert self.controller.connection is not None
def test_single_handler_calls(self, monkeypatch): """Test that the various Handler gets calles""" monkeypatch.setattr(Connection, 'connect_dbus', Mock()) for signal in ('preview_port_added', 'preview_port_removed', 'new_mode_online', 'show_face_marker', 'show_track_marker', 'select_face'): test_cb = Mock() controller = Controller(address='unix:abstract=abcd') getattr(controller, 'on_'+signal)(test_cb) controller.cb_signal_handler( None, ':0', '/us/timvideos/gstswitch/SwitchControllerInterface', 'us.timvideos.gstswitch.SwitchControllerInterface', signal, GLib.Variant('(iii)', (5, 10, 20,)), None) test_cb.assert_called_once_with(5, 10, 20)
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)
def permutate_composite_mode(num, delay): """Change composite mode num number of times""" import random video_port = 3000 serv = Server(path=PATH, video_port=video_port) try: serv.run() sources = TestSources(video_port=video_port) sources.new_test_video(pattern=6) sources.new_test_video(pattern=5) preview = PreviewSinks() preview.run() controller = Controller() res = controller.set_composite_mode(0) assert res is True prev_mode = 0 for _ in range(num-1): time.sleep(delay) mode = random.randint(0,3) expected_res = bool(prev_mode ^ mode) prev_mode = mode assert expected_res == controller.set_composite_mode(mode) preview.terminate() sources.terminate_video() finally: if serv.proc: poll = serv.proc.poll() if poll == -11: print "SEGMENTATION FAULT OCCURRED" print "ERROR CODE - {0}".format(poll) serv.terminate(1) log = open('server.log') print log.read()
def test_unknown_signal_name(self, monkeypatch): """Test that nothing happens when a unknown signal is on the bus""" monkeypatch.setattr(Connection, 'connect_dbus', Mock()) controller = Controller(address='unix:abstract=abcd') controller.cb_signal_handler(None, ':0', '/foo/bar', 'foo.bar', 'foobar', None, None)
def test_address_colon(self): """Test if address has no colon""" address = 'abcdefghijk' with pytest.raises(ValueError): Controller(address=address)
def test_address_normal(self): """Test if address is valid""" address = ['tcp:host=127.0.0.1,port=5000', 'unix:temp=/tmp/abcd/xyz'] for addr in address: conn = Controller(address=addr) assert conn.address == addr
def test_unpack(self): """Test when values cant unpack""" controller = Controller(address='unix:abstract=abcdefghijk') controller.connection = MockConnection(return_variant=False) with pytest.raises(ConnectionReturnError): controller.get_compose_port()
def test_normal_unpack(self): """Test when valid""" controller = Controller(address='unix:abstract=abcdef') controller.connection = MockConnection(return_variant=True) assert controller.get_compose_port() == 3001
def test_unpack(self): """Test if unpack fails""" controller = Controller(address='unix:abstract=abcdefghijk') controller.connection = MockConnection(return_variant=False) with pytest.raises(ConnectionReturnError): controller.get_encode_port()
def test_address_null(self): """Test if address is null""" address = ['', None, [], {}] for addr in address: with pytest.raises(ValueError): Controller(address=addr)