#NEWLINE# def test_camera_init( ) : #NEWLINE# #INDENT# with mock . patch ( 'picamera.camera.bcm_host' ) as bcm_host , mock . patch ( 'picamera.camera.mmal' ) as mmal , mock . patch ( 'picamera.camera.ct' ) as ct : #NEWLINE# #INDENT# mmal . mmal_component_create . return_value = 1 #NEWLINE# with pytest . raises ( picamera . PiCameraError ) as e : #NEWLINE# #INDENT# picamera . PiCamera ( ) #NEWLINE# #UNINDENT# assert e . value . args [ 0 ] . startswith ( 'Failed to create camera component' ) #NEWLINE# mmal . mmal_component_create . return_value = 0 #NEWLINE# ct . POINTER . return_value . return_value [ 0 ] . output_num = 0 #NEWLINE# ct . sizeof . return_value = 0 #NEWLINE# with pytest . raises ( picamera . PiCameraError ) as e : #NEWLINE# #INDENT# picamera . PiCamera ( ) #NEWLINE# #UNINDENT# assert ( e . value . args [ 0 ] == "Camera doesn't have output ports" ) #NEWLINE# ct . POINTER . return_value . return_value [ 0 ] . output_num = 3 #NEWLINE# mmal . mmal_port_parameter_set . side_effect = [ 0 , 0 , 0 , 1 ] #NEWLINE# with pytest . raises ( picamera . PiCameraError ) as e : #NEWLINE# #INDENT# picamera . PiCamera ( ) #NEWLINE# #UNINDENT# assert e . value . args [ 0 ] . startswith ( 'Unable to select camera 0' ) #NEWLINE# mmal . mmal_port_parameter_set . side_effect = None #NEWLINE# mmal . mmal_port_parameter_set . return_value = 0 #NEWLINE# mmal . mmal_port_enable . return_value = 1 #NEWLINE# with pytest . raises ( picamera . PiCameraError ) as e : #NEWLINE# #INDENT# picamera . PiCamera ( ) #NEWLINE# #UNINDENT# assert e . value . args [ 0 ] . startswith ( 'Unable to enable control port' ) #NEWLINE# mmal . mmal_port_enable . return_value = 0 #NEWLINE# mmal . mmal_port_format_commit . return_value = 0 #NEWLINE# for p in picamera . PiCamera . CAMERA_PORTS : #NEWLINE# #INDENT# ct . POINTER . return_value . return_value [ 0 ] . output [ p ] [ 0 ] . buffer_num = 1 #NEWLINE# #UNINDENT# mmal . mmal_component_enable . return_value = 1 #NEWLINE# with pytest . raises ( picamera . PiCameraError ) as e : #NEWLINE# #INDENT# picamera . PiCamera ( ) #NEWLINE# #UNINDENT# assert e . value . args [ 0 ] . startswith ( "Camera component couldn't be enabled" )