def test_preprocess_task(self): # The uploaded image should start out not preprocessed. # Otherwise, we need to change the setup code so that # the prepared image has preprocessed == False. self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, False) # Run task, attempt 1. result = PreprocessImages.delay(self.image_id) # Check that the task didn't encounter an exception self.assertTrue(result.successful()) # Should be preprocessed, and process_date should be set self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, True) process_date = Image.objects.get(pk=self.image_id).process_date self.assertNotEqual(process_date, None) # Run task, attempt 2. result = PreprocessImages.delay(self.image_id) # Check that the task didn't encounter an exception self.assertTrue(result.successful()) # Should have exited without re-doing the preprocess self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, True) # process_date should have stayed the same self.assertEqual(Image.objects.get(pk=self.image_id).process_date, process_date)
def test_make_features_task(self): # Preprocess the image first. result = PreprocessImages.delay(self.image_id) self.assertTrue(result.successful()) self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, True) # Sanity check: features have not been made yet self.assertEqual(Image.objects.get(pk=self.image_id).status.featuresExtracted, False) # Run task, attempt 1. result = MakeFeatures.delay(self.image_id) # Check that the task didn't encounter an exception self.assertTrue(result.successful()) # Should have extracted features self.assertEqual(Image.objects.get(pk=self.image_id).status.featuresExtracted, True) # Run task, attempt 2. result = MakeFeatures.delay(self.image_id) # Check that the task didn't encounter an exception self.assertTrue(result.successful()) # Should have exited without re-doing the feature making # TODO: Check file ctime/mtime to check that it wasn't redone? self.assertEqual(Image.objects.get(pk=self.image_id).status.featuresExtracted, True) # def test_add_feature_labels_task(self): # # Preprocess and feature-extract first. # result = PreprocessImages.delay(self.image_id) # self.assertTrue(result.successful()) # self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, True) # result = MakeFeatures.delay(self.image_id) # self.assertTrue(result.successful()) # self.assertEqual(Image.objects.get(pk=self.image_id).status.featuresExtracted, True) # # # TODO: The image needs to be human annotated first. # # # Sanity check: haven't added labels to features yet # self.assertEqual(Image.objects.get(pk=self.image_id).status.featureFileHasHumanLabels, False) # # # Run task, attempt 1. # result = addLabelsToFeatures.delay(self.image_id) # # Check that the task didn't encounter an exception # self.assertTrue(result.successful()) # # # Should have added labels to features # # TODO: Check file ctime/mtime to check that the file was changed # self.assertEqual(Image.objects.get(pk=self.image_id).status.featureFileHasHumanLabels, True) # # # Run task, attempt 2. # result = addLabelsToFeatures.delay(self.image_id) # # Check that the task didn't encounter an exception # self.assertTrue(result.successful()) # # # Should have exited without re-doing label adding # # TODO: Check file ctime/mtime to check that it wasn't redone? # self.assertEqual(Image.objects.get(pk=self.image_id).status.featureFileHasHumanLabels, True) # # def test_train_robot_task(self): # # TODO # #trainRobot # pass # # def test_classify_task(self): # # Preprocess and feature-extract first. # result = PreprocessImages.delay(self.image_id) # self.assertTrue(result.successful()) # self.assertEqual(Image.objects.get(pk=self.image_id).status.preprocessed, True) # result = MakeFeatures.delay(self.image_id) # self.assertTrue(result.successful()) # self.assertEqual(Image.objects.get(pk=self.image_id).status.featuresExtracted, True) # # # TODO: Do other preparation tasks. # # # Sanity check: not classified yet # self.assertEqual(Image.objects.get(pk=self.image_id).status.annotatedByRobot, False) # # # Run task, attempt 1. # result = Classify.delay(self.image_id) # # Check that the task didn't encounter an exception # self.assertTrue(result.successful()) # # # Should have classified the image # self.assertEqual(Image.objects.get(pk=self.image_id).status.annotatedByRobot, True) # # # Run task, attempt 2. # result = Classify.delay(self.image_id) # # Check that the task didn't encounter an exception # self.assertTrue(result.successful()) # # # Should have exited without re-doing the classification # # TODO: Check file ctime/mtime to check that it wasn't redone? # self.assertEqual(Image.objects.get(pk=self.image_id).status.annotatedByRobot, True)