Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions longbow/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

EXECLIST = []
PLUGINEXECS = {}
MODNAMEOVERRIDES = {}

# Loop through all the modules in the plugin.
for loader, modulename, ispkg in MODULES:
Expand All @@ -61,3 +62,12 @@

# Compile a dictionary associating executable with plugins.
PLUGINEXECS[executable] = modulename

# Is the module named differently on HPC than the software is called.
try:

MODNAMEOVERRIDES[modulename] = getattr(mod, "MODULENAME").items()

except AttributeError:

pass
5 changes: 5 additions & 0 deletions longbow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def _processconfigsfinalinit(jobs):
"""Perform some last bits of initialisation."""
# Initialisation.
modules = getattr(apps, "PLUGINEXECS")
modoverrides = getattr(apps, "MODNAMEOVERRIDES")
modules[""] = ""

for job in [a for a in jobs if "lbowconf" not in a]:
Expand All @@ -452,6 +453,10 @@ def _processconfigsfinalinit(jobs):

jobs[job]["modules"] = modules[jobs[job]["executable"]]

if jobs[job]["modules"] in modoverrides:

jobs[job]["modules"] = modoverrides[jobs[job]["modules"]]

except KeyError:

pass
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/configuration/test_processconfigsfinalinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,33 @@
"""
This testing module contains the tests for the configuration module methods.
"""
try:

from unittest import mock

except ImportError:

import mock

import os
from longbow.configuration import _processconfigsfinalinit


def pluginsdata(_, data):

"""
mocked getattr call for external data.
"""

if data == "PLUGINEXECS":

return {"testexec": "testmodule"}

elif data == "MODNAMEOVERRIDES":

return {"testmodule": "fictionmodule"}


def test_processconfigsfinalinit1():

"""
Expand Down Expand Up @@ -102,3 +124,32 @@ def test_processconfigsfinalinit2():
assert jobs["test"]["destdir"] != ""
assert jobs["test"]["remoteworkdir"] == "/work/dir"
assert jobs["test"]["modules"] == ""


@mock.patch('longbow.configuration.getattr')
def test_processconfigsfinalinit3(attr):

"""
Test the modulename overrides
"""

jobs = {
"jobone": {
"modules": "",
"localworkdir": "/somepath/to/dir",
"executableargs": "arg1 arg2 arg3",
"executable": "testexec",
"remoteworkdir": "/work/dir"
}
}

attr.side_effect = pluginsdata

_processconfigsfinalinit(jobs)

assert jobs["jobone"]["localworkdir"] == "/somepath/to/dir"
assert jobs["jobone"]["executableargs"] == ["arg1", "arg2", "arg3"]
assert jobs["jobone"]["executable"] == "testexec"
assert jobs["jobone"]["destdir"] != ""
assert jobs["jobone"]["remoteworkdir"] == "/work/dir"
assert jobs["jobone"]["modules"] == "fictionmodule"