Skip to content

Commit

Permalink
Improve error message when cores or memory is not specified (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
rblcoder authored and lesteve committed Aug 29, 2019
1 parent f50607b commit 975425e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 5 additions & 7 deletions dask_jobqueue/core.py
Expand Up @@ -203,14 +203,12 @@ def __init__(
if shebang is None:
shebang = dask.config.get("jobqueue.%s.shebang" % config_name)

if cores is None:
raise ValueError(
"You must specify how many cores to use per job like ``cores=8``"
)

if memory is None:
if cores is None or memory is None:
raise ValueError(
"You must specify how much memory to use per job like ``memory='24 GB'``"
"You must specify how much cores and memory per job you want to use, for example:\n"
"cluster = {}(cores={}, memory={!r})".format(
self.__class__.__name__, cores or 8, memory or "24GB"
)
)

# This attribute should be overridden
Expand Down
16 changes: 16 additions & 0 deletions dask_jobqueue/tests/test_jobqueue_core.py
Expand Up @@ -173,3 +173,19 @@ def test_jobqueue_cluster_call(tmpdir):
match = re.compile(match, re.DOTALL)
with pytest.raises(RuntimeError, match=match):
cluster._call([sys.executable, path_with_error.strpath])


@pytest.mark.parametrize(
"Cluster",
[PBSCluster, MoabCluster, SLURMCluster, SGECluster, LSFCluster, OARCluster],
)
def test_cluster_has_cores_and_memory(Cluster):
cls_name = Cluster.__name__ + r"\("
with pytest.raises(ValueError, match=cls_name + r"cores=\d, memory='\d+GB'"):
Cluster()

with pytest.raises(ValueError, match=cls_name + r"cores=\d, memory='1GB'"):
Cluster(memory="1GB")

with pytest.raises(ValueError, match=cls_name + r"cores=4, memory='\d+GB'"):
Cluster(cores=4)

0 comments on commit 975425e

Please sign in to comment.