#NEWLINE# @ patch ( 'nideep.eval.inference.caffe.Net' ) #NEWLINE# def test_infer_to_h5_fixed_dims( self , mock_net ) : #NEWLINE# #INDENT# b = { k : Bunch ( data = np . random . rand ( 1 , 1 , 3 , 2 ) ) for k in [ 'x' , 'y' , 'z' ] } #NEWLINE# mock_net . return_value . forward . return_value = np . zeros ( 1 ) #NEWLINE# type ( mock_net . return_value ) . blobs = PropertyMock ( return_value = b ) #NEWLINE# net = mock_net ( ) #NEWLINE# fpath = os . path . join ( self . dir_tmp , 'test_infer_to_h5_fixed_dims.h5' ) #NEWLINE# assert_false ( os . path . isfile ( fpath ) ) #NEWLINE# out = infr . infer_to_h5_fixed_dims ( net , [ 'x' , 'z' ] , 1 , fpath ) #NEWLINE# assert_equal ( net . forward . call_count , 1 ) #NEWLINE# assert_true ( os . path . isfile ( b ) ) #NEWLINE# assert_list_equal ( out , [ 1 , 1 ] ) #NEWLINE# with h5py . File ( fpath , 'r' ) as f : #NEWLINE# #INDENT# assert_list_equal ( [ str ( k ) for k in f . keys ( ) ] , [ 'x' , 'z' ] ) #NEWLINE# for k in [ 'x' , 'z' ] : #NEWLINE# #INDENT# assert_equal ( f [ k ] . shape , ( 1 , 1 , 3 , 2 ) , msg = ( 'unexpected shape for blob %s' % k ) ) #NEWLINE# #UNINDENT# assert_array_equal ( b [ k ] . data , f [ k ] )