Skip to content

Commit

Permalink
Merge pull request #225 from pyiron/nodeoutputjob_save
Browse files Browse the repository at this point in the history
[patch] NodeJobOutput: Overload the save function to not change the job name
  • Loading branch information
liamhuber committed Feb 28, 2024
2 parents 45a71b3 + ac1f72e commit 91c6b62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
13 changes: 12 additions & 1 deletion pyiron_workflow/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import os
import sys

from pyiron_base import TemplateJob, JOB_CLASS_DICT
from pyiron_base import GenericJob, TemplateJob, JOB_CLASS_DICT
from pyiron_base.jobs.flex.pythonfunctioncontainer import (
PythonFunctionContainerJob,
get_function_parameter_dict,
Expand Down Expand Up @@ -122,6 +122,17 @@ def run_static(self):
self.to_hdf()
self.status.finished = True

def save(self):
# PythonFunctionContainerJob.save assumes that the job is being created
# exclusively from pyiron_base.Project.wrap_python_function, and therefore
# always dynamically renames the job based on the wrapped function and the
# input.
# Here, the jobs are created in the usual way, with the usual use of job name,
# so it is just confusing if this renaming happens; thus, we save as usual.
# If at any point PythonFunctionContainerJob.save behaves in the usual way,
# this override can be removed
GenericJob.save(self)


JOB_CLASS_DICT[NodeOutputJob.__name__] = NodeOutputJob.__module__

Expand Down
32 changes: 30 additions & 2 deletions tests/unit/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,39 @@ def tearDown(self) -> None:


class TestNodeOutputJob(_WithAJob):
def make_a_job_from_node(self, node):
job = self.pr.create.job.NodeOutputJob(node.label)
def make_a_job_from_node(self, node, job_name=None):
job = self.pr.create.job.NodeOutputJob(
node.label if job_name is None else job_name
)
job.input["node"] = node
return job

@unittest.skipIf(sys.version_info < (3, 11), "Storage will only work in 3.11+")
def test_job_name_override(self):
job_name = "my_name"
job = self.make_a_job_from_node(
Workflow.create.standard.UserInput(42),
job_name=job_name
)
self.assertEqual(
job_name,
job.job_name,
msg="Sanity check"
)
try:
job.save()
self.assertEqual(
job_name,
job.job_name,
msg="Standard behaviour for the parent class is to dynamically rename "
"the job at save time; since we create these jobs as usual from "
"the job creator, this is just confusing and we want to avoid it. "
"If this behaviour is every changed in pyiron_base, the override "
"and this test can both be removed."
)
finally:
job.remove()

@unittest.skipIf(sys.version_info >= (3, 11), "Storage should only work in 3.11+")
def test_clean_failure(self):
with self.assertRaises(
Expand Down

0 comments on commit 91c6b62

Please sign in to comment.