Skip to content

Commit d45238a

Browse files
committed
Update VisualRecognitionRC tests to consolidate ifdefs
1 parent 54e9335 commit d45238a

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

Scripts/UnitTests/TestVisualRecognitionRC.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
*/
1717

1818
// Uncomment to train a new classifier
19-
//#define TRAIN_CLASSIFIER
20-
// Uncommnent to delete the trained classifier
21-
//#define DELETE_TRAINED_CLASSIFIER
19+
#define TRAIN_DELETE_CLASSIFIER
2220
// Uncomment to test RC
2321
#define TEST_RC
2422

@@ -45,25 +43,25 @@ public class TestVisualRecognitionRC : UnitTest
4543
private string _classifierID = "";
4644
private string _imageURL = "https://upload.wikimedia.org/wikipedia/commons/e/e9/Official_portrait_of_Barack_Obama.jpg";
4745

48-
#if DELETE_TRAINED_CLASSIFIER
46+
#if TRAIN_DELETE_CLASSIFIER
4947
private string _classifierToDelete;
5048
#endif
5149

5250
private bool _getClassifiersTested = false;
53-
#if TRAIN_CLASSIFIER
51+
#if TRAIN_DELETE_CLASSIFIER
5452
private bool _trainClassifierTested = false;
5553
private bool _getClassifierTested = false;
5654
private bool _getCoreMLModelTested = false;
5755
#endif
58-
#if DELETE_TRAINED_CLASSIFIER
56+
#if TRAIN_DELETE_CLASSIFIER
5957
private bool _deleteClassifierTested = false;
58+
private bool _isClassifierReady = false;
6059
#endif
6160
private bool _classifyGetTested = false;
6261
private bool _classifyPostTested = false;
6362
private bool _detectFacesGetTested = false;
6463
private bool _detectFacesPostTested = false;
6564

66-
private bool _isClassifierReady = false;
6765

6866
public override IEnumerator RunTest()
6967
{
@@ -122,7 +120,7 @@ public override IEnumerator RunTest()
122120
while (!_getClassifiersTested)
123121
yield return null;
124122

125-
#if TRAIN_CLASSIFIER
123+
#if TRAIN_DELETE_CLASSIFIER
126124
_isClassifierReady = false;
127125
// Train classifier
128126
Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier");
@@ -181,7 +179,7 @@ public override IEnumerator RunTest()
181179
while (!_detectFacesPostTested)
182180
yield return null;
183181

184-
#if DELETE_TRAINED_CLASSIFIER
182+
#if TRAIN_DELETE_CLASSIFIER
185183
Runnable.Run(IsClassifierReady(_classifierToDelete));
186184
while (!_isClassifierReady)
187185
yield return null;
@@ -213,32 +211,27 @@ private void OnGetClassifiers(ClassifiersBrief classifiers, Dictionary<string, o
213211
_getClassifiersTested = true;
214212
}
215213

216-
#if DELETE_TRAINED_CLASSIFIER
214+
#if TRAIN_DELETE_CLASSIFIER
217215
private void OnGetClassifier(ClassifierVerbose classifier, Dictionary<string, object> customData)
218216
{
219217
Log.Debug("TestVisualRecognition.OnGetClassifier()", "VisualRecognition - GetClassifier Response: {0}", customData["json"].ToString());
220218
Test(classifier != null);
221219
_getClassifierTested = true;
222220
}
223-
#endif
224221

225-
#if DELETE_TRAINED_CLASSIFIER
226222
private void OnDeleteClassifier(bool success, Dictionary<string, object> customData)
227223
{
228224
Log.Debug("TestVisualRecognition.OnDeleteClassifier()", "VisualRecognition - DeleteClassifier Response: {0}", success);
229225
Test(success);
230226
_deleteClassifierTested = true;
231227
}
232-
#endif
233228

234-
#if TRAIN_CLASSIFIER
235229
private void OnTrainClassifier(ClassifierVerbose classifier, Dictionary<string, object> customData)
236230
{
237231
Log.Debug("TestVisualRecognition.OnTrainClassifier()", "VisualRecognition - TrainClassifier Response: {0}", customData["json"].ToString());
238232

239-
#if DELETE_TRAINED_CLASSIFIER
240233
_classifierToDelete = classifier.classifier_id;
241-
#endif
234+
242235
_classifierID = classifier.classifier_id;
243236
Test(classifier != null);
244237
_trainClassifierTested = true;
@@ -274,15 +267,13 @@ private void OnDetectFacesPost(DetectedFaces multipleImages, Dictionary<string,
274267
_detectFacesPostTested = true;
275268
}
276269

277-
#if DELETE_TRAINED_CLASSIFIER
270+
#if TRAIN_DELETE_CLASSIFIER
278271
private void OnGetCoreMLModel(byte[] resp, Dictionary<string, object> customData)
279272
{
280273
Test(resp != null);
281274
_getCoreMLModelTested = true;
282275
}
283-
#endif
284276

285-
#if DELETE_TRAINED_CLASSIFIER
286277
#region Is Classifier Ready
287278
// Checking if classifier is ready before deletion due to a known bug in the Visual Recognition service where
288279
// if a classifier is deleted before it is `ready` or `failed` the classifier will still exist in object storage

0 commit comments

Comments
 (0)