@@ -21,10 +21,40 @@ namespace Microsoft.ML.AutoML.Test
2121{
2222 public class AutoFitTests : BaseTestClass
2323 {
24+ // Marker necessary for AutoFitContextLogTest to ensure that the wanted logs
25+ // from Experiment's sub MLContexts were relayed to the main calling MLContext.
26+ bool _markerAutoFitContextLogTest ;
2427 public AutoFitTests ( ITestOutputHelper output ) : base ( output )
2528 {
2629 }
2730
31+ private void MlContextLog ( object sender , LoggingEventArgs e )
32+ {
33+ // Log containing ImageClassificationTrainer will only come from AutoML's sub
34+ // contexts.
35+ if ( ! _markerAutoFitContextLogTest && e . Message . Contains ( "[Source=ImageClassificationTrainer;" ) )
36+ _markerAutoFitContextLogTest = true ;
37+ }
38+
39+ [ TensorFlowFact ]
40+ public void AutoFitContextLogTest ( )
41+ {
42+ // This test confirms that logs produced from contexts made during AutoML experiment
43+ // runs are correctly relayed to the main Experiment MLContext.
44+ _markerAutoFitContextLogTest = false ;
45+ var context = new MLContext ( 1 ) ;
46+ context . Log += MlContextLog ;
47+ var datasetPath = DatasetUtil . GetFlowersDataset ( ) ;
48+ var columnInference = context . Auto ( ) . InferColumns ( datasetPath , "Label" ) ;
49+ var textLoader = context . Data . CreateTextLoader ( columnInference . TextLoaderOptions ) ;
50+ var trainData = textLoader . Load ( datasetPath ) ;
51+ var result = context . Auto ( )
52+ . CreateMulticlassClassificationExperiment ( 15 )
53+ . Execute ( trainData , columnInference . ColumnInformation ) ;
54+ Assert . True ( _markerAutoFitContextLogTest , "Image classification trainer logs from Experiment's sub contexts" +
55+ "were not relayed to the main MLContext." ) ;
56+ }
57+
2858 [ Fact ]
2959 public void AutoFitBinaryTest ( )
3060 {
0 commit comments