Coverage for tests/dag_test_utils.py: 98%
43 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-26 02:14 -0700
« prev ^ index » next coverage.py v7.16.0, created at 2026-09-26 02:14 -0700
1# This file is part of ctrl_bps_htcondor.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28"""Utility functions for ctrl_bps_htcondor tests."""
30import logging
31from pathlib import Path
33from lsst.ctrl.bps.htcondor.lssthtc import HTC_VALID_JOB_KEYS, HTCDag, HTCJob, RestrictedDict
35_LOG = logging.getLogger(__name__)
38def make_lazy_dag(name: str, final: bool = True) -> tuple[HTCDag, list[str]]:
39 """Manually make a simple HTCDag with a lazy subdag for unit testing.
41 Parameters
42 ----------
43 name : `str`
44 Name to use for HTCDag.
45 final : `bool`, optional
46 Whether to include a FINAL job. Defaults to True.
48 Returns
49 -------
50 dag : `lsst.ctrl.bps.htcondor.lssthtc.HTCDag`
51 A simple HTCDag with a lazy subdag for testing.
52 filelist : `list` [`str`]
53 A list of files with relative paths that should be created
54 when DAG is written.
55 """
56 dag = HTCDag(name=name)
58 job_cmds = RestrictedDict(HTC_VALID_JOB_KEYS, {"executable": "/usr/bin/uptime"})
59 job_attrs = {"bps_run": "test_run"}
61 job = HTCJob("job1", "label1", job_cmds, initattrs=job_attrs)
62 subdir = Path(f"jobs/{job.label}")
63 job.subdir = subdir
64 job.subfile = f"{job.name}.sub"
65 job.add_dag_cmds({"dir": subdir})
66 dag.add_node("job1", data=job)
68 job = HTCJob("make_subdag", "label2", job_cmds, initattrs=job_attrs)
69 subdir = Path(f"jobs/{job.label}")
70 job.subdir = subdir
71 job.subfile = f"{job.name}.sub"
72 job.add_dag_cmds({"dir": subdir})
73 dag.add_node(job.name, data=job)
74 dag.add_edge("job1", job.name)
76 job = HTCJob("lazy_subdag", "lazy_label", job_cmds, initattrs=job_attrs)
77 job.subfile = "lazy_subdag.dag.condor.sub"
78 job.dag = HTCDag(name="lazy_subdag")
79 dag.add_node(job.name, data=job)
80 dag.add_edge("make_subdag", job.name)
82 job = HTCJob("job4", "label4", job_cmds, initattrs=job_attrs)
83 subdir = Path(f"jobs/{job.label}")
84 job.subdir = subdir
85 job.subfile = f"{job.name}.sub"
86 job.add_dag_cmds({"dir": subdir})
87 dag.add_node(job.name, data=job)
88 dag.add_edge("lazy_subdag", job.name)
90 filelist = [
91 f"{name}.dag",
92 "lazy_subdag.dag.condor.sub",
93 "jobs/label1/job1.sub",
94 "jobs/label2/make_subdag.sub",
95 "jobs/label4/job4.sub",
96 ]
98 if final: 98 ↛ 107line 98 didn't jump to line 107 because the condition on line 98 was always true
99 job = HTCJob("finalJob", "finalJob", job_cmds, initattrs=job_attrs)
100 subdir = Path(f"jobs/{job.label}")
101 job.subdir = subdir
102 job.subfile = f"{job.name}.sub"
103 job.add_dag_cmds({"dir": subdir})
104 dag.graph["final_job"] = job
105 filelist.append("jobs/finalJob/finalJob.sub")
107 return dag, filelist