def test_dynalog_loading(self): a_file = osp.join(TEST_DIR, 'dlogs', 'Adlog1.dlg') MachineLog(a_file) b_file = osp.join(TEST_DIR, 'dlogs', 'Bdlog1.dlg') MachineLog(b_file) a_but_not_b_dir = osp.join(TEST_DIR, 'a_no_b_dir', 'Adlog1.dlg') self.assertRaises(FileNotFoundError, MachineLog, a_but_not_b_dir) b_but_not_a_dir = osp.join(TEST_DIR, 'b_no_a_dir', 'Bdlog1.dlg') self.assertRaises(FileNotFoundError, MachineLog, b_but_not_a_dir) bad_name_dlg = osp.join(TEST_DIR, 'bad_names', 'bad_name_dlg.dlg') self.assertRaises(ValueError, MachineLog, bad_name_dlg)
def test_txt_file_also_loads_if_around(self): # has a .txt file log_with_txt = osp.join( TEST_DIR, 'mixed_types', "Anonymous_4DC Treatment_JST90_TX_20140712094246.bin") log = MachineLog(log_with_txt) self.assertTrue(hasattr(log, 'txt')) self.assertIsInstance(log.txt, dict) self.assertEqual(log.txt['Patient ID'], 'Anonymous') # DOESN'T have a txt file log_no_txt = osp.join( TEST_DIR, 'tlogs', "Anonymous_4DC Treatment_JS0_TX_20140712095629.bin") log = MachineLog(log_no_txt) self.assertFalse(hasattr(log, 'txt'))
def test_trajectorylog(self): tlog_file = osp.join( self.anon_folder, 'PatientID_4DC Treatment_JST90_TX_20140712094246.bin') tlog = MachineLog(tlog_file) tlog.anonymize() files = tlog.anonymize(inplace=True, suffix='inplace') self.assertIsInstance(files, list) for file in files: self.assertTrue('inplace' in file)
def test_dynalog(self): # test making an anonymized copy dlog_file = osp.join(self.anon_folder, 'A1234_patientid.dlg') dlog = MachineLog(dlog_file) dlog.anonymize() # test doing inplace anonymization files = dlog.anonymize(inplace=True, suffix='inplace') self.assertIsInstance(files, list) for file in files: self.assertTrue('inplace' in file)
def test_loading(self): """Test that loading the badly-named dynalog still loads and identifies properly.""" test_tlog = osp.join( TEST_DIR, 'tlogs', "Anonymous_4DC Treatment_JS0_TX_20140712095629.bin") # should produce no errors MachineLog(test_tlog) # throw an error for files that aren't logs not_a_file = test_tlog.replace(".bin", 'blahblah.bin') self.assertRaises(IOError, MachineLog, not_a_file) not_a_log = osp.join(osp.dirname(__file__), 'test_files', 'VMAT', 'DRGSmlc-105-example.dcm') self.assertRaises(IOError, MachineLog, not_a_log)
def test_append(self): # append a directory logs = MachineLogs(self.logs_altdir) logs.append(self.logs_altdir) self.assertEqual(logs.num_logs, 8) # append a file string single_file = osp.join( self.logs_altdir, 'Anonymous_4DC Treatment_JST90_TX_20140712094246.bin') logs.append(single_file) # append a MachineLog single_log = MachineLog(single_file) logs.append(single_log) # try to append something that's not a Log log = None with self.assertRaises(TypeError): logs.append(log)
def test_bad_name(self): """Test that a log with a bad name (no underscore) fails gracefully.""" dlog_file = osp.join(self.anon_folder, 'A1234patientid.dlg') dlog = MachineLog(dlog_file) with self.assertRaises(NameError): dlog.anonymize()
def test_destination(self): tlog_file = osp.join( self.anon_folder, 'PatientID_4DC Treatment_JST90_TX_20140712094246.bin') tlog = MachineLog(tlog_file) tlog.anonymize(destination=self.anon_folder) # shouldn't raise
def setUpClass(cls): cls.log = MachineLog(cls.get_filename()) cls.log.fluence.gamma.calc_map()