def test_batch_estimate_with_success_and_error(self): """ Test batch estimate with good and bad warp. """ badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE)) badWarp.coreImage = VLIMAGE_SMALL.coreImage with pytest.raises(LunaSDKException) as exceptionInfo: self.estimator.estimateBasicAttributesBatch( warps=[self._warp, badWarp], estimateAge=True, estimateGender=True, estimateEthnicity=True, aggregate=False, ) self.assertLunaVlError(exceptionInfo, LunaVLError.BatchedInternalError.format("Failed validation.")) assert len(exceptionInfo.value.context) == 2, "Expect two errors in exception context" self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[0], LunaVLError.Ok) self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[1], LunaVLError.InvalidImageSize)
def test_batch_detect_with_success_and_error(self): """ Test batch detection with success and error using FACE_DET_V3 (there is no error with other detector) """ badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE)) badWarp.coreImage = VLIMAGE_SMALL.coreImage for detector in self.detectors: with self.subTest(detectorType=detector.detectorType): with pytest.raises(LunaSDKException) as exceptionInfo: detector.detect( images=[VLIMAGE_ONE_FACE, VLIMAGE_BAD_IMAGE]) self.assertLunaVlError(exceptionInfo, LunaVLError.BatchedInternalError) assert len(exceptionInfo.value.context ) == 2, "Expect two errors in exception context" self.assertReceivedAndRawExpectedErrors( exceptionInfo.value.context[0], LunaVLError.Ok) self.assertReceivedAndRawExpectedErrors( exceptionInfo.value.context[1], LunaVLError.Internal)
def test_extract_descriptors_batch_positive_and_negative(self): """ Test estimate descriptor batch with one good warp and one bad (expected error). """ for case in self.cases: for planVersion in case.versions: extractor = case.extractorFactory(descriptorVersion=planVersion) for kw in (dict(), dict(descriptorBatch=self.getBatch(planVersion, len(case.warps), case.type))): for aggregate in (True, False): with self.subTest( type=case.type, plan_version=planVersion, aggregate=aggregate, external_descriptor=bool(kw) ): badWarp = FaceWarpedImage(VLImage.load(filename=WARP_CLEAN_FACE)) badWarp.coreImage = VLIMAGE_SMALL.coreImage with pytest.raises(LunaSDKException) as exceptionInfo: extractor.estimateDescriptorsBatch([case.warps[0], badWarp], aggregate=aggregate, **kw) assert len(exceptionInfo.value.context) == 2, "Expect two errors in exception context" self.assertReceivedAndRawExpectedErrors(exceptionInfo.value.context[0], LunaVLError.Ok) self.assertReceivedAndRawExpectedErrors( exceptionInfo.value.context[1], LunaVLError.InvalidImageSize )