def test_applicationspecificinputs_isprod_false( self ): self.shs.OutputFile = 'something' self.shs.InputFile = 'input.stdhep' self.shs.InputData = [] assertDiracSucceedsWith_equals( self.shs.applicationSpecificInputs(), 'Parameters resolved', self ) assertEqualsImproved( self.shs.OutputFile, 'something', self ) assertEqualsImproved( self.shs.listoutput, {}, self )
def test_getprocesslist( self ): with patch('%s.gConfig.getValue' % MODULE_NAME, new=Mock(return_value='some_gconf_testval')) as conf_mock, \ patch('%s.ProcessList' % MODULE_NAME, new=Mock()) as pl_mock: res = self.dilc.getProcessList() pl_mock.assert_called_once_with( 'some_gconf_testval' ) assertEqualsImproved( res, pl_mock(), self ) conf_mock.assert_called_once_with( '/LocalSite/ProcessListPath', '' )
def test_setsplitInputdata(self): """Test set split input data.""" input_data = ["/path/to/data1", "/path/to/data2"] self.ujo.setSplitInputData(input_data) for data in input_data: self.assertIn(data, self.ujo._data) assertEqualsImproved(self.ujo._splittingOption, "byData", self)
def test_setdetectormodel(self): with patch('os.path.exists', new=Mock(return_value=False)): self.lcs.setDetectorModel('Test_Detectorv103.clic') assertEqualsImproved(self.lcs.detectorModel, 'Test_Detectorv103.clic', self) self.assertFalse(self.lcs._errorDict) assertEqualsImproved(self.lcs.inputSB, [], self)
def test_setters_checks(self): self.olin.setMachine({'138rj': True}) self.olin.setProdID([]) self.olin.setUseEnergyForFileLookup('False') self.olin.setDetectorModel(9024) self.olin.setBackgroundType(8914) assertEqualsImproved(len(self.olin._errorDict['_checkArgs']), 5, self)
def test_checkconsistency_othercase(self): import inspect self.lcs.version = 'v2.4' self.lcs.steeringFile = '' self.lcs.trackingStrategy = 'lfn:/myTestStrat' self.lcs.detectorModel = 'correctDetector.zip' self.lcs._jobtype = 'notUser' self.lcs._listofoutput = [] app1 = Mock() app1.appame = 'myTestApp' app2 = Mock() app2.appname = 'marlin' self.lcs._inputapp = [app1, app2] self.lcs.outputFile = '' self.lcs.willBeCut = False with patch('os.path.exists', new=Mock(side_effect=[ False ])), \ patch.object(inspect.getmodule(LCSIM), 'Exists', new=Mock(return_value=S_OK())): assertDiracSucceeds(self.lcs._checkConsistency('myTestJob'), self) expected_output_list = [{ "outputFile": "@{outputREC}", "outputPath": "@{outputPathREC}", "outputDataSE": "@{OutputSE}" }, { "outputFile": "@{outputDST}", "outputPath": "@{outputPathDST}", "outputDataSE": "@{OutputSE}" }] assertEqualsImproved(self.lcs._listofoutput, expected_output_list, self) prodparam_dict = self.lcs.prodparameters assertEqualsImproved((prodparam_dict['detectorType'], prodparam_dict['lcsim_steeringfile'], prodparam_dict['lcsim_trackingstrategy']), ('SID', '', 'lfn:/myTestStrat'), self)
def test_setaliasproperties(self): with patch('os.path.exists', new=Mock(return_value=False)): self.lcs.setAliasProperties('myAlias.Properties.Test') assertEqualsImproved(self.lcs.aliasProperties, 'myAlias.Properties.Test', self) self.assertFalse(self.lcs._errorDict) assertEqualsImproved(self.lcs.inputSB, [], self)
def test_setpandorasettings_notfound(self): with patch('os.path.exists', new=Mock(return_value=False)): self.slic.setPandoraSettings('invalid_settings.xml') assertEqualsImproved( (self.slic.pandoraSettings, self.slic.inputSB), ('invalid_settings.xml', []), self) self.assertFalse(self.slic._errorDict)
def test_settrackingstrategy(self): with patch('os.path.exists', new=Mock(return_value=False)): self.lcs.setTrackingStrategy('Test_Strategy.trackme') assertEqualsImproved(self.lcs.trackingStrategy, 'Test_Strategy.trackme', self) self.assertFalse(self.lcs._errorDict) assertEqualsImproved(self.lcs.inputSB, [], self)
def test_applicationspecificinputs_nolist( self ): self.marAna.InputFile = [ 'dontleavemealone.txt' ] self.marAna.workflow_commons[ 'ParametricInputSandbox' ] = 'myEntryies;another_one.slcio' assertDiracSucceeds( self.marAna.applicationSpecificInputs(), self ) assertEqualsImproved( ( self.marAna.InputFile, self.marAna.InputData ), ( [ 'dontleavemealone.txt', 'myEntryies', 'another_one.slcio' ], [] ), self )
def test_preparemarlindll_swaplibpositions( self ): self.marAna.ProcessorListToExclude = [ 'mytestlibrary.so' ] exists_dict = { './lib/marlin_dll' : True } def replace_exists( path ): return exists_dict[path] file_contents = [[]] handles = FileUtil.getMultipleReadHandles( file_contents ) with patch('%s.open' % MODULE_NAME, mock_open()) as open_mock, \ patch('%s.os.chmod' % MODULE_NAME) as chmod_mock, \ patch('%s.shellCall' % MODULE_NAME, new=Mock(return_value=S_OK([ 0, 'MARlin_DLL/path', 'other_return_value_from_shell' ]))) as shell_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock(side_effect=[ True ])) as remove_mock, \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=replace_exists)) as exists_mock, \ patch('%s.glob.glob' % MODULE_NAME, new=Mock(return_value=[ 'testlibLCFIPlus.so', 'testlibLCFIVertex.1.so' ])) as glob_mock: open_mock.side_effect = (h for h in handles) result = self.marAna.prepareMARLIN_DLL( 'some_path' ) open_mock.assert_called_once_with( 'temp.sh', 'w' ) assertMockCalls( handles[0].__enter__().write, ['#!/bin/bash\n', 'source some_path > /dev/null\necho $MARLIN_DLL'], self) assertEqualsImproved( len( handles ), 1, self ) chmod_mock.assert_called_once_with('temp.sh', 0o755) shell_mock.assert_called_once_with( 0, './temp.sh' ) remove_mock.assert_called_once_with( 'temp.sh' ) exists_mock.assert_called_once_with( './lib/marlin_dll' ) glob_mock.assert_called_once_with( './lib/marlin_dll/*.so' ) assertDiracSucceedsWith( result, 'MARlin_DLL/path:testlibLCFIVertex.1.so:testlibLCFIPlus.so', self )
def test_applicationspecificinputs_othercases(self): self.rod.step_commons['Enable'] = {'mydict': True} assertDiracSucceedsWith(self.rod.applicationSpecificInputs(), 'Parameters resolved', self) assertEqualsImproved((self.rod.enable, self.rod.sel_eff, self.rod.cut_eff, self.rod.add_info), (False, 0, 0, ''), self)
def test_runit_with_many_inputfiles(self): get_input_from_app = [ "output1_%s.root" % self.fccAppIndex, "output2_%s.root" % self.fccAppIndex ] self.fccAna.step_commons['InputFile'] = get_input_from_app input_file1 = os.path.realpath(get_input_from_app[0]) input_file2 = os.path.realpath(get_input_from_app[1]) self.exists_dict[input_file1] = True self.exists_dict[input_file2] = True with patch('os.makedirs'), \ patch('os.path.exists') as mock_exists : mock_exists.side_effect = self.replace_exists assertDiracSucceedsWith( self.fccAna.runIt(), "Execution of the FCC application successfull", self) assertEqualsImproved(self.fccAna.InputFile, [input_file1, input_file2], self) assertEqualsImproved(self.fccAna.SteeringFile, " ".join(self.fccAna.InputFile), self) self.log_mock.debug.assert_any_call( "Application : Configuration file taken from the input file(s) '%s'" % self.fccAna.SteeringFile)
def test_checkconsistency_othercase( self ): import inspect self.lcs.version = 'v2.4' self.lcs.steeringFile = '' self.lcs.trackingStrategy = 'lfn:/myTestStrat' self.lcs.detectorModel = 'correctDetector.zip' self.lcs._jobtype = 'notUser' self.lcs._listofoutput = [] app1 = Mock() app1.appame = 'myTestApp' app2 = Mock() app2.appname = 'marlin' self.lcs._inputapp = [ app1, app2 ] self.lcs.outputFile = '' self.lcs.willBeCut = False with patch('os.path.exists', new=Mock(side_effect=[ False ])), \ patch.object(inspect.getmodule(LCSIM), 'Exists', new=Mock(return_value=S_OK())): assertDiracSucceeds( self.lcs._checkConsistency( 'myTestJob' ), self ) expected_output_list = [ { "outputFile" : "@{outputREC}", "outputPath" : "@{outputPathREC}", "outputDataSE" : "@{OutputSE}" }, { "outputFile" : "@{outputDST}", "outputPath" : "@{outputPathDST}", "outputDataSE" : "@{OutputSE}" } ] assertEqualsImproved( self.lcs._listofoutput, expected_output_list, self ) prodparam_dict = self.lcs.prodparameters assertEqualsImproved( ( prodparam_dict['detectorType'], prodparam_dict['lcsim_steeringfile'], prodparam_dict['lcsim_trackingstrategy'] ), ( 'SID' , '', 'lfn:/myTestStrat' ), self )
def test_osversion_win_position_4( self ): nm = get_win32_machine() nm._sysinfo = ( 'Windows', 'dhellmann', '2008ServerR2', '6.1.7600', 'AMD64', 'Intel64 Family 6 Model 15 Stepping 11, GenuineIntel' ) result = nm.OSVersion( 4 ) assertEqualsImproved( result, '6.1.7600', self ) assertEqualsImproved( nm._osversion, '6.1.7600', self )
def test_checkconsistency(self): self.mar.version = '13' self.mar.steeringFile = '/mysteer/file.stdhep' self.mar.gearFile = None self.mar._jobtype = 'notUser' self.mar.outputFile = None with patch('os.path.exists', new=Mock(return_value=True)), \ patch.object(inspect.getmodule(Marlin), 'checkXMLValidity', new=Mock(return_value=S_OK())): assertDiracSucceeds(self.mar._checkConsistency(), self) self.assertIn( { 'outputFile': '@{outputREC}', 'outputPath': '@{outputPathREC}', 'outputDataSE': '@{OutputSE}' }, self.mar._listofoutput) self.assertIn( { 'outputFile': '@{outputDST}', 'outputPath': '@{outputPathDST}', 'outputDataSE': '@{OutputSE}' }, self.mar._listofoutput) for keyword in [ 'detectorType', 'marlin_gearfile', 'marlin_steeringfile' ]: self.assertIn(keyword, self.mar.prodparameters) assertEqualsImproved(self.mar.gearFile, None, self)
def test_getfilesfromcastor(self): self.over.machine = 'testMach12' import subprocess popen_mock = Mock() popen_mock.communicate.side_effect = [ ('myfile1\nfile1923\n813tev_collision ', 'ignoreme'), ('file1.stdhep\nsome_other_file', 'ignoreme'), ('', 'ignoreme'), ('\nlast_file.txt', 'ignoreme') ] castor_dict = { 'ProdID': 121345, 'Energy': '813', 'EvtType': 'myTestEvt', 'DetectorType': 'myTestDetectorv3' } with patch('subprocess.Popen', new=Mock(return_value=popen_mock)) as proc_mock: proc_command_dir = '/castor/cern.ch/grid/ilc/prod/testMach12/813/myTestEvt/myTestDetectorv3/SIM/00121345/' assertDiracSucceedsWith_equals( self.over._OverlayInput__getFilesFromCastor(castor_dict), [ proc_command_dir + 'myfile1/file1.stdhep', proc_command_dir + 'myfile1/some_other_file', proc_command_dir + 'file1923/', proc_command_dir + '813tev_collision/', proc_command_dir + '813tev_collision/last_file.txt' ], self) assertEqualsImproved(proc_mock.mock_calls, [ call(['nsls', proc_command_dir], stdout=subprocess.PIPE), call(['nsls', proc_command_dir + 'myfile1'], stdout=subprocess.PIPE), call(['nsls', proc_command_dir + 'file1923'], stdout=subprocess.PIPE), call(['nsls', proc_command_dir + '813tev_collision'], stdout=subprocess.PIPE) ], self)
def test_cmt_osflavor( self ): unix_mach = get_naked_machine() unix_mach._ostype = 'Windows' unix_mach._arch = 'mytestarch' res_1 = unix_mach.CMTOSFlavour() assertEqualsImproved( res_1, 'winmytestarch', self ) unix_mach._ostype = 'Darwin' unix_mach._sysinfo = ( 'Darwin', 'hubert.local', '11.4.2', 'Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64', 'x86_64', 'i386' ) res_2 = unix_mach.CMTOSFlavour() assertEqualsImproved( res_2, 'osx107', self ) unix_mach._ostype = 'Linux' unix_mach._osflavor = 'Ubuntu' unix_mach._osversion = '14.04' res_3 = unix_mach.CMTOSFlavour() assertEqualsImproved( res_3, 'ub14', self ) unix_mach._ostype = 'Linux' unix_mach._osflavor = 'SuSE' unix_mach._osversion = '11.04' res_4 = unix_mach.CMTOSFlavour() assertEqualsImproved( res_4, 'suse11', self ) unix_mach._osversion = None unix_mach._ostype = 'Linux' unix_mach._osflavor = 'Redhat' unix_mach._osversion = '17.07' res_5 = unix_mach.CMTOSFlavour() assertEqualsImproved( res_5, 'rh17.07', self )
def test_application_specific_inputs_jobid_zero( self ): self.ujf.jobID = 0 self.ujf.enable = True result = self.ujf.applicationSpecificInputs() assertDiracSucceedsWith_equals( result, 'Parameters resolved', self ) assertEqualsImproved( self.ujf.jobID, 0, self ) assertEqualsImproved( self.ujf.enable, False, self )
def test_preparescript(self): exists_dict = {'TestApp_vT_Run_148.sh': True, './lib': True} (self.shc.platform, self.shc.applicationName, self.shc.applicationVersion, self.shc.STEP_NUMBER, self.shc.MaxNbEvts, self.shc.OutputFile, self.shc.SteeringFile) = ('testPlatformV1', 'TestApp', 'vT', 148, 13, 'test_OF.ile', 'steer_test.file') file_contents = [[]] handles = FileUtil.getMultipleReadHandles(file_contents) with patch('%s.getNewLDLibs' % MODULE_NAME, new=Mock(return_value='/my/testsoft/dir1/')) as getldlibs_mock, \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=lambda path: exists_dict[path])) as exists_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock()) as remove_mock, \ patch('%s.open' % MODULE_NAME, mock_open(), create=True ) as mo: mo.side_effect = (h for h in handles) self.shc.prepareScript('test_software/dir') remove_mock.assert_called_once_with('TestApp_vT_Run_148.sh') getldlibs_mock.assert_called_once_with('testPlatformV1', 'TestApp', 'vT') assertMockCalls(exists_mock, ['./lib', 'TestApp_vT_Run_148.sh'], self) mo.assert_called_once_with('TestApp_vT_Run_148.sh', 'w') assertEqualsImproved(len(handles), 1, self) assertMockCalls(handles[0].write, [ '#!/bin/sh \n', '#####################################################################\n', '# Dynamically generated script to run a production or analysis job. #\n', '#####################################################################\n', 'declare -x PATH=test_software/dir:$PATH\n', 'declare -x LD_LIBRARY_PATH=./lib:test_software/dir/lib:/my/testsoft/dir1/\n', 'env | sort >> localEnv.log\n', 'echo =============================\n', "stdhepCut -m 13 -o test_OF.ile -c steer_test.file ../*.stdhep\n", 'declare -x appstatus=$?\n', 'exit $appstatus\n' ], self) assert handles[0].close.called
def test_broadcast_processed_checkchunking(self): from DIRAC import S_OK from ILCDIRAC.ILCTransformationSystem.Agent.TransformationPlugin import TransformationPlugin import copy files = {} for i in xrange(0, 599): files[('/file/dir/input%s.txt' % i)] = ['child'] dataman_mock = Mock() trans_mock = Mock() util_mock = Mock() util_mock.fc.getFileDescendents.return_value = S_OK({ 'Successful': files, 'Failed': {} }) util_mock.transClient = trans_mock self.tfp = TransformationPlugin('BroadcastProcessed', dataman_mock, trans_mock) self.tfp.params['Status'] = '' self.tfp.util = util_mock self.tfp.setInputData(copy.deepcopy(files)) del self.tfp.data['/file/dir/input542.txt'] with patch('%s.TransformationPlugin._Broadcast' % MODULE_NAME, new=Mock(return_value=S_OK(98124))): assertDiracSucceedsWith_equals(self.tfp.run(), 98124, self) expected = {} for i in xrange(0, 599): if i != 542: expected[('/file/dir/input%s.txt' % i)] = ['child'] assertListContentEquals(self.tfp.data, expected, self) assertEqualsImproved(len(util_mock.fc.getFileDescendents.mock_calls), 3, self)
def test_setfullparamdict( self ): self.whiz.setFullParameterDict( { 'some_entry' : True, 'myParamDict' : {}, 123 : 2 } ) assert not self.whiz._errorDict assertEqualsImproved( self.whiz.fullParameterDict, { 'some_entry' : True, 'myParamDict' : {}, 123 : 2 }, self )
def test_execute_metadata_not_found(self): self.upod.prodOutputLFNs = ['/ilc/prod/ilc/sid/example_file'] with patch.object(self.upod, 'getCandidateFiles', new=Mock(return_value=S_OK({}))), \ patch.object(self.upod, 'getFileMetadata', new=Mock(return_value=S_ERROR( 'no_meta_test_data_err' ))): assertDiracFailsWith(self.upod.execute(), 'no_meta_test_data_err', self) assertEqualsImproved(self.upod.experiment, 'ILC_SID', self)
def test_checkconsistency(self): self.gsf.setFiles({ 'file': '/invalid/dir/mycoolfile.txt', 'something': True }) assertDiracSucceeds(self.gsf._checkConsistency(), self) assertEqualsImproved(self.gsf.outputFile, 'mycoolfile.txt', self)
def test_osflavor_win( self ): nm = get_win32_machine() nm._sysinfo = ('Windows', 'dhellmann', '2008ServerR2', '6.1.7600', 'AMD64', 'Intel64 Family 6 Model 15 Stepping 11, GenuineIntel' ) result = nm.OSFlavour() assertEqualsImproved( result, '2008ServerR2', self ) assertEqualsImproved( nm._osflavor, '2008ServerR2', self )
def test_setters_checks( self ): self.olin.setMachine( { '138rj' : True } ) self.olin.setProdID( [] ) self.olin.setUseEnergyForFileLookup( 'False' ) self.olin.setDetectorModel( 9024 ) self.olin.setBackgroundType( 8914 ) assertEqualsImproved( len( self.olin._errorDict['_checkArgs'] ), 5, self )
def test_checkconsistency_othercase(self): self.mar.version = '13' self.mar.steeringFile = '/mysteer/file.stdhep' self.mar.gearFile = 'myGearOutput.mock' self.mar._jobtype = 'notUser' self.mar.outputFile = 'myoutput.test' with patch('os.path.exists', new=Mock(return_value=False)): assertDiracSucceeds(self.mar._checkConsistency(), self) self.assertNotIn( { 'outputFile': '@{outputREC}', 'outputPath': '@{outputPathREC}', 'outputDataSE': '@{OutputSE}' }, self.mar._listofoutput) self.assertNotIn( { 'outputFile': '@{outputDST}', 'outputPath': '@{outputPathDST}', 'outputDataSE': '@{OutputSE}' }, self.mar._listofoutput) for keyword in [ 'detectorType', 'marlin_gearfile', 'marlin_steeringfile' ]: self.assertIn(keyword, self.mar.prodparameters) assertEqualsImproved(self.mar.gearFile, 'myGearOutput.mock', self)
def test_preparemarlindll_swaplibpositions(self): self.marAna.ProcessorListToExclude = ['mytestlibrary.so'] exists_dict = {'./lib/marlin_dll': True} def replace_exists(path): return exists_dict[path] file_contents = [[]] handles = FileUtil.getMultipleReadHandles(file_contents) with patch('%s.open' % MODULE_NAME, mock_open()) as open_mock, \ patch('%s.os.chmod' % MODULE_NAME) as chmod_mock, \ patch('%s.shellCall' % MODULE_NAME, new=Mock(return_value=S_OK([ 0, 'MARlin_DLL/path', 'other_return_value_from_shell' ]))) as shell_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock(side_effect=[ True ])) as remove_mock, \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=replace_exists)) as exists_mock, \ patch('%s.glob.glob' % MODULE_NAME, new=Mock(return_value=[ 'testlibLCFIPlus.so', 'testlibLCFIVertex.1.so' ])) as glob_mock: open_mock.side_effect = (h for h in handles) result = self.marAna.prepareMARLIN_DLL('some_path') open_mock.assert_called_once_with('temp.sh', 'w') assertMockCalls( handles[0].__enter__().write, ['#!/bin/bash\n', 'source some_path\necho $MARLIN_DLL'], self) assertEqualsImproved(len(handles), 1, self) chmod_mock.assert_called_once_with('temp.sh', 0755) shell_mock.assert_called_once_with(0, './temp.sh') remove_mock.assert_called_once_with('temp.sh') exists_mock.assert_called_once_with('./lib/marlin_dll') glob_mock.assert_called_once_with('./lib/marlin_dll/*.so') assertDiracSucceedsWith( result, 'MARlin_DLL/path:testlibLCFIVertex.1.so:testlibLCFIPlus.so', self)
def test_uploadproclist_upload_fails(self): import sys import DIRAC datman_mock = Mock() datman_mock.removeFile.return_value = S_OK('something') datmodule_mock = Mock() datmodule_mock.DataManager.return_value = datman_mock fileutil_mock = Mock() fileutil_mock.upload.return_value = S_ERROR('something') conf_mock = Mock() conf_mock.getOption.return_value = S_OK('somepath') mocked_modules = { 'DIRAC.DataManagementSystem.Client.DataManager': datmodule_mock, 'ILCDIRAC.Core.Utilities.FileUtils': fileutil_mock } module_patcher = patch.dict(sys.modules, mocked_modules) module_patcher.start() backup_conf = DIRAC.gConfig DIRAC.gConfig = conf_mock DIRAC.exit = abort_test with self.assertRaises(KeyboardInterrupt) as ki: self.prol.uploadProcessListToFileCatalog('asd', 'v1') key_interrupt = ki.exception assertEqualsImproved(key_interrupt.args, ('abort_my_test', ), self) DIRAC.gConfig = backup_conf module_patcher.stop()
def test_cmt_osflavor(self): unix_mach = get_naked_machine() unix_mach._ostype = 'Windows' unix_mach._arch = 'mytestarch' res_1 = unix_mach.CMTOSFlavour() assertEqualsImproved(res_1, 'winmytestarch', self) unix_mach._ostype = 'Darwin' unix_mach._sysinfo = ( 'Darwin', 'hubert.local', '11.4.2', 'Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64', 'x86_64', 'i386') res_2 = unix_mach.CMTOSFlavour() assertEqualsImproved(res_2, 'osx107', self) unix_mach._ostype = 'Linux' unix_mach._osflavor = 'Ubuntu' unix_mach._osversion = '14.04' res_3 = unix_mach.CMTOSFlavour() assertEqualsImproved(res_3, 'ub14', self) unix_mach._ostype = 'Linux' unix_mach._osflavor = 'SuSE' unix_mach._osversion = '11.04' res_4 = unix_mach.CMTOSFlavour() assertEqualsImproved(res_4, 'suse11', self) unix_mach._osversion = None unix_mach._ostype = 'Linux' unix_mach._osflavor = 'Redhat' unix_mach._osversion = '17.07' res_5 = unix_mach.CMTOSFlavour() assertEqualsImproved(res_5, 'rh17.07', self)
def test_transfer_register_and_failover_files( self ): self.ujf.failoverSEs = [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ] self.ujf.userFileCatalog = 'blaCatalogTestme' transfer_mock = Mock() transfer_mock.transferAndRegisterFileFailover.return_value = S_OK( {} ) filesUploaded = [] with patch('%s.random.shuffle' % MODULE_NAME) as shuffle_mock: result = self.ujf.transferRegisterAndFailoverFiles( transfer_mock, { 'filename1test' : { 'metadatadict1' : True, 'resolvedSE' : ( 'etc', 'privateSite4' ), 'localpath' : '/my/local/path/Testme.txt', 'lfn' : 'LFN:/ilc/mytest/LFN.txt', 'filedict' : 89546 }, 'my_other_testfile' : { 'metadatadict1' : True, 'resolvedSE' : ( 'testSite1', 'privateSite4' ), 'localpath' : '/my/local/path/Testme2.txt', 'lfn' : 'LFN:/ilc/othertest/new_lfn.lfn', 'filedict' : 475 } }, filesUploaded ) assertDiracSucceeds( result, self ) assertEqualsImproved( result['Value'], dict(cleanUp=False), self ) assertMockCalls( shuffle_mock, [ [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ], [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ] ], self ) assertEqualsImproved( transfer_mock.transferAndRegisterFileFailover.mock_calls, [ call( 'my_other_testfile', '/my/local/path/Testme2.txt', 'LFN:/ilc/othertest/new_lfn.lfn', 'testSite1', [ 'testSite2', 'myTestSite', 'privateSite4', 'etc' ], fileCatalog='blaCatalogTestme', fileMetaDict=475 ), call( 'filename1test', '/my/local/path/Testme.txt', 'LFN:/ilc/mytest/LFN.txt', 'etc', [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4' ], fileCatalog='blaCatalogTestme', fileMetaDict=89546 ) ], self ) self.assertIn( 'LFN:/ilc/mytest/LFN.txt', filesUploaded ) self.assertIn( 'LFN:/ilc/othertest/new_lfn.lfn', filesUploaded )
def test_osversion_darwin( self ): mach = get_naked_machine() mach._ostype = 'Darwin' mach._sysinfo = ( 'Darwin', 'hubert.local', '11.4.2', 'Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64', 'x86_64', 'i386' ) result = mach.OSVersion( 3 ) assertEqualsImproved( result, '10.7.4', self ) assertEqualsImproved( mach._osversion, '10.7.4', self )
def test_broadcast_processed_checkchunking( self ): from DIRAC import S_OK from ILCDIRAC.ILCTransformationSystem.Agent.TransformationPlugin import TransformationPlugin import copy files = {} for i in xrange(0, 599): files[ ( '/file/dir/input%s.txt' % i ) ] = [ 'child' ] dataman_mock = Mock() trans_mock = Mock() util_mock = Mock() util_mock.fc.getFileDescendents.return_value = S_OK( { 'Successful' : files, 'Failed' : {} } ) util_mock.transClient = trans_mock self.tfp = TransformationPlugin( 'BroadcastProcessed', dataman_mock, trans_mock ) self.tfp.params[ 'Status' ] = '' self.tfp.util = util_mock self.tfp.setInputData( copy.deepcopy( files ) ) del self.tfp.data[ '/file/dir/input542.txt' ] with patch('%s.TransformationPlugin._Broadcast' % MODULE_NAME, new=Mock(return_value=S_OK(98124))): assertDiracSucceedsWith_equals( self.tfp.run(), 98124, self ) expected = {} for i in xrange(0, 599): if i != 542: expected[ ( '/file/dir/input%s.txt' % i ) ] = [ 'child' ] assertListContentEquals( self.tfp.data, expected, self ) assertEqualsImproved( len( util_mock.fc.getFileDescendents.mock_calls ), 3, self )
def test_getsharedarealoc_notfound( self ): with patch('%s.Operations.getValue' % MODULE_NAME, new=Mock(return_value=[])), \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=[ False, True ])), \ patch('%s.DIRAC.gConfig.getValue' % MODULE_NAME, new=Mock(side_effect=['a', 'a', '', ''])), \ patch('%s.os.path.isdir' % MODULE_NAME, new=Mock(return_value=True)): result = getSharedAreaLocation() assertEqualsImproved( result, '', self )
def test_randomstring(self): random_string_1 = generateRandomString() random_string_2 = generateRandomString() assertEqualsImproved(len(random_string_1), 8, self) assertEqualsImproved(len(random_string_2), 8, self) assert isinstance(random_string_1, basestring) assert isinstance(random_string_2, basestring)
def test_applicationSpecificInputs(self): self.upod.step_commons['TestFailover'] = 'something' self.upod.workflow_commons['outputList'] = [{ 'appdict': True, 'myOutput': 'yes', 'outputFile': '' }, { 'outputFile': True }] self.upod.workflow_commons['PRODUCTION_ID'] = 1834 self.upod.workflow_commons['JOB_ID'] = 418 self.upod.workflow_commons['outputDataFileMask'] = ['mycoollist'] with patch('%s.getProdFilename' % MODULE_NAME, new=Mock(side_effect=['myOutputF_1', 'other_file.txt'])): assertDiracSucceedsWith(self.upod.applicationSpecificInputs(), 'Parameters resolved', self) assertEqualsImproved(self.upod.failoverTest, False, self) assertEqualsImproved(self.upod.outputList, [{ 'appdict': True, 'myOutput': 'yes', 'outputFile': 'myOutputF_1' }, { 'outputFile': 'other_file.txt' }], self)
def test_applicationSpecificInputs(self): # Compare to this. Get outside of patch, else constructor fails reference = OverlayInput() with patch('%s.Operations.getValue' % MODULE_NAME, new=Mock(return_value=2)): result = self.over.applicationSpecificInputs() assertDiracSucceedsWith_equals(result, TestOverlayUnittests.GOOD_EXIT, self) # Assert nothing has been changed, except the values in setUp (and DataManager/FileCatalogClient since theyre created anew for every object) assertEqualsImproved( (self.over.enable, self.over.STEP_NUMBER, self.over.log, self.over.applicationName, self.over.curdir, self.over.applicationLog, self.over.printoutflag, self.over.prodid, self.over.detector, self.over.energy, self.over.nbofeventsperfile, self.over.lfns, self.over.nbfilestoget, self.over.BkgEvtType, self.over.ggtohadint, self.over.nbsigeventsperfile, self.over.nbinputsigfile, self.over.site, self.over.useEnergyForFileLookup, self.over.machine, self.over.pathToOverlayFiles), (reference.enable, reference.STEP_NUMBER, reference.log, reference.applicationName, reference.curdir, reference.applicationLog, reference.printoutflag, reference.prodid, reference.detector, reference.energy, reference.nbofeventsperfile, reference.lfns, reference.nbfilestoget, reference.BkgEvtType, reference.ggtohadint, reference.nbsigeventsperfile, reference.nbinputsigfile, reference.site, reference.useEnergyForFileLookup, reference.machine, reference.pathToOverlayFiles), self) if self.over.fcc is None: self.fail('FCC not initialized') if self.over.datMan is None: self.fail('DataManager not initialized')
def test_execute_ignoremissing_works( self ): module_mock = Mock() module_mock.execute.side_effect = [ { 'OK' : True, 'Failed' : [ 'myReplicaSite1', 'other_failure' ], 'Successful' : { 'WorkingSite1' : True, 'OtherGoodSite' : True } }, { 'OK' : True, 'Failed' : [], 'Successful' : { 'other_site' : True, 'TestSite1' : True } } ] self.mfac_mock.ModuleFactory().getModule.return_value = S_OK( module_mock ) from ILCDIRAC.Core.Utilities.InputDataResolution import InputDataResolution self.idr = InputDataResolution( { 'Job' : { 'InputDataPolicy' : [ '/myTestPolicy/some/path', 'other_policy/path' ] }, 'Configuration': { 'SiteName' :'myTestSitename' }, 'IgnoreMissing' : True } ) res = self.idr.execute() assertDiracSucceeds( res, self ) assertEqualsImproved( res, { 'OK' : True, 'Value' : None, 'Failed' : [], 'Successful' : { 'WorkingSite1' : True, 'OtherGoodSite' : True, 'other_site' : True, 'TestSite1' : True } }, self ) assertMockCalls( self.mfac_mock.ModuleFactory().getModule, [ ( '/myTestPolicy/some/path', { 'Job' : { 'InputDataPolicy' : [ '/myTestPolicy/some/path', 'other_policy/path' ] }, 'Configuration' : { 'SiteName' : 'myTestSitename' }, 'IgnoreMissing' : True } ), ( 'other_policy/path', { 'Job': { 'InputDataPolicy' : [ '/myTestPolicy/some/path', 'other_policy/path' ] }, 'Configuration' : { 'SiteName' : 'myTestSitename' }, 'IgnoreMissing' : True } ) ], self )
def test_getters(self): from ILCDIRAC.Core.Utilities.WhizardOptions import WhizardOptions expected_pdict = { 'OK': True, 'Value': { 'integration_input': {}, 'simulation_input': {}, 'diagnostics_input': {}, 'process_input': {}, 'beam_input_1': {}, 'beam_input_2': {} } } pdict = self.whiz.getPDict() self.whiz.setEvtType('myevent_test') self.assertIsNotNone(pdict) self.whiz.setGlobalEvtType('test_myglobalevt') self.whiz.setLuminosity(138.312) self.whiz.setRandomSeed(9024) self.whiz.setParameterDict({ 'mytestval': True, 'more_entres': 'value', 'something': 9103 }) self.whiz.setGeneratorLevelCuts({ 'generator': False, 'cuts': 123, 'level': 'OK' }) assert not self.whiz.willBeCut self.whiz.willCut() assert not self.whiz.useGridFiles self.whiz.usingGridFiles() self.whiz.setJobIndex('mytestJobIndexS&P500') self.whiz.setModel('mytestSModel') self.whiz._wo = WhizardOptions(self.whiz.model) with patch('__builtin__.open', mock_open(), create=True) as mo: self.whiz.addedtojob = True self.whiz.dumpWhizardDotIn('someFile.in') self.whiz.addedtojob = False mo.assert_called_once_with('someFile.in', 'w') assertMockCalls(mo().write, [TestWhizard.EXPECTED_PRINTOUT, '\n'], self) assertEqualsImproved( (pdict, self.whiz.eventType, self.whiz.globalEventType, self.whiz.luminosity, self.whiz.randomSeed, self.whiz.parameterDict, self.whiz.generatorLevelCuts, self.whiz.willBeCut, self.whiz.useGridFiles, self.whiz.jobIndex, self.whiz.model), (expected_pdict, 'myevent_test', 'test_myglobalevt', 138.312, 9024, { 'mytestval': True, 'more_entres': 'value', 'something': 9103 }, { 'generator': False, 'cuts': 123, 'level': 'OK' }, True, True, 'mytestJobIndexS&P500', 'mytestSModel'), self) assert not self.whiz._errorDict
def test_randomstring( self ): random_string_1 = generateRandomString() random_string_2 = generateRandomString() assertEqualsImproved( len(random_string_1), 8, self ) assertEqualsImproved( len(random_string_2), 8, self ) assert isinstance( random_string_1, basestring ) assert isinstance( random_string_2, basestring )
def test_setfilestatus_useexistingfilereport( self ): report_mock = Mock() report_mock.setFileStatus.return_value = S_OK('my_report_test_returnval') self.moba.workflow_commons['FileReport'] = report_mock assertDiracSucceedsWith_equals( self.moba.setFileStatus( 'production', 'lfn', 'status' ), 'my_report_test_returnval', self ) assertEqualsImproved( self.moba.workflow_commons['FileReport'], report_mock, self )
def test_setfilestatus( self ): report_mock = Mock() report_mock.setFileStatus.return_value = S_OK('other_my_report_test') with patch('%s.FileReport' % MODULE_NAME, new=Mock(return_value=report_mock)): assertDiracSucceedsWith_equals( self.moba.setFileStatus( 'production', 'lfn', 'status' ), 'other_my_report_test', self ) assertEqualsImproved( self.moba.workflow_commons['FileReport'], report_mock, self )
def test_runit_othercases( self ): exists_dict = { 'SteerFile.testme' : True, 'myAppTestLog.log' : False } open_mock = Mock() open_mock.readlines.side_effect = [ 'line1\n', 'line2\n', 'newline\n', '\n', 'ok\n' ] open_mock.__enter__.return_value = [ 'Events kept 23', 'Events passing cuts 14', 'Events total 37' ] self.shc.scriptName = 'my_test_script.sh' self.shc.ignoreapperrors = True self.shc.OutputFile = 'something' self.shc.applicationLog = 'myAppTestLog.log' self.shc.SteeringFile = '/my/dir/SteerFile.testme' self.shc.workflow_commons[ 'Info' ] = { 'some_entry' : 'rememberMe' } self.shc.MaxNbEvts = 100 ( self.shc.platform, self.shc.applicationName, self.shc.applicationVersion ) = ( 'testPlatform', 'AppTestName', 'vT' ) with patch('%s.getSoftwareFolder' % MODULE_NAME, new=Mock(return_value=S_OK('SoftDir'))), \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=lambda path: exists_dict[path])), \ patch('%s.open' % MODULE_NAME, new=Mock(return_value=open_mock)) as open_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock()), \ patch('%s.os.chmod' % MODULE_NAME, new=Mock()), \ patch('%s.shellCall' % MODULE_NAME, new=Mock(return_value=S_OK( ( 0, )))), \ patch('%s.StdHepCut.prepareScript' % MODULE_NAME, new=Mock()): assertDiracSucceedsWith_equals( self.shc.runIt(), 'AppTestName vT Successful', self ) assertEqualsImproved( self.shc.workflow_commons[ 'Info'], { 'some_entry' : 'rememberMe', 'stdhepcut' : { 'Reduction' : 1. * 23 / 14, 'CutEfficiency' : 1. * 14 / 37 } }, self ) assert 'Luminosity' not in self.shc.workflow_commons
def test_preparescript( self ): exists_dict = { 'TestApp_vT_Run_148.sh' : True, './lib' : True } ( self.shc.platform, self.shc.applicationName, self.shc.applicationVersion, self.shc.STEP_NUMBER, self.shc.MaxNbEvts, self.shc.OutputFile, self.shc.SteeringFile ) = ( 'testPlatformV1', 'TestApp', 'vT', 148, 13, 'test_OF.ile', 'steer_test.file' ) file_contents = [[]] handles = FileUtil.getMultipleReadHandles(file_contents) with patch('%s.getNewLDLibs' % MODULE_NAME, new=Mock(return_value='/my/testsoft/dir1/')) as getldlibs_mock, \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=lambda path: exists_dict[path])) as exists_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock()) as remove_mock, \ patch('%s.open' % MODULE_NAME, mock_open(), create=True ) as mo: mo.side_effect = ( h for h in handles ) self.shc.prepareScript( 'test_software/dir' ) remove_mock.assert_called_once_with( 'TestApp_vT_Run_148.sh' ) getldlibs_mock.assert_called_once_with( 'testPlatformV1', 'TestApp', 'vT' ) assertMockCalls( exists_mock, [ './lib', 'TestApp_vT_Run_148.sh' ], self ) mo.assert_called_once_with( 'TestApp_vT_Run_148.sh', 'w' ) assertEqualsImproved( len( handles ), 1, self ) assertMockCalls( handles[0].write, [ '#!/bin/sh \n', '#####################################################################\n', '# Dynamically generated script to run a production or analysis job. #\n', '#####################################################################\n', 'declare -x PATH=test_software/dir:$PATH\n', 'declare -x LD_LIBRARY_PATH=./lib:test_software/dir/lib:/my/testsoft/dir1/\n', 'env | sort >> localEnv.log\n', 'echo =============================\n', "stdhepCut -m 13 -o test_OF.ile -c steer_test.file ../*.stdhep\n", 'declare -x appstatus=$?\n', 'exit $appstatus\n' ], self ) assert handles[0].close.called
def test_native_compiler_preset( self ): win_mach = get_win32_machine() win_mach.nativeCompiler() win_mach._ostype = 'Linux' result = win_mach.nativeCompiler() assertEqualsImproved( result, 'vc71', self ) assertEqualsImproved( win_mach._compiler, 'vc71', self )
def test_runit_complete( self ): exists_dict = { '/my/steer/dir/SteerFile.testme' : False, 'SteerFile.testme' : False, 'myAppTestLog.log' : True } open_mock = Mock() open_mock.readlines.side_effect = [ 'line1\n', 'line2\n', 'newline\n', '\n', 'ok\n' ] open_mock.__enter__.return_value = [ 'Events kept 12', 'Events passing cuts 2984', 'Events total 2996' ] self.shc.applicationLog = 'myAppTestLog.log' self.shc.OutputFile = 'something' self.shc.SteeringFile = '/my/dir/SteerFile.testme' self.shc.workflow_commons[ 'Luminosity' ] = 13.0 ( self.shc.platform, self.shc.applicationName, self.shc.applicationVersion ) = ( 'testPlatform', 'AppTestName', 'vT' ) with patch('%s.getSoftwareFolder' % MODULE_NAME, new=Mock(return_value=S_OK('SoftDir'))), \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=lambda path: exists_dict[path])), \ patch('%s.open' % MODULE_NAME, new=Mock(return_value=open_mock)) as open_mock, \ patch('%s.os.remove' % MODULE_NAME, new=Mock()) as remove_mock, \ patch('%s.os.chmod' % MODULE_NAME, new=Mock()), \ patch('%s.shellCall' % MODULE_NAME, new=Mock(return_value=S_OK( ( 0, )))), \ patch('%s.StdHepCut.prepareScript' % MODULE_NAME, new=Mock()), \ patch('%s.getSteeringFileDirName' % MODULE_NAME, new=Mock(return_value=S_OK('/my/steer/dir'))): assertDiracSucceedsWith_equals( self.shc.runIt(), 'AppTestName vT Successful', self ) remove_mock.assert_called_once_with( 'myAppTestLog.log' ) assertEqualsImproved( self.shc.workflow_commons[ 'Luminosity' ], 13.0 * ( 1. * 12 / 2984 ), self ) assertEqualsImproved( self.shc.workflow_commons[ 'Info' ], { 'stdhepcut' : { 'Reduction' : 1. * 12 / 2984, 'CutEfficiency' : 1. * 2984 / 2996 } }, self )
def test_sliced_limited_add_up_to_maximum( self ): from ILCDIRAC.ILCTransformationSystem.Agent.TransformationPlugin import TransformationPlugin from DIRAC import S_OK dataman_mock = Mock() util_mock = Mock() trans_mock = Mock() trans_mock.getCounters.return_value = S_OK( [ ( { 'Status' : 'Processed' }, 4 ), ( { 'Status' : 'junk' }, 6 ), ( { 'Status' : 'Ignore_me' }, 8 ), ( { 'Status' : 'Assigned' }, 6 ) ] ) util_mock.transClient = trans_mock self.tfp = TransformationPlugin( 'SlicedLimited', dataman_mock, trans_mock ) self.tfp.params[ 'Status' ] = 'Processed' self.tfp.params[ 'MaxNumberOfTasks' ] = 12 self.tfp.params[ 'TransformationID' ] = 78456 self.tfp.util = util_mock self.tfp.setInputData( { '/my/file/here_abc' : [ 'myTestSE' ], '/my/file/other_file.txt' : [ 'secretSE', 'StorageSE', 'TestSE' ], '/my/file/newfile.pdf' : [ 'TestSE' ], '/my/file/a' : [], '/dir/somefile': [ '' ] } ) result = self.tfp.run() assertDiracSucceeds( result, self ) to_check = result[ 'Value' ] print(result) assertEqualsImproved( ( len( to_check ), to_check[0][0], to_check[1][0], len( to_check[0][1] ), len( to_check[1][1] ) ), ( 2, '', '', 1, 1 ), self ) # Checks that two tasks are added, that the two tasks have the form ('', [ a ]) self.assertNotEquals( to_check[0][1][0], to_check[1][1][0] ) # Checks that the same lfn isnt added twice # Checks that the LFN is one of those expected (since keys() iteration is random for dictionaries) expected = [ '/my/file/here_abc', '/my/file/other_file.txt', '/my/file/newfile.pdf', '/my/file/a', '/dir/somefile' ] assertInImproved( to_check[0][1][0], expected, self ) assertInImproved( to_check[1][1][0], expected, self ) trans_mock.getCounters.assert_called_once_with( 'TransformationFiles', [ 'Status' ], { 'TransformationID' : 78456 } )
def test_constructoutputlfns_proxy_missing( self ): self.ujf.jobID = 8234 self.ujf.workflow_commons = {} with patch('%s.getProxyInfo' % MODULE_NAME, new=Mock(return_value=S_ERROR('proxy_err_testme'))): result = self.ujf.constructOutputLFNs() assertDiracFailsWith( result, 'could not obtain owner from proxy', self ) assertEqualsImproved( self.ujf.jobID, 8234, self )
def test_transferreg_transfer_fails( self ): self.ujf.failoverSEs = [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ] self.ujf.userFileCatalog = 'blaCatalogTestme' transfer_mock = Mock() transfer_mock.transferAndRegisterFileFailover.return_value = S_ERROR( 'some_transfer_test_err' ) filesUploaded = [] with patch('%s.random.shuffle' % MODULE_NAME) as shuffle_mock: result = self.ujf.transferRegisterAndFailoverFiles( transfer_mock, { 'filename1test' : { 'metadatadict1' : True, 'resolvedSE' : ( 'nonexistant', ) , 'localpath' : '/my/local/path/Testme.txt', 'lfn' : 'LFN:/ilc/mytest/LFN.txt', 'filedict' : 89546 } }, filesUploaded ) assertDiracSucceeds( result, self ) assertEqualsImproved( result['Value'], dict(cleanUp=True), self ) shuffle_mock.assert_called_once_with( [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ] ) transfer_mock.transferAndRegisterFileFailover.assert_called_once_with( 'filename1test', '/my/local/path/Testme.txt', 'LFN:/ilc/mytest/LFN.txt', 'nonexistant', [ 'testSite1', 'testSite2', 'myTestSite', 'privateSite4', 'etc' ], fileCatalog='blaCatalogTestme', fileMetaDict=89546 ) assertEqualsImproved( filesUploaded, [], self )
def test_native_compiler_preset(self): win_mach = get_win32_machine() win_mach.nativeCompiler() win_mach._ostype = 'Linux' result = win_mach.nativeCompiler() assertEqualsImproved(result, 'vc71', self) assertEqualsImproved(win_mach._compiler, 'vc71', self)
def test_osversion_linux_with_teststring( self ): mach = get_naked_machine() mach._ostype = 'Linux' with patch('%s.os.path.exists' % MODULE_NAME, new=Mock(return_value=True)), \ patch('%s.open' % MODULE_NAME, mock_open(read_data='somethingsomething\nUbuntu 19.3'), create=True): result = mach.OSVersion( 2, 'SuSE 3.6' ) assertEqualsImproved( result, '3.6', self ) assertEqualsImproved( mach._osversion, '3.6', self )
def test_setfilestatus_fails( self ): report_mock = Mock() report_mock.setFileStatus.return_value = S_ERROR('test_setfile_staterr') with patch('%s.FileReport' % MODULE_NAME, new=Mock(return_value=report_mock)): assertDiracFailsWith( self.moba.setFileStatus( 'production', 'lfn', 'status' ), 'test_setfile_staterr', self ) assertEqualsImproved( self.moba.workflow_commons['FileReport'], report_mock, self ) self.log_mock.warn.assert_called_once_with('test_setfile_staterr')
def test_setfilestatus_fails_useexistingfilereport( self ): report_mock = Mock() report_mock.setFileStatus.return_value = S_ERROR('test_setfilestat_err') self.moba.workflow_commons['FileReport'] = report_mock assertDiracFailsWith( self.moba.setFileStatus( 'production', 'lfn', 'status' ), 'test_setfilestat_err', self ) assertEqualsImproved( self.moba.workflow_commons['FileReport'], report_mock, self ) self.log_mock.warn.assert_called_once_with('test_setfilestat_err')
def test_osversion_linux_with_teststring(self): mach = get_naked_machine() mach._ostype = 'Linux' with patch('%s.os.path.exists' % MODULE_NAME, new=Mock(return_value=True)), \ patch('%s.open' % MODULE_NAME, mock_open(read_data='somethingsomething\nUbuntu 19.3'), create=True): result = mach.OSVersion(2, 'SuSE 3.6') assertEqualsImproved(result, '3.6', self) assertEqualsImproved(mach._osversion, '3.6', self)
def test_osflavor_win(self): nm = get_win32_machine() nm._sysinfo = ('Windows', 'dhellmann', '2008ServerR2', '6.1.7600', 'AMD64', 'Intel64 Family 6 Model 15 Stepping 11, GenuineIntel') result = nm.OSFlavour() assertEqualsImproved(result, '2008ServerR2', self) assertEqualsImproved(nm._osflavor, '2008ServerR2', self)
def test_setfiles_othercase( self ): with patch('os.path.exists', new=Mock(return_value=False)): self.assertFalse( self.mok._errorDict ) self.mok.setMacFile( '/invalid/dir/myMac.file' ) self.mok.setDbSlice( '/invalid/dir/someDb.sql' ) assertEqualsImproved( ( self.mok.macFile, self.mok.dbSlice ), ( '/invalid/dir/myMac.file', '/invalid/dir/someDb.sql' ), self ) self.assertFalse( self.mok._errorDict )
def test_execute_status_not_ok( self ): log = 'my_123_log.txt' self.over.applicationLog = log self.over.workflowStatus = S_ERROR('myerror167') with patch('%s.Operations.getValue' % MODULE_NAME, new=Mock(return_value=2)): result = self.over.execute() assertDiracSucceedsWith( result, 'OverlayInput should not proceed', self ) assertEqualsImproved( self.over.applicationLog, os.getcwd() + '/' + log, self )
def test_getsharedarealoc_notadir( self ): with patch('%s.Operations.getValue' % MODULE_NAME, new=Mock(return_value=[ 'testLocation135', '$MANY_MORE_LOCATIONS' ])), \ patch.dict( os.environ, { 'MANY_MORE_LOCATIONS' : '/abc/def/ghi'}, True ), \ patch('%s.os.path.exists' % MODULE_NAME, new=Mock(side_effect=[ False, True ])), \ patch('%s.DIRAC.gConfig.getValue' % MODULE_NAME, new=Mock(side_effect=['a', 'a', '', ''])), \ patch('%s.os.path.isdir' % MODULE_NAME, new=Mock(return_value=False)): result = getSharedAreaLocation() assertEqualsImproved( result, '', self )
def test_osversion_win_position_4(self): nm = get_win32_machine() nm._sysinfo = ('Windows', 'dhellmann', '2008ServerR2', '6.1.7600', 'AMD64', 'Intel64 Family 6 Model 15 Stepping 11, GenuineIntel') result = nm.OSVersion(4) assertEqualsImproved(result, '6.1.7600', self) assertEqualsImproved(nm._osversion, '6.1.7600', self)
def test_cmt_supported_config( self ): unix_mach = get_naked_machine() unix_mach._machine = 'x86_64' unix_mach._ostype = 'Darwin' unix_mach._sysinfo = ( 'Darwin', 'hubert.local', '9.4.2', 'Darwin Kernel Version 9.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64', 'x86_64', 'i386' ) assertEqualsImproved( unix_mach.CMTSupportedConfig(), [], self )