Skip to content

Commit

Permalink
WIP test the get_jobs function
Browse files Browse the repository at this point in the history
  • Loading branch information
madwort committed Sep 25, 2024
1 parent 90a2cdd commit 424e8c0
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/cli/test_kill_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@
from tests.factories import job_factory


def test_get_jobs_partial_id(db, monkeypatch):
# make a fake job
job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING)

# take the first four characters to make a partial id
partial_job_id = job.id[:4]
partial_job_ids = [partial_job_id]

monkeypatch.setattr("builtins.input", lambda _: "")

# search for jobs with our partial id
output_job_ids = kill_job.get_jobs(partial_job_ids)

assert output_job_ids[0].id == job.id


def test_get_jobs_partial_id_quit(db, monkeypatch):
# make a fake job
job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING)

# take the first four characters to make a partial id
partial_job_id = job.id[:4]
partial_job_ids = [partial_job_id]

monkeypatch.setattr("builtins.input", lambda _: "")

# search for jobs with our partial id
output_job_ids = kill_job.get_jobs(partial_job_ids)

assert False


def test_get_jobs_full_id(db):
# make a fake job
job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING)

# this "partial id" is secretly a full id!!
full_job_id = job.id
full_job_ids = [full_job_id]

# search for jobs with our partial id
output_job_ids = kill_job.get_jobs(full_job_ids)

assert output_job_ids[0].id == job.id


@pytest.mark.parametrize("cleanup", [False, True])
def test_kill_job(cleanup, tmp_work_dir, db, monkeypatch):
job = job_factory(state=State.RUNNING, status_code=StatusCode.EXECUTING)
Expand Down

0 comments on commit 424e8c0

Please sign in to comment.