2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
6
+ using System . Collections . Generic ;
5
7
using System . CommandLine . Builder ;
6
8
using System . CommandLine . Invocation ;
7
9
using System . IO ;
10
+ using System . Linq ;
8
11
using Microsoft . ML . CLI . Commands ;
9
12
using Microsoft . ML . CLI . Data ;
10
13
using Microsoft . VisualStudio . TestTools . UnitTesting ;
@@ -30,6 +33,10 @@ public void TestMinimumCommandLineArgs()
30
33
// Parser
31
34
. AddCommand ( CommandDefinitions . New ( handler ) )
32
35
. UseDefaults ( )
36
+ . UseExceptionHandler ( ( e , ctx ) =>
37
+ {
38
+ Console . WriteLine ( e . ToString ( ) ) ;
39
+ } )
33
40
. Build ( ) ;
34
41
35
42
var trainDataset = Path . GetTempFileName ( ) ;
@@ -58,6 +65,10 @@ public void TestCommandLineArgsFailTest()
58
65
// parser
59
66
. AddCommand ( CommandDefinitions . New ( handler ) )
60
67
. UseDefaults ( )
68
+ . UseExceptionHandler ( ( e , ctx ) =>
69
+ {
70
+ Console . WriteLine ( e . ToString ( ) ) ;
71
+ } )
61
72
. Build ( ) ;
62
73
63
74
// Incorrect mltask test
@@ -96,29 +107,33 @@ public void TestCommandLineArgsValuesTest()
96
107
var validDataset = Path . GetTempFileName ( ) ;
97
108
var labelName = "Label" ;
98
109
var name = "testname" ;
99
- var outputPath = ". " ;
110
+ var outputPath = "x: \\ mlnet " ;
100
111
var falseString = "false" ;
101
112
102
113
// Create handler outside so that commandline and the handler is decoupled and testable.
103
114
var handler = CommandHandler . Create < NewCommandSettings > (
104
115
( opt ) =>
105
116
{
106
- parsingSuccessful = true ;
107
117
Assert . AreEqual ( opt . MlTask , "binary-classification" ) ;
108
- Assert . AreEqual ( opt . Dataset , trainDataset ) ;
109
- Assert . AreEqual ( opt . TestDataset , testDataset ) ;
110
- Assert . AreEqual ( opt . ValidationDataset , validDataset ) ;
118
+ Assert . AreEqual ( opt . Dataset . FullName , trainDataset ) ;
119
+ Assert . AreEqual ( opt . TestDataset . FullName , testDataset ) ;
120
+ Assert . AreEqual ( opt . ValidationDataset . FullName , validDataset ) ;
111
121
Assert . AreEqual ( opt . LabelColumnName , labelName ) ;
112
- Assert . AreEqual ( opt . MaxExplorationTime , 5 ) ;
122
+ Assert . AreEqual ( opt . MaxExplorationTime , ( uint ) 5 ) ;
113
123
Assert . AreEqual ( opt . Name , name ) ;
114
- Assert . AreEqual ( opt . OutputPath , outputPath ) ;
124
+ Assert . AreEqual ( opt . OutputPath . FullName , outputPath ) ;
115
125
Assert . AreEqual ( opt . HasHeader , bool . Parse ( falseString ) ) ;
126
+ parsingSuccessful = true ;
116
127
} ) ;
117
128
118
129
var parser = new CommandLineBuilder ( )
119
130
// Parser
120
131
. AddCommand ( CommandDefinitions . New ( handler ) )
121
132
. UseDefaults ( )
133
+ . UseExceptionHandler ( ( e , ctx ) =>
134
+ {
135
+ Console . WriteLine ( e . ToString ( ) ) ;
136
+ } )
122
137
. Build ( ) ;
123
138
124
139
// Incorrect mltask test
@@ -151,6 +166,10 @@ public void TestCommandLineArgsMutuallyExclusiveArgsTest()
151
166
// Parser
152
167
. AddCommand ( CommandDefinitions . New ( handler ) )
153
168
. UseDefaults ( )
169
+ . UseExceptionHandler ( ( e , ctx ) =>
170
+ {
171
+ Console . WriteLine ( e . ToString ( ) ) ;
172
+ } )
154
173
. Build ( ) ;
155
174
156
175
// Incorrect arguments : specifying dataset and train-dataset
@@ -186,17 +205,21 @@ public void CacheArgumentTest()
186
205
var handler = CommandHandler . Create < NewCommandSettings > (
187
206
( opt ) =>
188
207
{
189
- parsingSuccessful = true ;
190
208
Assert . AreEqual ( opt . MlTask , "binary-classification" ) ;
191
- Assert . AreEqual ( opt . Dataset , trainDataset ) ;
209
+ Assert . AreEqual ( opt . Dataset . FullName , trainDataset ) ;
192
210
Assert . AreEqual ( opt . LabelColumnName , labelName ) ;
193
211
Assert . AreEqual ( opt . Cache , cache ) ;
212
+ parsingSuccessful = true ;
194
213
} ) ;
195
214
196
215
var parser = new CommandLineBuilder ( )
197
216
// Parser
198
217
. AddCommand ( CommandDefinitions . New ( handler ) )
199
218
. UseDefaults ( )
219
+ . UseExceptionHandler ( ( e , ctx ) =>
220
+ {
221
+ Console . WriteLine ( e . ToString ( ) ) ;
222
+ } )
200
223
. Build ( ) ;
201
224
202
225
// valid cache test
@@ -230,5 +253,43 @@ public void CacheArgumentTest()
230
253
File . Delete ( trainDataset ) ;
231
254
File . Delete ( testDataset ) ;
232
255
}
256
+
257
+ [ TestMethod ]
258
+ public void IgnoreColumnsArgumentTest ( )
259
+ {
260
+ bool parsingSuccessful = false ;
261
+ var trainDataset = Path . GetTempFileName ( ) ;
262
+ var testDataset = Path . GetTempFileName ( ) ;
263
+ var labelName = "Label" ;
264
+
265
+ // Create handler outside so that commandline and the handler is decoupled and testable.
266
+ var handler = CommandHandler . Create < NewCommandSettings > (
267
+ ( opt ) =>
268
+ {
269
+ Assert . AreEqual ( opt . MlTask , "binary-classification" ) ;
270
+ Assert . AreEqual ( opt . Dataset . FullName , trainDataset ) ;
271
+ Assert . AreEqual ( opt . LabelColumnName , labelName ) ;
272
+ Assert . IsTrue ( opt . IgnoreColumns . SequenceEqual ( new List < string > ( ) { "a" , "b" , "c" } ) ) ;
273
+ parsingSuccessful = true ;
274
+ } ) ;
275
+
276
+ var parser = new CommandLineBuilder ( )
277
+ // Parser
278
+ . AddCommand ( CommandDefinitions . New ( handler ) )
279
+ . UseDefaults ( )
280
+ . UseExceptionHandler ( ( e , ctx ) =>
281
+ {
282
+ Console . WriteLine ( e . ToString ( ) ) ;
283
+ } )
284
+ . Build ( ) ;
285
+
286
+ // valid cache test
287
+ string [ ] args = new [ ] { "new" , "--ml-task" , "binary-classification" , "--dataset" , trainDataset , "--label-column-name" , labelName , "--ignore-columns" , "a" , "b" , "c" } ;
288
+ parser . InvokeAsync ( args ) . Wait ( ) ;
289
+ Assert . IsTrue ( parsingSuccessful ) ;
290
+
291
+ File . Delete ( trainDataset ) ;
292
+ File . Delete ( testDataset ) ;
293
+ }
233
294
}
234
295
}
0 commit comments