Skip to content

Commit

Permalink
Add functionality to select all jobs that are finished
Browse files Browse the repository at this point in the history
Fixes #250
  • Loading branch information
mpvanderschelling committed Dec 13, 2023
1 parent 69dbb8b commit d82fbd0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
36 changes: 36 additions & 0 deletions tests/experimentdata/test__jobqueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd

from f3dasm._src.experimentdata._jobqueue import _JobQueue


def test_select_all_with_matching_status():
# Create a job queue with some jobs
job_queue = _JobQueue()
job_queue.jobs = pd.Series(['in progress', 'running', 'completed', 'in progress', 'failed'])

# Select all jobs with status 'in progress'
selected_jobs = job_queue.select_all('in progress')

# Check if the selected jobs match the expected result
assert (selected_jobs.jobs == ['in progress', 'in progress']).all()

def test_select_all_with_no_matching_status():
# Create a job queue with some jobs
job_queue = _JobQueue()
job_queue.jobs = pd.Series(['in progress', 'running', 'completed', 'in progress', 'failed'])

# Select all jobs with status 'cancelled'
selected_jobs = job_queue.select_all('cancelled')

# Check if the selected jobs match the expected result
assert selected_jobs.jobs.empty

def test_select_all_with_empty_job_queue():
# Create an empty job queue
job_queue = _JobQueue()

# Select all jobs with status 'in progress'
selected_jobs = job_queue.select_all('in progress')

# Check if the selected jobs match the expected result
assert selected_jobs.jobs.empty
26 changes: 25 additions & 1 deletion tests/experimentdata/test_experimentdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,5 +703,29 @@ def test_iter_behaviour(experimentdata_continuous: ExperimentData):
assert isinstance(i, ExperimentSample)


def test_select_with_status_open(experimentdata: ExperimentData):
selected_data = experimentdata.select_with_status('open')
assert all(job == Status.OPEN for job in selected_data._jobs.jobs)


def test_select_with_status_in_progress(experimentdata: ExperimentData):
selected_data = experimentdata.select_with_status('in progress')
assert all(job == Status.IN_PROGRESS for job in selected_data._jobs.jobs)


def test_select_with_status_finished(experimentdata: ExperimentData):
selected_data = experimentdata.select_with_status('finished')
assert all(job == Status.FINISHED for job in selected_data._jobs.jobs)


def test_select_with_status_error(experimentdata: ExperimentData):
selected_data = experimentdata.select_with_status('error')
assert all(job == Status.ERROR for job in selected_data._jobs.jobs)


def test_select_with_status_invalid_status(experimentdata: ExperimentData):
with pytest.raises(ValueError):
_ = experimentdata.select_with_status('invalid_status')

if __name__ == "__main__": # pragma: no cover
pytest.main()
pytest.main()

0 comments on commit d82fbd0

Please sign in to comment.