From 0c30617c24ace0bde14a32a2218aa93acbabeac7 Mon Sep 17 00:00:00 2001 From: James Gebbie-Rayet Date: Tue, 7 Nov 2017 15:14:38 +0000 Subject: [PATCH] Issue #75 Further problems with absolute paths where a keyerror would occur on the executable. A fix has been applied where the os.path.basename is run against the executable. This should at least allow longbow to match the executables that it knows. --- longbow/corelibs/applications.py | 22 +++++++------ .../corelibs_applications/test_processjobs.py | 33 ++++++++++++++++++- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/longbow/corelibs/applications.py b/longbow/corelibs/applications.py index 8e5fff1..2e2c666 100755 --- a/longbow/corelibs/applications.py +++ b/longbow/corelibs/applications.py @@ -147,7 +147,7 @@ def processjobs(jobs): filelist = [] appplugins = getattr(apps, "PLUGINEXECS") - app = appplugins[jobs[job]["executable"]] + app = appplugins[os.path.basename(jobs[job]["executable"])] foundflags = [] substitution = {} @@ -180,7 +180,7 @@ def processjobs(jobs): "The local job directory '{0}' cannot be found for job '{1}'" .format(jobs[job]["localworkdir"], job)) - # Detect command-line parameter substitutions. + # Hook to determine command-line parameter substitutions. try: substitution = getattr( @@ -222,8 +222,9 @@ def _flagvalidator(job, foundflags): """Validate that required command-line flags are provided.""" # Initialisation. appplugins = getattr(apps, "PLUGINEXECS") - app = appplugins[job["executable"]] - execdata = getattr(apps, app.lower()).EXECDATA[job["executable"]] + executable = os.path.basename(job["executable"]) + app = appplugins[executable] + execdata = getattr(apps, app.lower()).EXECDATA[executable] # Final check for if any required flags are missing. flags = list(set(execdata["requiredfiles"]) - set(foundflags)) @@ -288,17 +289,17 @@ def _proccommandline(job, filelist, foundflags, substitution): """ # Initialisation. appplugins = getattr(apps, "PLUGINEXECS") - app = appplugins[job["executable"]] + executable = os.path.basename(job["executable"]) + app = appplugins[executable] args = list(job["executableargs"]) - subexecs = getattr( - apps, app.lower()).EXECDATA[job["executable"]]["subexecutables"] + subexe = getattr(apps, app.lower()).EXECDATA[executable]["subexecutables"] try: for arg in args: if (arg != "<" and arg != ">" and arg[0] != "-" and - arg not in subexecs): + arg not in subexe): foundflags = _procfiles(job, arg, filelist, foundflags, substitution) @@ -318,7 +319,8 @@ def _procfiles(job, arg, filelist, foundflags, substitution): """Processor for finding flags and files.""" # Initialisation. appplugins = getattr(apps, "PLUGINEXECS") - app = appplugins[job["executable"]] + executable = os.path.basename(job["executable"]) + app = appplugins[executable] initargs = list(job["executableargs"]) # Check for as many files as there are replicates (default of 1). @@ -349,7 +351,7 @@ def _procfiles(job, arg, filelist, foundflags, substitution): _markfoundfiles(arg, initargs, foundflags) - # Search input file for any file dependencies. + # Hook to search input file for any file dependencies. try: getattr(apps, app.lower()).file_parser( diff --git a/tests/unit/corelibs_applications/test_processjobs.py b/tests/unit/corelibs_applications/test_processjobs.py index 9a8508d..fe1c17e 100644 --- a/tests/unit/corelibs_applications/test_processjobs.py +++ b/tests/unit/corelibs_applications/test_processjobs.py @@ -98,7 +98,38 @@ def test_processjobs_pardir(): @mock.patch('longbow.corelibs.applications._proccommandline') @mock.patch('longbow.corelibs.applications._flagvalidator') -def test_processjobs_singlejob(m_validator, m_proccommandline): +def test_processjobs_singlejob1(m_validator, m_proccommandline): + + """Test for single job, make sure parameters are all set correctly.""" + + jobs = { + "jobone": { + "executableargs": ["-i", "input", "-c", "coords", "-p", "topol"], + "localworkdir": os.path.join(os.getcwd(), + "tests/standards/jobs/single"), + "executable": "/some/path/pmemd.MPI", + "upload-include": "", + "upload-exclude": "" + } + } + + m_proccommandline.side_effect = _proccommandline + + m_validator.return_value = None + + processjobs(jobs) + + assert jobs["jobone"]["upload-exclude"] == "*" + assert jobs["jobone"]["localworkdir"] == os.path.join( + os.getcwd(), "tests/standards/jobs/single") + assert jobs["jobone"]["executableargs"] == \ + "/some/path/pmemd.MPI -i input -c coords -p topol" + assert jobs["jobone"]["upload-include"] == "input, coords, topol" + + +@mock.patch('longbow.corelibs.applications._proccommandline') +@mock.patch('longbow.corelibs.applications._flagvalidator') +def test_processjobs_singlejob2(m_validator, m_proccommandline): """Test for single job, make sure parameters are all set correctly."""