From 798676b4b5b6fd320db0e121c5310d21f266702f Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 7 Mar 2024 16:41:44 -0500 Subject: [PATCH] Convert + improve test_job/task_metrics --- test/unit/data/data_access/conftest.py | 28 ++++++++++++++++++++++ test/unit/data/data_access/test_misc.py | 31 +++++++++++++++++++++++++ test/unit/data/test_galaxy_mapping.py | 21 ----------------- 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/test/unit/data/data_access/conftest.py b/test/unit/data/data_access/conftest.py index d41311448334..5d5c78ec8c66 100644 --- a/test/unit/data/data_access/conftest.py +++ b/test/unit/data/data_access/conftest.py @@ -169,6 +169,18 @@ def f(**kwd): return f +@pytest.fixture +def make_job(session): + def f(**kwd): + job = m.Job(**kwd) + with transaction(session): + session.add(job) + session.commit() + return job + + return f + + @pytest.fixture def make_ldca(session): def f(**kwd): @@ -270,6 +282,22 @@ def f(**kwd): return f +@pytest.fixture +def make_task(session, make_job): + def f(**kwd): + kwd["job"] = kwd.get("job", make_job()) + # Assumption: if the following args are needed, a test should supply them + kwd["working_directory"] = kwd.get("working_directory", random_str()) + kwd["prepare_files_cmd"] = kwd.get("prepare_files_cmd", random_str()) + task = m.Task(**kwd) + with transaction(session): + session.add(task) + session.commit() + return task + + return f + + @pytest.fixture def make_user(session): def f(**kwd): diff --git a/test/unit/data/data_access/test_misc.py b/test/unit/data/data_access/test_misc.py index bf2373ef72aa..5a7c74e83fcc 100644 --- a/test/unit/data/data_access/test_misc.py +++ b/test/unit/data/data_access/test_misc.py @@ -278,3 +278,34 @@ def test_metadata_spec(make_hda): assert d.metadata.chromCol == 1 assert d.metadata.anyAttribute is None assert "items" not in d.metadata + + +def test_job_metrics(make_job): + job = make_job() + job.add_metric("gx", "galaxy_slots", 5) + job.add_metric("system", "system_name", "localhost") + + assert len(job.text_metrics) == 1 + assert job.text_metrics[0].plugin == "system" + assert job.text_metrics[0].metric_name == "system_name" + assert job.text_metrics[0].metric_value == "localhost" + assert len(job.numeric_metrics) == 1 + assert job.numeric_metrics[0].plugin == "gx" + assert job.numeric_metrics[0].metric_name == "galaxy_slots" + assert job.numeric_metrics[0].metric_value == 5 + + +def test_task_metrics(make_task): + task = make_task() + task.add_metric("foo", "some-name", "some-value") + big_value = ":".join(f"{i}" for i in range(2000)) + task.add_metric("env", "BIG_PATH", big_value) + + assert len(task.text_metrics) == 2 + assert task.text_metrics[0].plugin == "foo" + assert task.text_metrics[0].metric_name == "some-name" + assert task.text_metrics[0].metric_value == "some-value" + assert task.text_metrics[1].plugin == "env" + assert task.text_metrics[1].metric_name == "BIG_PATH" + # Ensure big values truncated + assert len(task.text_metrics[1].metric_value) <= 1023 diff --git a/test/unit/data/test_galaxy_mapping.py b/test/unit/data/test_galaxy_mapping.py index 10adb57de9ec..2063074fd07e 100644 --- a/test/unit/data/test_galaxy_mapping.py +++ b/test/unit/data/test_galaxy_mapping.py @@ -211,27 +211,6 @@ def test_nested_collection_attributes(self): ] assert c4.dataset_elements == [dce1, dce2] - def test_job_metrics(self): - u = model.User(email="jobtest@foo.bar.baz", password="password") - job = model.Job() - job.user = u - job.tool_id = "cat1" - - job.add_metric("gx", "galaxy_slots", 5) - job.add_metric("system", "system_name", "localhost") - - self.persist(u, job) - - task = model.Task(job=job, working_directory="/tmp", prepare_files_cmd="split.sh") - task.add_metric("gx", "galaxy_slots", 5) - task.add_metric("system", "system_name", "localhost") - - big_value = ":".join(f"{i}" for i in range(2000)) - task.add_metric("env", "BIG_PATH", big_value) - self.persist(task) - # Ensure big values truncated - assert len(task.text_metrics[1].metric_value) <= 1023 - def test_tasks(self): u = model.User(email="jobtest@foo.bar.baz", password="password") job = model.Job()