Coverage for tests / test_job.py: 18%
40 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-22 09:02 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-22 09:02 +0000
1# This file is part of ctrl_bps_parsl.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org) and the LSST DESC (https://www.lsstdesc.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/>.
28import os
30from lsst.ctrl.bps import BpsConfig, GenericWorkflowJob
31from lsst.ctrl.bps.parsl.job import ParslJob
33TESTDIR = os.path.abspath(os.path.dirname(__file__))
36def testInitWithTemplate():
37 """Test ParslJob stdout/stderr init. with template."""
38 # Test doesn't actually use directory
39 submit_path = os.path.join(TESTDIR, "with_template")
40 config = BpsConfig(
41 {
42 "subDirTemplate": "{label}/{tract}/{patch}/{band}/{visit}/{exposure}",
43 "submitPath": submit_path,
44 },
45 search_order=[],
46 )
47 gwjob = GenericWorkflowJob("job1", label="label1")
48 gwjob.tags = {"exposure": 903344}
50 parsl_job = ParslJob(gwjob, config, {})
51 assert parsl_job.stdout == os.path.join(submit_path, "logs/label1/903344/job1.stdout")
52 assert parsl_job.stderr == os.path.join(submit_path, "logs/label1/903344/job1.stderr")
55def testInitWithTemplateNoTags():
56 """Test ParslJob stdout/stderr init. with template but without tags."""
57 # Test doesn't actually use directory
58 submit_path = os.path.join(TESTDIR, "with_template_no_tags")
59 config = BpsConfig(
60 {
61 "subDirTemplate": "{label}/{tract}/{patch}/{band}/{visit}/{exposure}",
62 "submitPath": submit_path,
63 },
64 search_order=[],
65 )
66 gwjob = GenericWorkflowJob("job2", label="label2")
67 gwjob.tags = None
69 parsl_job = ParslJob(gwjob, config, {})
70 assert parsl_job.stdout == os.path.join(submit_path, "logs/label2/job2.stdout")
71 assert parsl_job.stderr == os.path.join(submit_path, "logs/label2/job2.stderr")
74def testInitWithoutTemplate():
75 """Test ParslJob stdout/stderr init. with template."""
76 # Test doesn't actually use directory
77 submit_path = os.path.join(TESTDIR, "without_template")
78 config = BpsConfig({"subDirTemplate": "", "submitPath": submit_path}, search_order=[])
79 gwjob = GenericWorkflowJob("job3", label="label3")
80 gwjob.tags = {"exposure": 903344}
82 parsl_job = ParslJob(gwjob, config, {})
83 assert parsl_job.stdout == os.path.join(submit_path, "logs/job3.stdout")
84 assert parsl_job.stderr == os.path.join(submit_path, "logs/job3.stderr")
87def testJobResourceLists():
88 """Test that ParslJob.get_resources() returns resource specifications
89 expected by Parsl Executors, including special handling needed for the
90 `priority` request.
91 """
92 # Test doesn't actually use directory
93 submit_path = os.path.join(TESTDIR, "without_template")
94 config = BpsConfig({"subDirTemplate": "", "submitPath": submit_path}, search_order=[])
95 gwjob = GenericWorkflowJob("job", label="label")
97 # If gwjob.priority is None, for Parsl's HighThroughputExecutor
98 # `"priority"` must be omitted, but WorkQueueExecutor requires
99 # `("cores", "disk", "memory")` to be provided.
100 gwjob.priority = None
101 parsl_job = ParslJob(gwjob, config, {})
102 assert "priority" not in parsl_job.get_resources()
103 for resource in ("cores", "disk", "memory"):
104 assert resource in parsl_job.get_resources()
106 # Check case where gwjob.priority is not None.
107 gwjob.priority = 1
108 for resource in ("cores", "disk", "memory", "priority"):
109 assert resource in parsl_job.get_resources()