File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed
tests/TensorFlowSharp.Tests.CSharp Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -2929,14 +2929,28 @@ public Runner AddTarget (params TFOperation [] targets)
29292929 // Parses user strings that contain both the operation name and an index.
29302930 TFOutput ParseOutput ( string operation )
29312931 {
2932+ TFOperation tfOperation ;
29322933 var p = operation . IndexOf ( ':' ) ;
2933- if ( p != - 1 && p != operation . Length - 1 ) {
2934+ if ( p != - 1 && p != operation . Length - 1 )
2935+ {
2936+
29342937 var op = operation . Substring ( 0 , p ) ;
2935- if ( int . TryParse ( operation . Substring ( p + 1 ) , out var idx ) ) {
2936- return session . Graph [ op ] [ idx ] ;
2938+ if ( int . TryParse ( operation . Substring ( p + 1 ) , out var idx ) )
2939+ {
2940+ tfOperation = session . Graph [ op ] ;
2941+ if ( tfOperation == null )
2942+ {
2943+ throw new ArgumentOutOfRangeException ( $ "An operation named { op } is not in this graph.") ;
2944+ }
2945+ return tfOperation [ idx ] ;
29372946 }
29382947 }
2939- return session . Graph [ operation ] [ 0 ] ;
2948+ tfOperation = session . Graph [ operation ] ;
2949+ if ( tfOperation == null )
2950+ {
2951+ throw new ArgumentOutOfRangeException ( $ "An operation named { operation } is not in this graph.") ;
2952+ }
2953+ return tfOperation [ 0 ] ;
29402954 }
29412955
29422956 /// <summary>
Original file line number Diff line number Diff line change 1- using System . Linq ;
1+ using System ;
2+ using System . Linq ;
23using TensorFlow ;
34using Xunit ;
45
@@ -16,5 +17,18 @@ public void Should_ListDeviceReturnDevices ()
1617 Assert . True ( devices . Any ( ) ) ;
1718 }
1819 }
20+
21+ [ Theory ]
22+ [ InlineData ( "Placeholder" ) ]
23+ [ InlineData ( "Placeholder:0" ) ]
24+ public void ParseOutput_ThrowsForMissingOp ( string name )
25+ {
26+ using ( var graph = new TFGraph ( ) )
27+ using ( var session = new TFSession ( graph ) )
28+ {
29+ var runner = session . GetRunner ( ) ;
30+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => runner . AddInput ( name , new TFTensor ( 1 ) ) ) ;
31+ }
32+ }
1933 }
2034}
You can’t perform that action at this time.
0 commit comments