def test_move_bad(self, onvifmock): """If the camera fails to respond to a move command, RuntimeError is raised.""" camera = IPCamera('192.0.2.123', 9160, 'root', 'hunter2') ptzmock = Mock() ptzmock.AbsoluteMove.side_effect = ONVIFError('Simulated PTZ Error') camera.ptz_service = ptzmock with self.assertRaises(RuntimeError): camera.move_to(180, 45)
def camera_control(camera_host, camera_port, camera_user, camera_pass, q): """Control a maho.Camera based on inputs from a multiprocessing queue" On startup this function will place the stream_url in the queue if camera communication works. If it fails the exception for why will be placed in the queue before exiting """ try: camera = IPCamera(camera_host, camera_port, camera_user, camera_pass) q.put(camera.get_rtsp_url()) except RuntimeError as exc: q.put(exc) try: while True: camera.move_to(*q.get()) except KeyboardInterrupt: pass
def test_move_good(self, onvifmock): """Camera handles good and oob coordinates when moving""" camera = IPCamera('192.0.2.123', 9160, 'root', 'hunter2') ptzmock = Mock() camera.ptz_service = ptzmock self.assertEqual((180, 45), camera.move_to(180, 45)) # if offsets are provided, the camera returns the actual location moved to # altitude is capped at 0-9, but azimuth with loop around camera.azimuth_offset = 10.0 camera.altitude_offset = 10.0 self.assertEqual((10, 90), camera.move_to(360, 81)) # negative offsets work too camera.azimuth_offset = -10.0 camera.altitude_offset = -10.0 self.assertEqual((355, 35), camera.move_to(5, 45)) self.assertEqual((80, 0), camera.move_to(90, 5))