diff --git a/.gitlab-ci.d/run-setests.sh b/.gitlab-ci.d/run-setests.sh index 014f22d90fa892672b841f44d0d7d1536584f368..da8f19135e9676cd8df4cd3d0d40a1877d901b91 100755 --- a/.gitlab-ci.d/run-setests.sh +++ b/.gitlab-ci.d/run-setests.sh @@ -1,5 +1,5 @@ #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source .gitlab-ci.d/set-reportstyle.sh -export PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --cov-append --junit-xml=junit_se.xml" +export PYTEST_ADDOPTS="${PYTEST_ADDOPTS} --no-cov --junit-xml=junit_se.xml" pytest -n2 --randomly-dont-reorganize $DIR/../Tests/Integration/Test_SEs.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51d05631df287fcaaaceb34b17e616e45b6b5191..1099144117e28fadafc5a543ac94b4092d31a134 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -107,7 +107,7 @@ variables: - pip uninstall -y distribute - pip install --upgrade setuptools || echo "done" - pip install --upgrade setuptools_scm || echo "done scm" - - pip install --upgrade pylint mock MySQL-python pytest-cov pytest-randomly pytest-mock pytest-timeout pytest-xdist flake8 psutil flake8-docstrings flake8-commas caniusepython3 parameterized + - pip install --upgrade pylint mock MySQL-python pytest-cov pytest-randomly pytest-mock pytest-timeout pytest-xdist flake8 psutil flake8-docstrings flake8-commas caniusepython3 parameterized suds_jurko - cd .. artifacts: paths: @@ -343,12 +343,14 @@ prodTests:CC7: setests:SL6: <<: *seTests <<: *rule - <<: *sl6integration + <<: *sl6docker + needs: ["install:SL6"] setests:CC7: <<: *seTests <<: *rule - <<: *cc7integration + <<: *cc7docker + needs: ["install:CC7"] compiledoc: <<: *sl6docker @@ -463,7 +465,8 @@ deploydoc: docDev: <<: *doc variables: - EOS_PATH: "/eos/project/l/lcd-web/www/doc/ilcdiracdocDev/" + EOS_PATH: "/eos/project/l/lcd-web/www/doc/ilcdiracdocDev/" + CI_OUTPUT_DIR: "ilcdiracdoc" docProd: @@ -473,6 +476,7 @@ docProd: <<: *doc variables: EOS_PATH: "/eos/project/l/lcd-web/www/doc/ilcdiracdoc/" + CI_OUTPUT_DIR: "ilcdiracdoc" deploytag: diff --git a/Core/scripts/dirac-ilc-add-cvmfs-software.py b/Core/scripts/dirac-ilc-add-cvmfs-software.py index 98fcc9482ee23d7e2526d7b038a9917f3c296000..eeef50770d3056b00611ec8e92ad7ad5f29085a9 100644 --- a/Core/scripts/dirac-ilc-add-cvmfs-software.py +++ b/Core/scripts/dirac-ilc-add-cvmfs-software.py @@ -30,7 +30,8 @@ from DIRAC import gLogger, gConfig, S_OK, S_ERROR, exit as dexit __RCSID__ = "$Id$" -class Params(object): + +class _Params(object): """Collection of Parameters set via CLI switches""" def __init__( self ): self.version = '' @@ -310,7 +311,7 @@ class CVMFSAdder(object): def addSoftware(): """uploads, registers, and sends email about new software package""" - cliParams = Params() + cliParams = _Params() cliParams.registerSwitches() Script.parseCommandLine( ignoreErrors = True ) diff --git a/Core/scripts/dirac-ilc-add-software.py b/Core/scripts/dirac-ilc-add-software.py index 89ee5dc80de26a258f55ec802f681c5fb76e8f3f..add19cdffb92567e52d522d25331e6a8497989e1 100644 --- a/Core/scripts/dirac-ilc-add-software.py +++ b/Core/scripts/dirac-ilc-add-software.py @@ -16,7 +16,7 @@ except ImportError: import md5 -class Params(object): +class _Params(object): """Collection of Parameters set via CLI switches""" def __init__( self ): self.version = '' @@ -232,7 +232,7 @@ class SoftwareAdder(object): def addSoftware(): """uploads, registers, and sends email about new software package""" - cliParams = Params() + cliParams = _Params() cliParams.registerSwitches() Script.parseCommandLine( ignoreErrors = True ) platform = cliParams.platform diff --git a/Core/scripts/dirac-ilc-add-user.py b/Core/scripts/dirac-ilc-add-user.py index ac1a3641523c7502e01b4d9fac49c252145a9add..3739e32d349e39eb8b0d3ba97fe307f10a1aeb70 100644 --- a/Core/scripts/dirac-ilc-add-user.py +++ b/Core/scripts/dirac-ilc-add-user.py @@ -29,7 +29,9 @@ from DIRAC.Core.Base import Script from DIRAC import gLogger, gConfig, exit as dexit from DIRAC import S_OK, S_ERROR -class Params(object): + + +class _Params(object): """Parameter Object""" def __init__(self): self.uname = '' @@ -219,7 +221,7 @@ def getUserInfoFromPhonebook(client, clip): def addUser(): """Add user to configuration service and other things""" - clip = Params() + clip = _Params() clip.registerSwitches() Script.parseCommandLine() if not ( clip.certCN and clip.groups and clip.certDN and clip.uname): diff --git a/Core/scripts/dirac-ilc-add-whizard.py b/Core/scripts/dirac-ilc-add-whizard.py index 5f44c82513b75e8418e0bbde64fc77cc6f440dc2..856605b6f455f78f70edf984160b57371c5fa427 100644 --- a/Core/scripts/dirac-ilc-add-whizard.py +++ b/Core/scripts/dirac-ilc-add-whizard.py @@ -20,7 +20,8 @@ try: except ImportError: import md5 -class Params(object): + +class _Params(object): def __init__(self): self.path = '' self.version = '' @@ -158,7 +159,7 @@ def doTheWhizardInstallation(): gLogger.error(res['Message']) dexit(1) - cliParams = Params() + cliParams = _Params() cliParams.registerSwitches() Script.parseCommandLine( ignoreErrors= False) diff --git a/Core/scripts/dirac-ilc-list-users.py b/Core/scripts/dirac-ilc-list-users.py index cfc5f5c8f4e366d765cbfacf5b589ab337b1f21b..b7a1b24abecbf51b5608d3090e6a8e2e37878ef3 100644 --- a/Core/scripts/dirac-ilc-list-users.py +++ b/Core/scripts/dirac-ilc-list-users.py @@ -25,7 +25,8 @@ except ImportError: LOG.error("Run pip install suds_jurko") raise -class Params(object): + +class _Params(object): """Parameter Object""" def __init__(self): self.username = '' @@ -68,7 +69,7 @@ def printUser(user, addPrint): def printUsers(): """Print the list of users in the VO""" - clip = Params() + clip = _Params() clip.registerSwitches() Script.parseCommandLine() clip.setURLs() diff --git a/ILCTransformationSystem/Tests/Test_createMovingTransformation.py b/ILCTransformationSystem/Tests/Test_createMovingTransformation.py index f49c2bd6586065ceed330ba4e51e9d5c0223b7bd..ba1958a27c93a6edb7119cfe4a67963d4a75f607 100644 --- a/ILCTransformationSystem/Tests/Test_createMovingTransformation.py +++ b/ILCTransformationSystem/Tests/Test_createMovingTransformation.py @@ -196,7 +196,7 @@ def test_moving_createTrafo_force(movingModule, mocker): movingModule.Script.getPositionalArgs.return_value = ['12345', 'TargetSE', 'SourceSE', 'SIM'] PARAMS['flavour'] = 'Moving' PARAMS['forcemoving'] = True - mocker.patch(THE_SCRIPT + '.Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', + mocker.patch(THE_SCRIPT + '._Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', new=MyParams) parDict = dict(flavour='Moving', targetSE=['TargetSE'], @@ -218,7 +218,7 @@ def test_moving_createTrafo_REC(movingModule, mocker): movingModule.Script.getPositionalArgs.return_value = ['12346', 'TargetSE', 'SourceSE', 'REC'] PARAMS['flavour'] = 'Moving' PARAMS['forcemoving'] = False - mocker.patch(THE_SCRIPT + '.Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', + mocker.patch(THE_SCRIPT + '._Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', new=MyParams) parDict = dict(flavour='Moving', targetSE=['TargetSE'], @@ -257,7 +257,7 @@ def test_moving_createTrafo_notEnougParameters(movingModule): def test_repl_createTrafo(replModule, mocker): replModule.Script.getPositionalArgs.return_value = ['12345', 'TargetSE', 'SourceSE', 'SIM'] - mocker.patch(THE_REPL_SCRIPT + '.Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', + mocker.patch(THE_REPL_SCRIPT + '._Params', spec='ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters.Params', new=MyParams) PARAMS['flavour'] = 'Replication' PARAMS['plugin'] = 'Broadcast' diff --git a/ILCTransformationSystem/Tests/Test_diracClicMakeProductions.py b/ILCTransformationSystem/Tests/Test_diracClicMakeProductions.py index b68fe5da8085ae820d196770ea0858a252edc34a..46d4c03d0ea510bfaa5ca2275445ded98d603bd8 100644 --- a/ILCTransformationSystem/Tests/Test_diracClicMakeProductions.py +++ b/ILCTransformationSystem/Tests/Test_diracClicMakeProductions.py @@ -795,7 +795,7 @@ def test_loadFlags(theFlags): @pytest.fixture def theParams(): """Return the Params fixture.""" - return theScript.Params() + return theScript._Params() def test_params_init(theParams): diff --git a/ILCTransformationSystem/scripts/dirac-clic-make-productions.py b/ILCTransformationSystem/scripts/dirac-clic-make-productions.py index 4cea3b67675d91ad02b50a75129e677f52e435c7..56d249966f459219a9e19aeeb37bb79bcd15d434 100644 --- a/ILCTransformationSystem/scripts/dirac-clic-make-productions.py +++ b/ILCTransformationSystem/scripts/dirac-clic-make-productions.py @@ -163,7 +163,7 @@ STRING_ATTRIBUTES = ['configPackage', ] -class Params(object): +class _Params(object): """Parameter Object""" def __init__(self): self.prodConfigFilename = None @@ -1114,7 +1114,7 @@ overlayEventType = %(overlayEventType)s if __name__ == "__main__": - CLIP = Params() + CLIP = _Params() CLIP.registerSwitches() Script.parseCommandLine() from ILCDIRAC.Core.Utilities.CheckAndGetProdProxy import checkOrGetGroupProxy diff --git a/ILCTransformationSystem/scripts/dirac-ilc-get-prod-log.py b/ILCTransformationSystem/scripts/dirac-ilc-get-prod-log.py index 88f7d72531db024dcfe922a18b899f934048df23..a3b54db728d138b9b80ec9a221137d6da89ddd80 100644 --- a/ILCTransformationSystem/scripts/dirac-ilc-get-prod-log.py +++ b/ILCTransformationSystem/scripts/dirac-ilc-get-prod-log.py @@ -58,10 +58,12 @@ class _Params(object): return S_OK() def setQuery(self, query): + if ':' not in query: + return S_ERROR('Query syntax not correct') self.query = dict(q.split(':') for q in query.split(',')) return S_OK() - def registerSwitch(self): + def registerSwitches(self): """registers switches""" Script.registerSwitch('D:', 'LogFileDir=', 'Production log dir to download', self.setLogFileD) Script.registerSwitch('F:', 'LogFile=', 'Production log to download', self.setLogFileF) @@ -85,7 +87,7 @@ def _printErrorReport(res): def _getProdLogs(): """get production log files from LogSE""" clip = _Params() - clip.registerSwitch() + clip.registerSwitches() Script.parseCommandLine() if not ( clip.logF or clip.logD or clip.prodid ): Script.showHelp() diff --git a/ILCTransformationSystem/scripts/dirac-ilc-moving-transformation.py b/ILCTransformationSystem/scripts/dirac-ilc-moving-transformation.py index 6ba1de3939c5b229fdc6e1493cfe805b3c466406..4cd86b5982c5f1c707589cebba6b979e99024a20 100644 --- a/ILCTransformationSystem/scripts/dirac-ilc-moving-transformation.py +++ b/ILCTransformationSystem/scripts/dirac-ilc-moving-transformation.py @@ -25,7 +25,7 @@ from DIRAC.Core.Base import Script from DIRAC import gLogger as LOG, exit as dexit from DIRAC.TransformationSystem.Utilities.ReplicationTransformation import createDataTransformation -from ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters import Params, checkDatatype, \ +from ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters import Params as _Params, checkDatatype, \ getTransformationGroup __RCSID__ = "$Id$" @@ -41,7 +41,7 @@ def registerSwitches(clip, script): def _createTrafo(): """reads command line parameters, makes check and creates replication transformation""" - clip = Params() + clip = _Params() clip.flavour = 'Moving' clip.plugin = 'BroadcastProcessed' clip.groupSize = 10 diff --git a/ILCTransformationSystem/scripts/dirac-ilc-production-summary.py b/ILCTransformationSystem/scripts/dirac-ilc-production-summary.py index 3f94eb214b56532c6ef6759ec65b2b38848c1a04..55c94681405242647c53ad434048117d4b627dc5 100644 --- a/ILCTransformationSystem/scripts/dirac-ilc-production-summary.py +++ b/ILCTransformationSystem/scripts/dirac-ilc-production-summary.py @@ -18,7 +18,7 @@ import textwrap from DIRAC.Core.Base import Script from DIRAC.Core.Utilities.List import breakListIntoChunks -from DIRAC import S_OK, exit as dexit +from DIRAC import S_OK, exit as dexit, S_ERROR def _getFileInfo(lfn, fc): @@ -122,14 +122,17 @@ class _Params(object): else: parts = [opt] prods = [] - for part in parts: - if part.count("gt"): - self.minprod = int(part.replace("gt","")) - continue - if part.count("-"): - prods.extend(range(int(part.split("-")[0]), int(part.split("-")[1])+1)) - else: - prods.append(int(part)) + try: + for part in parts: + if part.count("gt"): + self.minprod = int(part.replace("gt", "")) + continue + if part.count("-"): + prods.extend(range(int(part.split("-")[0]), int(part.split("-")[1]) + 1)) + else: + prods.append(int(part)) + except ValueError: + return S_ERROR('ProductionID: bad syntax') self.prod = prods return S_OK() @@ -141,7 +144,10 @@ class _Params(object): def setSampleSize(self, opt): """Set the number of generator files to sample for cross-section and luminosity.""" - self.sampleSize = int(opt) + try: + self.sampleSize = int(opt) + except ValueError: + return S_ERROR('SampleSize: bad value') return S_OK() def setProdTypes(self, opt): @@ -154,7 +160,7 @@ class _Params(object): self.statuses = opt.split(",") return S_OK() - def registerSwitch(self): + def registerSwitches(self): """Register all CLI switches.""" Script.registerSwitch("P:", "prods=", "Productions: greater than with gt1234, range with 32-56, list with 34,56", self.setProdID) Script.registerSwitch("p", "precise_detail", "Precise detail, slow", self.setFullDetail) @@ -168,7 +174,7 @@ class _Params(object): def _getProductionSummary(): clip = _Params() - clip.registerSwitch() + clip.registerSwitches() Script.parseCommandLine() from ILCDIRAC.Core.Utilities.HTML import Table from ILCDIRAC.Core.Utilities.ProcessList import ProcessList diff --git a/ILCTransformationSystem/scripts/dirac-ilc-replication-transformation.py b/ILCTransformationSystem/scripts/dirac-ilc-replication-transformation.py index dafc61098cf5ebb08701a850da2315231ad3a97e..77a28c3ecccfa31ba11241d4dca9d9d2788ba3ca 100644 --- a/ILCTransformationSystem/scripts/dirac-ilc-replication-transformation.py +++ b/ILCTransformationSystem/scripts/dirac-ilc-replication-transformation.py @@ -21,7 +21,7 @@ from DIRAC.Core.Base import Script from DIRAC import gLogger, exit as dexit from DIRAC.TransformationSystem.Utilities.ReplicationTransformation import createDataTransformation -from ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters import Params, getTransformationGroup +from ILCDIRAC.ILCTransformationSystem.Utilities.DataParameters import Params as _Params, getTransformationGroup __RCSID__ = "$Id$" @@ -34,7 +34,7 @@ def registerSwitches(script): def _createTrafo(): """reads command line parameters, makes check and creates replication transformation""" - clip = Params() + clip = _Params() clip.groupSize = 10 clip.registerSwitches(Script) registerSwitches(Script) diff --git a/ILCTransformationSystem/scripts/dirac-ilc-upload-gen-files.py b/ILCTransformationSystem/scripts/dirac-ilc-upload-gen-files.py index d5ddae35157919a72a444fe8fdd917b98c8360b5..5cf3f3839dcce913fc8301352895457b5351cb71 100644 --- a/ILCTransformationSystem/scripts/dirac-ilc-upload-gen-files.py +++ b/ILCTransformationSystem/scripts/dirac-ilc-upload-gen-files.py @@ -78,7 +78,7 @@ class _Params(object): return S_ERROR("Energy should be unit less, only integers") return S_OK() - def setProcessID(self,opt): + def setProcessID(self, opt): try: self.fmeta['GenProcessID'] = int(opt) except ValueError: @@ -95,11 +95,17 @@ class _Params(object): return S_OK() def setLumi(self,opt): - self.lumi = float(opt) + try: + self.lumi = float(opt) + except ValueError: + return S_ERROR('Luminosity: bad value') return S_OK() def setNumberOfEvents(self,opt): - self.fmeta['NumberOfEvents'] = int(opt) + try: + self.fmeta['NumberOfEvents'] = int(opt) + except ValueError: + return S_ERROR('NumberOfEvents: bad value') return S_OK() def setBeamP1(self, opt): diff --git a/ILCTransformationSystem/scripts/dirac-transformation-recover-data.py b/ILCTransformationSystem/scripts/dirac-transformation-recover-data.py index 750250f1e051c95d6e212293afb150e8f731d31b..407b9f5754e0772e07b059c4c31ff7193036495e 100755 --- a/ILCTransformationSystem/scripts/dirac-transformation-recover-data.py +++ b/ILCTransformationSystem/scripts/dirac-transformation-recover-data.py @@ -1,13 +1,13 @@ #!/bin/env python """Script to call the DataRecoveryAgent functionality by hand.""" -from DIRAC import S_OK, gLogger +from DIRAC import S_OK, S_ERROR, gLogger from DIRAC.Core.Base import Script __RCSID__ = '$Id$' -class Params(object): +class _Params(object): """Collection of Parameters set via CLI switches.""" def __init__(self): @@ -19,7 +19,10 @@ class Params(object): return S_OK() def setProdID(self, prodID): - self.prodID = int(prodID) + try: + self.prodID = int(prodID) + except ValueError: + return S_ERROR('ProdID: Bad Value') return S_OK() def registerSwitches(self): @@ -31,7 +34,7 @@ class Params(object): if __name__ == '__main__': - PARAMS = Params() + PARAMS = _Params() PARAMS.registerSwitches() Script.parseCommandLine(ignoreErrors=False) diff --git a/Interfaces/scripts/TestAndProbeSites.py b/Interfaces/scripts/TestAndProbeSites.py index 6da532e05d5d5376d776726cd6b7172808eddd00..98838bd0565488ca5863800bf98b06a0f7188641 100755 --- a/Interfaces/scripts/TestAndProbeSites.py +++ b/Interfaces/scripts/TestAndProbeSites.py @@ -8,7 +8,8 @@ from DIRAC import gLogger LOG = gLogger.getSubLogger(__name__) -class Params(object): + +class _Params(object): def __init__(self): self.site = None self.ce = None @@ -28,7 +29,7 @@ class Params(object): def testAndProbeSites(): """submits jobs to test sites""" - clip = Params() + clip = _Params() clip.registerSwitches() Script.parseCommandLine() diff --git a/Tests/test_scriptCLI.py b/Tests/test_scriptCLI.py new file mode 100644 index 0000000000000000000000000000000000000000..c1e42534d98c53056a56f988b11f97af15d312a1 --- /dev/null +++ b/Tests/test_scriptCLI.py @@ -0,0 +1,126 @@ +"""Test the command line options for the scrips.""" +from copy import deepcopy +import importlib +import logging +import random +import pytest + + +def ris(): + """Return random int as string.""" + return str(random.randint(0, 100000)) + + +def fis(): + """Return foo plus random int as string.""" + return 'foo' + str(random.randint(0, 100000)) + + +SCRIPTS = [('ILCDIRAC.Core.scripts.dirac-ilc-add-cvmfs-software', {}), + ('ILCDIRAC.Core.scripts.dirac-ilc-add-software', {}), + ('ILCDIRAC.Core.scripts.dirac-ilc-add-user', {'Email': {'S': ['foo@bar.baz'], 'E': [fis()]}, + 'VO': {'S': ['calice'], 'E': ['vo']}}), + ('ILCDIRAC.Core.scripts.dirac-ilc-add-whizard', {}), + ('ILCDIRAC.Core.scripts.dirac-ilc-list-users', {'VO': {'S': ['calice'], 'E': ['vo']}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-clic-make-productions', {'configFile': {'E': ['any'], + 'S': []}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-add-tasks-to-prod', {'Tasks': + {'E': [fis()], 'S': [ris()]}, + 'ProductionID': + {'E': [fis()], 'S': [ris()]}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-filestatus-transformation', {}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-get-info', {'ProductionID': + {'E': [fis()], 'S': [ris()]}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-get-prod-log', + {'Query': {'S': ['Foo:Bar'], 'E': ['FooBar']}}), + # ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-make-ddsimtarball', {}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-moving-transformation', {'ps': True}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-production-summary', {'prods': + {'E': [fis()], 'S': [ris()]}, + 'sample_size': + {'E': [fis()], 'S': [ris()]}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-replication-transformation', {'ps': True}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-ilc-upload-gen-files', {'Energy': + {'E': [fis()], 'S': [ris()]}, + 'EvtID': + {'E': [fis()], 'S': [ris()]}, + 'NumberOfEvents': + {'E': [fis()], 'S': [ris()]}, + 'XSectionError': + {'E': [fis()], 'S': [ris()]}, + 'XSection': + {'E': [fis()], 'S': [ris()]}, + 'Luminosity': + {'E': [fis()], 'S': [ris()]}}), + ('ILCDIRAC.ILCTransformationSystem.scripts.dirac-transformation-recover-data', {'ProdID': + {'E': [fis()], 'S': [ris()]}, + }), + ('ILCDIRAC.Interfaces.scripts.dirac-ilc-find-in-FC', {}), + ('ILCDIRAC.Interfaces.scripts.dirac-ilc-show-software', {}), + ('ILCDIRAC.Interfaces.scripts.dirac-repo-create-lfn-list', {}), + ('ILCDIRAC.Interfaces.scripts.dirac-repo-retrieve-jobs-output-data', {}), + ('ILCDIRAC.Interfaces.scripts.dirac-repo-retrieve-jobs-output', {}), + ('ILCDIRAC.Interfaces.scripts.TestAndProbeSites', {}), + ] + + +@pytest.mark.parametrize('scriptPath, options', SCRIPTS) +def test_scriptCLI(caplog, scriptPath, options, mocker): + """Check that calling the callback does something.""" + caplog.set_level(logging.DEBUG) + rsm = mocker.Mock() + mocker.patch('DIRAC.Core.Base.Script.registerSwitch', new=rsm) + try: + module = importlib.import_module(scriptPath) + except ImportError: + assert False + try: + paramClass = getattr(module, '_Params') + theParams = paramClass() + if options.get('ps'): + theParams.registerSwitches(rsm) + else: + theParams.registerSwitches() + except AttributeError as e: + logging.info(dir(module)) + assert False, 'ERROR: ' + str(e) + return theParams + + for call in rsm.call_args_list: + logging.info(call) + flag = call[0][1].strip('=:') + callback = call[0][3] + if isinstance(callback, bool): + continue + paramBefor = deepcopy(vars(theParams)) + errorFlags = options.get(flag, {}).get('E', []) + successFlags = options.get(flag, {}).get('S', [ris(), fis()]) + for value in errorFlags: + retVal = callback(value) + assert not retVal['OK'], 'Value should cause failure' + + for value in successFlags: + retVal = callback(value) + if not retVal['OK']: + assert False, 'failure for ' + value + flag + str(successFlags) + str(options) + continue + + paramAfter = vars(theParams) + logging.info('befor: %s', sorted(paramBefor)) + logging.info('after: %s', sorted(paramAfter)) + logging.info('befor: %s', paramBefor.values()) + logging.info('after: %s', paramAfter.values()) + assert paramBefor != paramAfter + # assert any(randVal in aVal for aVal in paramAfter.values() if aVal) + diff = 0 + for name, befor in paramBefor.items(): + after = paramAfter[name] + logging.info('Befor: %r -- After: %r', befor, after) + if after == value: + logging.info('The Rand Val: %r', value) + diff = 1 + break + if befor != after: + logging.info('Difference') + diff += 1 + assert diff == 1 diff --git a/pytest.ini b/pytest.ini index 8d477d7a9461b554e709a61bdf23747d4e222a12..584e04683b90b2b88f735585f46581675878ff7b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,4 +4,7 @@ python_files=[tT]est*.py # find all Test*, Test_*, *tests, *test, etc. files. Mi python_classes=*Test* python_functions=test_* markers = - integration: tests requiring a proxy \ No newline at end of file + integration: tests requiring a proxy + +log_format = %(name)s %(levelname)s %(message)s +log_date_format = %Y-%m-%d %H:%M:%S \ No newline at end of file