def test_Philips_DirStructure(self): """ test Philips_utils.Philips_DirStucture """ # update config file to match local paths configFile = join(paths['Philips_dir'], 'scannerConfig.yaml') helper_tools.replace_scannerConfig_sessionDir(configFile, paths['Philips_funcDir']) # create instance of ScannerSettings class from general_utils scannerSettings = general_utils.ScannerSettings(paths['Philips_dir']) # create instance of Philips_DirStructure for testing scannerDirs = Philips_utils.Philips_DirStructure(scannerSettings) ### Run through Philips_DirStructure class methods scannerDirs.print_currentSeries() assert scannerDirs.get_seriesDirs() == ['0001'] ### Test the waitForSeriesDir function by creating a fake dir # threading.timer object to create a new dir after a few sec fakeNewSeries = join(paths['Philips_funcDir'], '0TEST') t = threading.Timer(1.0, helper_tools.createFakeSeriesDir, [fakeNewSeries]) t.start() scannerDirs.waitForSeriesDir() # assuming it didn't crash, cancel the timer function and delete new dir t.cancel() shutil.rmtree(fakeNewSeries) # remove local paths from the config file helper_tools.cleanConfigFile(configFile)
def test_initializeSession(self): """ test general_utils.initializeSession() """ # loop over the different scan environments for scanEnv in ['GE', 'Philips', 'Siemens']: print('testing environment: ' + scanEnv) # set paths based on current test environment if scanEnv == 'GE': envDir = paths['GE_dir'] funcDir = paths['GE_funcDir'] elif scanEnv == 'Philips': envDir = paths['Philips_dir'] funcDir = paths['Philips_funcDir'] elif scanEnv == 'Siemens': envDir = paths['Siemens_dir'] funcDir = paths['Siemens_funcDir'] # update config file to match local paths configFile = join(envDir, 'scannerConfig.yaml') helper_tools.replace_scannerConfig_sessionDir(configFile, funcDir) general_utils.initializeSession(pynealScannerDir=envDir) # remove local paths from config file helper_tools.cleanConfigFile(configFile) print('Passed!')
def test_Siemens_DirStructure(self): # update config file to match local paths configFile = join(paths['Siemens_dir'], 'scannerConfig.yaml') helper_tools.replace_scannerConfig_sessionDir(configFile, paths['Siemens_funcDir']) # create instace of ScannerSettings class from general_utils scannerSettings = general_utils.ScannerSettings(paths['Siemens_dir']) # create instance of Philips_DirStructure for testing scannerDirs = Siemens_utils.Siemens_DirStructure(scannerSettings) ## Run through the Siemens_DirStructure class methods scannerDirs.print_currentSeries() assert scannerDirs.getUniqueSeries() == set(['000013']) ## Test waitForNewSeries function by simulating new series data # threading.timer object to copy in new data after a few sec newSeriesNum = 999 t = threading.Timer(1.0, fakeNewSiemensSeries, [newSeriesNum]) t.start() scannerDirs.waitForNewSeries() # assuming that didn't crash, stop the timer object and remove new file t.cancel() removeFakeSiemensSeries(newSeriesNum) # remove local paths from the config file helper_tools.cleanConfigFile(configFile)
def test_ScannerSettings(self): """ test general_utils.ScannerSettings class Test methods in ScannerSettings class against sample data from each scanner make """ # loop over the different scan environments for scanEnv in ['GE', 'Philips', 'Siemens']: print('testing environment: ' + scanEnv) # set paths based on current test environment if scanEnv == 'GE': envDir = paths['GE_dir'] funcDir = paths['GE_funcDir'] elif scanEnv == 'Philips': envDir = paths['Philips_dir'] funcDir = paths['Philips_funcDir'] elif scanEnv == 'Siemens': envDir = paths['Siemens_dir'] funcDir = paths['Siemens_funcDir'] # update config file to match local paths configFile = join(envDir, 'scannerConfig.yaml') helper_tools.replace_scannerConfig_sessionDir(configFile, funcDir) # run through all functions in ScannerSettings class scanSettings = general_utils.ScannerSettings(envDir) scanSettings.print_allSettings() scanSettings.get_scannerMake() scanSettings.get_scannerSessionDir() scanSettings.get_pynealSocketHost() scanSettings.get_pynealSocketPort() scanSettings.get_allSettings() # remove local paths from config file helper_tools.cleanConfigFile(configFile) print('Passed!')
def test_getSeries_Siemens(self): """ test getSeries.getSeries_Siemens """ envDir = paths['Siemens_dir'] funcDir = paths['Siemens_funcDir'] # update config file to match local paths configFile = join(envDir, 'scannerConfig.yaml') helper_tools.replace_scannerConfig_sessionDir(configFile, funcDir) # run initializeSettings to get the scannerDirs object scannerSettings, scannerDirs = general_utils.initializeSession( pynealScannerDir=envDir) ### run getSeries_Siemens import pyneal_scanner.getSeries as getSeries # module expects user to input 2 things: desired series, and output prefix. # We have to mock the input for automatic testing, but can only mock one # input (at least as far as I can figure out). So, by hardcoding the input # to '000013', we will get series 000013 and build a nifti named # '000013_000013.nii.gz' saved in pyneal/pyneal_scanner/data. Delete this file # at end of test seriesNum = '000013' getSeries.input = lambda x: seriesNum getSeries.getSeries_Siemens(scannerDirs) # return the module input to the normal __builtin__ input function getSeries.input = input # ensure output file created, then delete outputFile = join(paths['pynealScannerDir'], 'data', '{}_{}.nii.gz'.format(seriesNum, seriesNum)) assert os.path.exists(outputFile) os.remove(outputFile) # remove local paths from the config file helper_tools.cleanConfigFile(configFile)