Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow + Job magic methods #369

Merged
merged 28 commits into from
Aug 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9087529
implement Flow __len__, __contains__, __iter__, __repr__ and arithmet…
janosh Jul 17, 2023
5f105d4
implement Job implement __contains__, __hash__, __repr__, __eq__
janosh Jul 17, 2023
e0c1555
increase Flow.__repr__ indentation for every level of subflow
janosh Jul 18, 2023
f9d3ece
drop 'consisting of n jobs' from repr
janosh Jul 18, 2023
771869d
add Flow.jobs setter
janosh Jul 29, 2023
a92252e
__setitem__ raise TypeError if value is not a Job or Flow
janosh Jul 29, 2023
11a02ce
Flow.__sub__ raise ValueError if the value is not in the flow
janosh Jul 29, 2023
c3ca465
fix line too long
janosh Jul 29, 2023
2fb76d7
add test_flow_magic_methods()
janosh Jul 29, 2023
d38c8e0
add test_flow_magic_methods_edge_cases()
janosh Jul 29, 2023
387da32
add test_flow_repr()
janosh Jul 29, 2023
47a0347
self.__class__.__name__ -> type(self).__name__
janosh Jul 29, 2023
763033e
use broader typing.Sequence for type hints
janosh Jul 29, 2023
e5aaf06
rewrite __copy__ to __deepcopy__
janosh Jul 29, 2023
1cf1b51
finish test_flow_magic_methods_edge_cases()
janosh Jul 29, 2023
8d3f400
Merge branch 'main' into flow-job-magic-methods
janosh Aug 7, 2023
2094ecd
fix mypy
janosh Aug 7, 2023
8fd0925
fix bad import auto-complete
janosh Aug 7, 2023
7a19168
make Job.__eq__ more strict: require self.__dict__ == other.__dict__ …
janosh Aug 7, 2023
59584ca
revert accidental auto-fix of implicit optional
janosh Aug 7, 2023
9940df0
add test_job_magic_methods()
janosh Aug 7, 2023
e26a924
coverage ignore if TYPE_CHECKING
janosh Aug 7, 2023
955c6b8
move test error msg for multiple stores to test_store_inputs()
janosh Aug 7, 2023
6dd27bd
add test for Flow.__setitem__ raising TypeError
janosh Aug 7, 2023
1307d30
add test Flow.__setitem__ with single item and __add__ with bad type
janosh Aug 7, 2023
962ad44
delete Job.__getitem__
janosh Aug 7, 2023
94fdb64
test passing single job to @jobs setter
janosh Aug 7, 2023
781d3b5
document difference between flow.iterflow() and flow.__iter__()
janosh Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test_job_magic_methods()
  • Loading branch information
janosh committed Aug 7, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ulyssa Ulyssa
commit 9940df02c8c28296d7c5ef4ca4fd91441d43941c
36 changes: 36 additions & 0 deletions tests/core/test_job.py
Original file line number Diff line number Diff line change
@@ -1261,3 +1261,39 @@ def use_maker(maker):
response = test_job.run(memory_jobstore)
assert response.replace.jobs[0].config == new_config
assert response.replace.jobs[0].config_updates[0]["config"] == new_config


def test_job_magic_methods():
import os

from jobflow import Job

# prepare test jobs
job1 = Job(function=sum, function_args=(1, 2))
job2 = Job(function=os.path.join, function_args=("folder", "filename.txt"))
job3 = Job(function=sum, function_args=(1, 2))

# test __repr__
assert repr(job1) == f"Job(name='sum', uuid='{job1.uuid}')"
assert repr(job2) == f"Job(name='join', uuid='{job2.uuid}')"
assert repr(job3) == f"Job(name='sum', uuid='{job3.uuid}')"
assert repr(job1) != repr(job3)

# test __contains__ (using some fake UUID)
# initial job.input_references is empty so can't test positive case
assert "fake-uuid" not in job1

# test __eq__
assert job1 == job1
assert job2 == job2
assert job1 != job2
assert job1 != job3 # Different UUIDs

# test __hash__
assert hash(job1) != hash(job2) != hash(job3)

# Test __init__ with True for multiple additional stores
with pytest.raises(
ValueError, match="Cannot select True for multiple additional stores"
):
_ = Job(function=sum, function_args=(1, 2), store1=True, store2=True)