def __helper_test_process(self, exp, cont): ''' Helper method to validate slice feature ''' if not isinstance(exp, list): exp = [exp] if not isinstance(cont, list): cont = [cont] # Create a schema validator n = len(exp) + len(cont) + 1 com_schema = { 'bounds': And([str], lambda x: len(x) == n), 'mean': And([float], lambda x: len(x) == n), 'min': And([float], lambda x: len(x) == n), 'max': And([float], lambda x: len(x) == n), 'dvh': And([np.ndarray], lambda x: len(x) == n) } validator = Schema(com_schema) # Compute features feat = VolumetricFeature('test', mask=self.mask, dose=self.dg, expand=exp, contract=cont) output = feat.process() # Check the output schema try: self.assertTrue(validator.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_process_with_dvh(self): ''' Can list specific DVH values to compute ''' # Set up a schema validator com_schema = { 'bounds': And([str], lambda x: len(x) == 1), 'mean': And([float], lambda x: len(x) == 1), 'min': And([float], lambda x: len(x) == 1), 'max': And([float], lambda x: len(x) == 1), 'dvh': And([np.ndarray], lambda x: np.all([d.shape == (6, 2) for d in x]), lambda x: len(x) == 1) } validator = Schema(com_schema) # Compute features dvh_vals = [0, 0.2, 0.4, 0.6, 0.8, 1] feat = VolumetricFeature('test', mask=self.mask, dose=self.dg, dvh=dvh_vals) output = feat.process() # Check the output schema try: self.assertTrue(validator.validate(output) is not SchemaError) except SchemaError: self.fail('Output does not match given schema')
def test_process_before_load(self): ''' Cannot process before loading data ''' feat = VolumetricFeature('test') self.assertFalse(feat.loaded) self.assertRaises(ValueError, lambda: feat.process())