( self, inputfile, tests )
| 89 | self.__testCrop( inputFile , tests ) |
| 90 | |
| 91 | def __testCrop( self, inputfile, tests ): |
| 92 | r = IECore.Reader.create(inputfile) |
| 93 | img = r.read() |
| 94 | self.assertEqual(type(img), IECoreImage.ImagePrimitive) |
| 95 | |
| 96 | cropOp = IECoreImage.ImageCropOp() |
| 97 | errors = [] |
| 98 | |
| 99 | testIdx = 0 |
| 100 | for testCase in tests: |
| 101 | testIdx = testIdx + 1 |
| 102 | cropOp['copyInput'] = True |
| 103 | cropOp['cropBox'] = testCase['cropBox'] |
| 104 | cropOp['matchDataWindow'] = testCase.get( 'matchDataWindow', True ) |
| 105 | resetOrigin = testCase.get( 'resetOrigin', True ) |
| 106 | cropOp['resetOrigin'] = resetOrigin |
| 107 | cropOp['extendDataWindow'] = False |
| 108 | cropOp['input'] = img |
| 109 | |
| 110 | croppedImg = cropOp() |
| 111 | |
| 112 | if not croppedImg.channelsValid(): |
| 113 | raise Exception( |
| 114 | "Invalid cropped image in test case: " + str(testCase) + |
| 115 | ". Image info (displayWindow, dataWindow,bufferSize): " + |
| 116 | str( croppedImg.displayWindow) + ", " + str( croppedImg.dataWindow ) |
| 117 | + ", " + str( len(croppedImg["R"]) ) |
| 118 | ) |
| 119 | |
| 120 | #Uncomment to generate missing expected result files |
| 121 | #if not os.path.exists( testCase['checkFile'] ) : |
| 122 | # IECore.Writer.create( croppedImg, testCase['checkFile'] ).write() |
| 123 | |
| 124 | expectedImg = IECore.Reader.create( testCase['checkFile'] ).read() |
| 125 | |
| 126 | expectedImg.blindData().clear() |
| 127 | croppedImg.blindData().clear() |
| 128 | |
| 129 | if croppedImg == expectedImg : |
| 130 | |
| 131 | continue |
| 132 | |
| 133 | errors.append( "Crop test case failed:" + str(testCase) + ". Cropped image: " + str(croppedImg.displayWindow) + " " + str(croppedImg.dataWindow) + " Loaded image: " + str(expectedImg.displayWindow) + " " + str(expectedImg.dataWindow) ) |
| 134 | |
| 135 | if len(errors): |
| 136 | raise Exception( "\n".join( errors ) ) |
| 137 | |
| 138 | def testDefaults( self ) : |
| 139 |
no test coverage detected