Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mixed_types(self):
"""test mixed directory (tlogs & dlogs)"""
log_dir = osp.join(self._logs_dir, 'mixed_types')
logs = MachineLogs(log_dir)
self.assertEqual(logs.num_logs, 3)
def test_anonymize(self):
logs = MachineLogs(self.logs_dir, recursive=False)
files = logs.anonymize(inplace=False, suffix='_suffixed')
self.assertIsInstance(files, list)
# cleanup
for pdir, sdir, files in os.walk(self.logs_dir):
to_remove = [file for file in files if 'suffixed' in file]
for file in to_remove:
os.remove(osp.join(pdir, file))
def test_avg_gamma_pct(self):
logs = MachineLogs(self.logs_dir, recursive=False)
gamma = logs.avg_gamma_pct()
self.assertAlmostEqual(gamma, 100, delta=0.01)
def test_num_logs(self):
logs = MachineLogs(self.logs_dir, recursive=False)
self.assertEqual(logs.num_logs, 3)
self.assertEqual(logs.num_tlogs, 2)
self.assertEqual(logs.num_dlogs, 1)
logs = MachineLogs(self.mix_type_dir)
self.assertEqual(logs.num_dlogs, 1)
self.assertEqual(logs.num_tlogs, 2)
def test_loading(self):
# test root level directory
logs = MachineLogs(self.logs_dir, recursive=False)
self.assertEqual(logs.num_logs, 3)
# test recursive
logs = MachineLogs(self.logs_dir)
self.assertEqual(logs.num_logs, 3)
# test using zip file
zfile = osp.join(self._logs_dir, 'mixed_types.zip')
logs = MachineLogs.from_zip(zfile)
self.assertEqual(logs.num_logs, 3)
def test_empty_dir(self):
empty_dir = osp.join(self._logs_dir, 'empty_dir')
logs = MachineLogs(empty_dir)
self.assertEqual(logs.num_logs, 0)
with self.assertRaises(ValueError):
logs.avg_gamma()
String pointing to a single log file or a directory that contains log files.
exclude_beam_off : bool
Whether to include snapshots where the beam was off.
recursive : bool
Whether to recursively search a directory. Irrelevant for single log files.
Returns
-------
One of :class:`~pylinac.log_analyzer.Dynalog`, :class:`~pylinac.log_analyzer.TrajectoryLog`,
:class:`~pylinac.log_analyzer.MachineLogs`.
"""
if io.is_url(file_or_dir):
file_or_dir = io.get_url(file_or_dir)
if osp.isfile(file_or_dir):
if io.is_zipfile(file_or_dir):
return MachineLogs.from_zip(file_or_dir)
if not is_log(file_or_dir):
raise NotALogError("Not a valid log")
elif is_tlog(file_or_dir):
return TrajectoryLog(file_or_dir, exclude_beam_off)
else:
return Dynalog(file_or_dir, exclude_beam_off)
elif osp.isdir(file_or_dir):
return MachineLogs(file_or_dir, recursive)
else:
raise NotALogError(f"'{file_or_dir}' did not point to a valid file, directory, or ZIP archive")
One of :class:`~pylinac.log_analyzer.Dynalog`, :class:`~pylinac.log_analyzer.TrajectoryLog`,
:class:`~pylinac.log_analyzer.MachineLogs`.
"""
if io.is_url(file_or_dir):
file_or_dir = io.get_url(file_or_dir)
if osp.isfile(file_or_dir):
if io.is_zipfile(file_or_dir):
return MachineLogs.from_zip(file_or_dir)
if not is_log(file_or_dir):
raise NotALogError("Not a valid log")
elif is_tlog(file_or_dir):
return TrajectoryLog(file_or_dir, exclude_beam_off)
else:
return Dynalog(file_or_dir, exclude_beam_off)
elif osp.isdir(file_or_dir):
return MachineLogs(file_or_dir, recursive)
else:
raise NotALogError(f"'{file_or_dir}' did not point to a valid file, directory, or ZIP archive")