def test_sets_status_to_empty_when_recon_done_present(self, mock_exists): recon_done = self.fs_path + '/scripts/recon-all.done' mock_exists.side_effect = lambda x: True if x == recon_done else False my_log = scraper.FSLog(self.fs_path) assert my_log.status == ''
def test_sets_status_error_when_recon_error_present(self, mock_exists): error_log = self.fs_path + '/scripts/recon-all.error' mock_exists.side_effect = lambda x: True if x == error_log else False my_log = scraper.FSLog(self.fs_path) assert my_log.status == scraper.FSLog._ERROR
def test_sets_status_maybe_halted_when_IsRunning_log_unreadable( self, mock_glob): # Return path to nonexistent file mock_glob.return_value = ["/some/path/IsRunning.lh+rh"] my_log = scraper.FSLog(self.fs_path) assert my_log.status == scraper.FSLog._MAYBE_HALTED
def test_sets_running_status_when_subject_running_less_than_24h( self, mock_glob, mock_read_log): mock_glob.return_value = ['/some/path/IsRunning.lh+rh'] # Time zone isnt taken into account when time is compared, but required # by the date parsing code now = datetime.datetime.now(tz=EST()).strftime(self.FS_date_format) mock_read_log.return_value = ['DATE {}'.format(now)] my_log = scraper.FSLog(self.fs_path) assert my_log.status == scraper.FSLog._RUNNING
def get_site_standards(freesurfer_dir, args, subject_folder): logger.debug("Using subject {} to generate standards.".format(subject_folder)) if not args: return None standard_log = fs_scraper.FSLog(subject_folder) standards = {'build': standard_log.build, 'kernel': standard_log.kernel, 'args': args} return standards
def test_sets_status_timedout_when_subject_running_more_than_24h( self, mock_glob, mock_read_log): mock_glob.return_value = ['/some/path/IsRunning.lh+rh'] two_days_ago = datetime.datetime.now(tz=EST()) - datetime.timedelta(2) mock_read_log.return_value = [ 'DATE {}'.format(two_days_ago.strftime(self.FS_date_format)) ] my_log = scraper.FSLog(self.fs_path) assert my_log.status == scraper.FSLog._TIMEDOUT.format( 'IsRunning.lh+rh')
def get_halted_subjects(fs_path, subjects): timed_out_msg = fs_scraper.FSLog._TIMEDOUT.format("") halted = [] for subject in subjects: if sid.is_phantom(subject): continue fs_folder = os.path.join(fs_path, subject) try: log = fs_scraper.FSLog(fs_folder) except: pass else: if log.status.startswith(timed_out_msg): halted.append(subject) return halted
def test_values_set_to_empty_when_recon_done_unreadable( self, mock_exists, mock_read_log): recon_done = self.fs_path + '/scripts/recon-all.done' mock_exists.side_effect = lambda x: True if x == recon_done else False mock_read_log.return_value = {} my_log = scraper.FSLog(self.fs_path) assert my_log.status == '' # Subject will be set to basename of the freesurfer path if # recon-all.done isnt present/is unreadable # assert my_log.subject == '' assert my_log.start == '' assert my_log.end == '' assert my_log.kernel == '' assert my_log.args == '' assert my_log.nii_inputs == ''