def test_DataParser_save_sample(self): data_parser = DataParser(' ') data_parser.set_result_path(self._result_path) for line in self._link: try: """ generate results """ dicom_file_path = os.path.join(self._data_path, line) contour_file_path = os.path.join(self._data_path, self._link[line]) shape, img, mask, contour = data_parser.parse_sample( dicom_file_path, contour_file_path) data_parser.save_sample( os.path.splitext(line)[0], shape, img, mask, contour) """ Load baseline and do the comparison """ with h5py.File(os.path.join(self._baseline_path, 'data.h5'), 'r') as hf: sample = hf[os.path.splitext(line)[0]] equal1 = np.array_equal(np.array(sample['shape']), shape) equal2 = np.array_equal(np.array(sample['img']), img) equal3 = np.array_equal(np.array(sample['mask']), mask) if (not (equal1 and equal2 and equal3)): return False except: return False return True
def test_DataParser_parse_sample(self): data_parser = DataParser(' ') for line in self._link: try: """ generate results """ dicom_file_path = os.path.join(self._data_path, line) contour_file_path = os.path.join(self._data_path, self._link[line]) shape, img, mask, contour = data_parser.parse_sample( dicom_file_path, contour_file_path) np.savez(os.path.join(self._result_path, os.path.splitext(line)[0]) + '.npz', shape=shape, img=img, mask=mask, contour=contour) """ Load baseline and do the comparison """ baseline = np.load( os.path.join(self._baseline_path, os.path.splitext(line)[0]) + '.npz') equal1 = np.array_equal(baseline['shape'], shape) equal2 = np.array_equal(baseline['img'], img) equal3 = np.array_equal(baseline['mask'], mask) equal4 = np.array_equal(baseline['contour'], contour) if (not (equal1 and equal2 and equal3 and equal4)): return False except: return False return True