Skip to content

Commit

Permalink
Improve error message when cores or memory is not specified in cluste…
Browse files Browse the repository at this point in the history
…r class. (#362)
  • Loading branch information
lesteve authored and mrocklin committed Nov 4, 2019
1 parent b667430 commit af37667
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion dask_jobqueue/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ def __init__(
shebang = dask.config.get("jobqueue.%s.shebang" % config_name)

if cores is None or memory is None:
job_class_name = self.__class__.__name__
cluster_class_name = job_class_name.replace("Job", "Cluster")
raise ValueError(
"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"
cluster_class_name, cores or 8, memory or "24GB"
)
)

Expand Down
7 changes: 4 additions & 3 deletions dask_jobqueue/tests/test_jobqueue_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ def test_jobqueue_cluster_call(tmpdir):
[PBSCluster, MoabCluster, SLURMCluster, SGECluster, LSFCluster, OARCluster],
)
def test_cluster_has_cores_and_memory(Cluster):
with pytest.raises(ValueError, match=r"cores=\d, memory='\d+GB'"):
base_regex = r"{}.+".format(Cluster.__name__)
with pytest.raises(ValueError, match=base_regex + r"cores=\d, memory='\d+GB'"):
Cluster()

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

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

0 comments on commit af37667

Please sign in to comment.