MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / test_mapping_file

Method test_mapping_file

tests/data/test_mapping_file.py:57–81  ·  view source on GitHub ↗
(self, savepath_in_metadict)

Source from the content-addressed store, hash-verified

55
56 @parameterized.expand([(True,), (False,)])
57 def test_mapping_file(self, savepath_in_metadict):
58 mapping_file_path = os.path.join(self.temp_dir, "mapping.json")
59 name = "test_image"
60 input_file = create_input_file(self.temp_dir, name)
61 output_file = os.path.join(self.temp_dir, name, name + "_trans.nii.gz")
62
63 transform = create_transform(self.temp_dir, mapping_file_path, savepath_in_metadict)
64
65 if savepath_in_metadict:
66 transform(input_file)
67 self.assertTrue(os.path.exists(mapping_file_path))
68 with open(mapping_file_path) as f:
69 mapping_data = json.load(f)
70 self.assertEqual(len(mapping_data), 1)
71 self.assertEqual(mapping_data[0]["input"], input_file)
72 self.assertEqual(mapping_data[0]["output"], output_file)
73 else:
74 with self.assertRaises(RuntimeError) as cm:
75 transform(input_file)
76 cause_exception = cm.exception.__cause__
77 self.assertIsInstance(cause_exception, KeyError)
78 self.assertIn(
79 "Missing 'saved_to' key in metadata. Check SaveImage argument 'savepath_in_metadict' is True.",
80 str(cause_exception),
81 )
82
83 def test_multiprocess_mapping_file(self):
84 num_images = 50

Callers

nothing calls this directly

Calls 3

create_transformFunction · 0.85
loadMethod · 0.80
create_input_fileFunction · 0.70

Tested by

no test coverage detected