Skip to content

Commit abb06a2

Browse files
committed
more value checking, move tests to launcher specific tests
1 parent 39e8e1c commit abb06a2

File tree

7 files changed

+90
-41
lines changed

7 files changed

+90
-41
lines changed

smartsim/settings/arguments/batch/lsf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ def set_walltime(self, walltime: str) -> None:
5757
:param walltime: Time in hh:mm format, e.g. "10:00" for 10 hours,
5858
if time is supplied in hh:mm:ss format, seconds
5959
will be ignored and walltime will be set as ``hh:mm``
60+
:raises TypeError: if not type str
6061
"""
6162
# For compatibility with other launchers, as explained in docstring
63+
if not isinstance(walltime, str):
64+
raise TypeError("walltime argument was not of type str")
6265
if walltime:
6366
if len(walltime.split(":")) > 2:
6467
walltime = ":".join(walltime.split(":")[:2])

smartsim/settings/arguments/batch/pbs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ def set_walltime(self, walltime: str) -> None:
9595
9696
:param walltime: wall time
9797
:raises ValueError: if walltime format is invalid
98+
:raises TypeError: if not type str
9899
"""
100+
if not isinstance(walltime, str):
101+
raise TypeError("walltime argument was not of type str")
99102
pattern = r"^\d{2}:\d{2}:\d{2}$"
100103
if walltime and re.match(pattern, walltime):
101104
self.set("walltime", walltime)
@@ -110,7 +113,7 @@ def set_queue(self, queue: str) -> None:
110113
"""
111114
if not isinstance(queue, str):
112115
raise TypeError("queue argument was not of type str")
113-
self.set("q", str(queue))
116+
self.set("q", queue)
114117

115118
def set_ncpus(self, num_cpus: int) -> None:
116119
"""Set the number of cpus obtained in each node.
@@ -134,7 +137,7 @@ def set_account(self, account: str) -> None:
134137
"""
135138
if not isinstance(account, str):
136139
raise TypeError("account argument was not of type str")
137-
self.set("A", str(account))
140+
self.set("A", account)
138141

139142
def format_batch_args(self) -> t.List[str]:
140143
"""Get the formatted batch arguments for a preview

smartsim/settings/arguments/batch/slurm.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def set_walltime(self, walltime: str) -> None:
5757
5858
:param walltime: wall time
5959
:raises ValueError: if walltime format is invalid
60+
:raises TypeError: if not str
6061
"""
62+
if not isinstance(walltime, str):
63+
raise TypeError("walltime argument was not of type str")
6164
pattern = r"^\d{2}:\d{2}:\d{2}$"
6265
if walltime and re.match(pattern, walltime):
6366
self.set("time", str(walltime))
@@ -94,8 +97,11 @@ def set_partition(self, partition: str) -> None:
9497
This sets ``--partition``.
9598
9699
:param partition: partition name
100+
:raises TypeError: if not a str
97101
"""
98-
self.set("partition", str(partition))
102+
if not isinstance(partition, str):
103+
raise TypeError("partition argument was not of type str")
104+
self.set("partition", partition)
99105

100106
def set_queue(self, queue: str) -> None:
101107
"""alias for set_partition
@@ -115,7 +121,10 @@ def set_cpus_per_task(self, cpus_per_task: int) -> None:
115121
This sets ``--cpus-per-task``
116122
117123
:param num_cpus: number of cpus to use per task
124+
:raises TypeError: if not int
118125
"""
126+
if not isinstance(cpus_per_task, int):
127+
raise TypeError("cpus_per_task argument was not of type int")
119128
self.set("cpus-per-task", str(cpus_per_task))
120129

121130
def set_hostlist(self, host_list: t.Union[str, t.List[str]]) -> None:

tests/temp_tests/test_settings/test_batchSettings.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -159,41 +159,3 @@ def test_batch_arguments_type_set_queue(scheduler):
159159
bs = BatchSettings(batch_scheduler=scheduler, env_vars={"ENV": "VAR"})
160160
with pytest.raises(TypeError, match="queue argument was not of type str"):
161161
bs.batch_args.set_queue(27)
162-
163-
164-
@pytest.mark.parametrize(
165-
"scheduler",
166-
[
167-
pytest.param("slurm", id="slurm scheduler"),
168-
pytest.param("lsf", id="bsub scheduler"),
169-
pytest.param("pbs", id="qsub scheduler"),
170-
],
171-
)
172-
def test_batch_arguments_type_set_hostlist(scheduler):
173-
bs = BatchSettings(batch_scheduler=scheduler, env_vars={"ENV": "VAR"})
174-
with pytest.raises(TypeError, match="host_list argument must be a list of strings"):
175-
bs.batch_args.set_hostlist([25, 37])
176-
177-
178-
def test_batch_arguments_type_set_ncpus():
179-
bs = BatchSettings(batch_scheduler="pbs", env_vars={"ENV": "VAR"})
180-
with pytest.raises(TypeError, match="num_cpus argument was not of type int"):
181-
bs.batch_args.set_ncpus("invalid")
182-
183-
184-
def test_batch_arguments_type_set_smts():
185-
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
186-
with pytest.raises(TypeError, match="smts argument was not of type int"):
187-
bs.batch_args.set_smts("invalid")
188-
189-
190-
def test_batch_arguments_type_set_project():
191-
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
192-
with pytest.raises(TypeError, match="project argument was not of type str"):
193-
bs.batch_args.set_project(27)
194-
195-
196-
def test_batch_arguments_type_set_tasks():
197-
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
198-
with pytest.raises(TypeError, match="tasks argument was not of type int"):
199-
bs.batch_args.set_tasks("invalid")

tests/temp_tests/test_settings/test_lsfScheduler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,33 @@ def test_create_bsub():
7575
lsfScheduler.batch_args.set_queue("default")
7676
args = lsfScheduler.format_batch_args()
7777
assert args == ["-core_isolation", "-nnodes", "1", "-W", "10:10", "-q", "default"]
78+
79+
80+
def test_batch_arguments_type_set_hostlist(scheduler):
81+
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
82+
with pytest.raises(TypeError, match="host_list argument must be a list of strings"):
83+
bs.batch_args.set_hostlist([25, 37])
84+
85+
86+
def test_batch_arguments_type_set_smts():
87+
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
88+
with pytest.raises(TypeError, match="smts argument was not of type int"):
89+
bs.batch_args.set_smts("invalid")
90+
91+
92+
def test_batch_arguments_type_set_project():
93+
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
94+
with pytest.raises(TypeError, match="project argument was not of type str"):
95+
bs.batch_args.set_project(27)
96+
97+
98+
def test_batch_arguments_type_set_tasks():
99+
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
100+
with pytest.raises(TypeError, match="tasks argument was not of type int"):
101+
bs.batch_args.set_tasks("invalid")
102+
103+
104+
def test_batch_arguments_type_set_walltime():
105+
bs = BatchSettings(batch_scheduler="lsf", env_vars={"ENV": "VAR"})
106+
with pytest.raises(TypeError, match="walltime argument was not of type str"):
107+
bs.batch_args.set_walltime(27)

tests/temp_tests/test_settings/test_pbsScheduler.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,21 @@ def test_format_pbs_batch_args():
8686
"-A",
8787
"myproject",
8888
]
89+
90+
91+
def test_batch_arguments_type_set_hostlist(scheduler):
92+
bs = BatchSettings(batch_scheduler="pbs", env_vars={"ENV": "VAR"})
93+
with pytest.raises(TypeError, match="host_list argument must be a list of strings"):
94+
bs.batch_args.set_hostlist([25, 37])
95+
96+
97+
def test_batch_arguments_type_set_ncpus():
98+
bs = BatchSettings(batch_scheduler="pbs", env_vars={"ENV": "VAR"})
99+
with pytest.raises(TypeError, match="num_cpus argument was not of type int"):
100+
bs.batch_args.set_ncpus("invalid")
101+
102+
103+
def test_batch_arguments_type_set_walltime():
104+
bs = BatchSettings(batch_scheduler="pbs", env_vars={"ENV": "VAR"})
105+
with pytest.raises(TypeError, match="walltime argument was not of type str"):
106+
bs.batch_args.set_walltime(27)

tests/temp_tests/test_settings/test_slurmScheduler.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,27 @@ def test_sbatch_manual():
134134
formatted = slurmScheduler.format_batch_args()
135135
result = ["--nodes=5", "--account=A3531", "--time=10:00:00"]
136136
assert formatted == result
137+
138+
139+
def test_batch_arguments_type_set_walltime():
140+
bs = BatchSettings(batch_scheduler="slurm", env_vars={"ENV": "VAR"})
141+
with pytest.raises(TypeError, match="walltime argument was not of type str"):
142+
bs.batch_args.set_walltime(27)
143+
144+
145+
def test_batch_arguments_type_set_cpus_per_task():
146+
bs = BatchSettings(batch_scheduler="slurm", env_vars={"ENV": "VAR"})
147+
with pytest.raises(TypeError, match="cpus_per_task argument was not of type int"):
148+
bs.batch_args.set_cpus_per_task("invalid")
149+
150+
151+
def test_batch_arguments_type_set_partition():
152+
bs = BatchSettings(batch_scheduler="slurm", env_vars={"ENV": "VAR"})
153+
with pytest.raises(TypeError, match="partition argument was not of type str"):
154+
bs.batch_args.set_partition(27)
155+
156+
157+
def test_batch_arguments_type_set_hostlist(scheduler):
158+
bs = BatchSettings(batch_scheduler="slurm", env_vars={"ENV": "VAR"})
159+
with pytest.raises(TypeError, match="host_list argument must be a list of strings"):
160+
bs.batch_args.set_hostlist([25, 37])

0 commit comments

Comments
 (0)