Skip to content

Commit d4a3c9d

Browse files
bdiceatravitz
andauthored
Require a scheduler to submit, even with --pretend enabled. (#533)
* Require a scheduler to submit, even with --pretend enabled. * Use TestEnvironment for submission tests. * Update changelog. * Update changelog.txt * Remove pretend argument (part of **kwargs). Co-authored-by: Alyssa Travitz <[email protected]>
1 parent c274ac4 commit d4a3c9d

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

changelog.txt

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Changed
2323

2424
- Jinja templates are indented for easier reading (#461, #495).
2525
- ``flow.directives`` is deprecated in favor of ``flow.FlowProject.operation.with_directives`` (#309, #502).
26+
- All environments require a scheduler in order to submit, even in pretend mode (#533).
27+
- Submitting in pretend mode will show additional scheduler command information (#533).
2628

2729
Fixed
2830
+++++

flow/project.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -3609,7 +3609,6 @@ def _submit_operations(
36093609
flags=None,
36103610
force=False,
36113611
template="script.sh",
3612-
pretend=False,
36133612
show_template_help=False,
36143613
**kwargs,
36153614
):
@@ -3630,9 +3629,6 @@ def _submit_operations(
36303629
template : str
36313630
The name of the template file to be used to generate the submission
36323631
script. (Default value = "script.sh")
3633-
pretend : bool
3634-
Do not actually submit, but only print the submission script to screen. Useful
3635-
for testing the submission workflow. (Default value = False)
36363632
show_template_help : bool
36373633
Show information about available template variables and filters and
36383634
exit. (Default value = False)
@@ -3692,13 +3688,9 @@ def _msg(group):
36923688
"the template script, including: %s",
36933689
", ".join(sorted(keys_unused)),
36943690
)
3695-
if pretend:
3696-
print(script)
3697-
3698-
else:
3699-
return self._environment.submit(
3700-
_id=_id, script=script, flags=flags, **kwargs
3701-
)
3691+
return self._environment.submit(
3692+
_id=_id, script=script, flags=flags, **kwargs
3693+
)
37023694

37033695
def submit(
37043696
self,

tests/test_project.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ def call_subcmd(self, subcmd, stderr=subprocess.DEVNULL):
193193
# Determine path to project module and construct command.
194194
fn_script = inspect.getsourcefile(type(self.project))
195195
_cmd = f"python {fn_script} {subcmd}"
196-
197196
try:
198197
with add_path_to_environment_pythonpath(os.path.abspath(self.cwd)):
199198
with switch_to_directory(self.project.root_directory()):
@@ -1522,29 +1521,41 @@ def setup_main_interface(self, request):
15221521
os.chdir(self._tmp_dir.name)
15231522
request.addfinalizer(self.switch_to_cwd)
15241523

1525-
def test_main_submit_walltime_with_directive(self):
1524+
def test_main_submit_walltime_with_directive(self, monkeypatch):
1525+
# Force the submitting subprocess to use the TestEnvironment and
1526+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1527+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
15261528
assert len(self.project)
15271529
output = self.call_subcmd(
15281530
"submit -o op_walltime --pretend --template slurm.sh",
15291531
subprocess.STDOUT,
15301532
).decode("utf-8")
15311533
assert "#SBATCH -t 01:00:00" in output
15321534

1533-
def test_main_submit_walltime_no_directive(self):
1535+
def test_main_submit_walltime_no_directive(self, monkeypatch):
1536+
# Force the submitting subprocess to use the TestEnvironment and
1537+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1538+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
15341539
assert len(self.project)
15351540
output = self.call_subcmd(
15361541
"submit -o op_walltime_2 --pretend --template slurm.sh", subprocess.STDOUT
15371542
).decode("utf-8")
15381543
assert "#SBATCH -t" not in output
15391544

1540-
def test_main_submit_walltime_with_groups(self):
1545+
def test_main_submit_walltime_with_groups(self, monkeypatch):
1546+
# Force the submitting subprocess to use the TestEnvironment and
1547+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1548+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
15411549
assert len(self.project)
15421550
output = self.call_subcmd(
15431551
"submit -o walltimegroup --pretend --template slurm.sh", subprocess.STDOUT
15441552
).decode("utf-8")
15451553
assert "#SBATCH -t 03:00:00" in output
15461554

1547-
def test_main_submit_walltime_serial(self):
1555+
def test_main_submit_walltime_serial(self, monkeypatch):
1556+
# Force the submitting subprocess to use the TestEnvironment and
1557+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1558+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
15481559
assert len(self.project)
15491560
job_id = next(iter(self.project)).get_id()
15501561
output = self.call_subcmd(
@@ -1554,7 +1565,10 @@ def test_main_submit_walltime_serial(self):
15541565
).decode("utf-8")
15551566
assert "#SBATCH -t 03:00:00" in output
15561567

1557-
def test_main_submit_walltime_parallel(self):
1568+
def test_main_submit_walltime_parallel(self, monkeypatch):
1569+
# Force the submitting subprocess to use the TestEnvironment and
1570+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1571+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
15581572
assert len(self.project)
15591573
job_id = next(iter(self.project)).get_id()
15601574
output = self.call_subcmd(
@@ -1926,7 +1940,10 @@ def test_main_run(self):
19261940
else:
19271941
assert not job.isfile("world.txt")
19281942

1929-
def test_main_submit(self):
1943+
def test_main_submit(self, monkeypatch):
1944+
# Force the submitting subprocess to use the TestEnvironment and
1945+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
1946+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
19301947
project = self.mock_project()
19311948
assert len(project)
19321949
# Assert that correct output for group submission is given
@@ -2069,7 +2086,10 @@ def test_main_run_cmd(self):
20692086

20702087
assert "1 and 2" in run_output
20712088

2072-
def test_main_submit(self):
2089+
def test_main_submit(self, monkeypatch):
2090+
# Force the submitting subprocess to use the TestEnvironment and
2091+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
2092+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
20732093
project = self.mock_project()
20742094
assert len(project)
20752095

@@ -2096,7 +2116,10 @@ def test_main_run(self):
20962116
assert job.doc.op2
20972117
assert job.doc.op3
20982118

2099-
def test_main_submit(self):
2119+
def test_main_submit(self, monkeypatch):
2120+
# Force the submitting subprocess to use the TestEnvironment and
2121+
# FakeScheduler via the SIGNAC_FLOW_ENVIRONMENT environment variable.
2122+
monkeypatch.setenv("SIGNAC_FLOW_ENVIRONMENT", "TestEnvironment")
21002123
project = self.mock_project()
21012124
assert len(project)
21022125

0 commit comments

Comments
 (0)