Skip to content

Commit 48dfbe5

Browse files
authored
Merge pull request #253 from lsst/tickets/DM-50999
DM-50999: Replace getPackageDir with ResourcePath
2 parents 939e037 + 78d60e9 commit 48dfbe5

File tree

1 file changed

+45
-26
lines changed

1 file changed

+45
-26
lines changed

tests/test_pipelines.py

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2121

22-
import glob
2322
import itertools
24-
import os.path
2523
import tempfile
2624
import unittest
2725

@@ -34,12 +32,14 @@
3432
import lsst.utils
3533
import lsst.utils.tests
3634

35+
from lsst.resources import ResourcePath
36+
3737

3838
class PipelineDefintionsTestSuite(lsst.utils.tests.TestCase):
3939
"""Tests of the self-consistency of our pipeline definitions.
4040
"""
4141
def setUp(self):
42-
self.path = os.path.join(lsst.utils.getPackageDir("ap_pipe"), "pipelines")
42+
self.path = ResourcePath("eups://ap_pipe/pipelines/", forceDirectory=True)
4343
# Each pipeline file should have a subset that represents it in
4444
# higher-level pipelines.
4545
self.synonyms = {"ApPipe.yaml": "apPipe",
@@ -55,30 +55,37 @@ def test_graph_build(self):
5555
"""Test that each pipeline definition file can be
5656
used to build a graph.
5757
"""
58-
files = glob.glob(os.path.join(self.path, "**", "*.yaml"))
58+
files = ResourcePath.findFileResources([self.path], file_filter=r".*\.yaml$")
5959
for file in files:
60-
if "QuickTemplate" in file:
60+
if "QuickTemplate" in file.path:
6161
# Our QuickTemplate definition cannot be tested here because it
6262
# depends on drp_tasks, which we cannot make a dependency here.
6363
continue
64-
if "PromptTemplate" in file:
64+
if "PromptTemplate" in file.path:
6565
# Our PromptTemplate definition cannot be tested here because it
6666
# depends on drp_tasks, which we cannot make a dependency here.
6767
continue
68-
with self.subTest(file):
68+
with self.subTest(file=str(file)):
6969
pipeline = lsst.pipe.base.Pipeline.from_uri(file)
7070
pipeline.addConfigOverride("parameters", "apdb_config", "some/file/path.yaml")
7171
# If this fails, it will produce a useful error message.
7272
pipeline.to_graph()
7373

7474
def test_datasets(self):
75-
files = glob.glob(os.path.join(self.path, "_ingredients", "*.yaml"))
75+
files = [
76+
f for f in ResourcePath.findFileResources(
77+
[self.path.join("_ingredients", forceDirectory=True)], file_filter=r".*\.yaml$"
78+
)
79+
# Validation currently broken for injection pipelines.
80+
# TODO: DM-54077
81+
if "injection/" not in f.path
82+
]
7683
for file in files:
77-
if "QuickTemplate" in file:
84+
if "QuickTemplate" in file.path:
7885
# Our QuickTemplate definition cannot be tested here because it
7986
# depends on drp_tasks, which we cannot make a dependency here.
8087
continue
81-
with self.subTest(file):
88+
with self.subTest(file=str(file)):
8289
expected_inputs = {
8390
# ISR
8491
"raw", "camera", "crosstalk", "crosstalkSources", "bias", "dark", "flat", "ptc",
@@ -91,7 +98,7 @@ def test_datasets(self):
9198
"skyMap", "gaia_dr3_20230707", "gaia_dr2_20200414", "ps1_pv3_3pi_20170110",
9299
"template_coadd", "pretrainedModelPackage", "dia_source_apdb"
93100
}
94-
if "WithFakes" in file:
101+
if "WithFakes" in file.path:
95102
expected_inputs.add("injection_catalog")
96103
tester = PipelineStepTester(
97104
filename=file,
@@ -115,38 +122,48 @@ def test_whole_subset(self):
115122
"""Test that each pipeline's synonymous subset includes all tasks,
116123
including those imported from other files.
117124
"""
118-
files = glob.glob(os.path.join(self.path, "**", "*.yaml"))
125+
files = [
126+
f for f in ResourcePath.findFileResources([self.path], file_filter=r".*\.yaml$")
127+
# Validation currently broken for injection pipelines.
128+
# TODO: DM-54077
129+
if "injection/" not in f.path
130+
]
119131
for file in files:
120-
if "QuickTemplate" in file:
132+
if "QuickTemplate" in file.path:
121133
# Our QuickTemplate definition cannot be tested here because it
122134
# depends on drp_tasks, which we cannot make a dependency here.
123135
continue
124-
elif "ApdbDeduplication" in file:
136+
elif "ApdbDeduplication" in file.path:
125137
# The task to export catalogs from the APDB and re-run
126138
# association is not intended to be part of Prompt Processing
127139
# or batch AP pipeline runs.
128140
continue
129-
elif "PromptTemplate" in file:
141+
elif "PromptTemplate" in file.path:
130142
# Our PromptTemplate definition cannot be tested here because it
131143
# depends on drp_tasks, which we cannot make a dependency here.
132144
continue
133-
with self.subTest(file):
145+
with self.subTest(file=str(file)):
134146
pipeline = lsst.pipe.base.Pipeline.from_uri(file)
135-
subset = self.synonyms[os.path.basename(file)]
136-
self.assertEqual(pipeline.subsets[subset], set(pipeline.task_labels),
137-
msg=f"These tasks are missing from subset '{subset}'.")
147+
subset = self.synonyms.get(file.basename(), "<unknown_synonym>")
148+
self.assertEqual(pipeline.subsets.get(subset, "<missing>"), set(pipeline.task_labels),
149+
msg=f"These tasks are missing from subset '{subset}'")
138150

139151
def test_ap_pipe_subsets(self):
140152
"""Test the unique subsets of ApPipe.
141153
"""
142-
files = glob.glob(os.path.join(self.path, "**", "ApPipe*.yaml"))
154+
files = [
155+
f for f in ResourcePath.findFileResources([self.path], file_filter=r"^ApPipe.*\.yaml$")
156+
# Validation currently broken for injection pipelines.
157+
# TODO: DM-54077
158+
if "injection/" not in f.path
159+
]
143160
required_subsets = {"preload", "prompt", "afterburner"}
144161
# getRegionTimeFromVisit is part of no subset besides apPipe. This is a
145162
# very deliberate exception; see RFC-997.
146163
no_subset_wanted = {"getRegionTimeFromVisit"}
147164

148165
for file in files:
149-
with self.subTest(file):
166+
with self.subTest(file=str(file)):
150167
pipeline = lsst.pipe.base.Pipeline.from_uri(file)
151168
# Do all steps exist?
152169
self.assertGreaterEqual(pipeline.subsets.keys(), required_subsets,
@@ -171,12 +188,14 @@ def test_inherited_subsets(self):
171188
172189
Note that this does not check inheritance *within* `_ingredients`!
173190
"""
174-
files = [f for f in glob.glob(os.path.join(self.path, "**", "*.yaml"))
175-
if "_ingredients" not in f]
191+
files = [
192+
f for f in ResourcePath.findFileResources([self.path], file_filter=r".*\.yaml$")
193+
if "_ingredients" not in f.path
194+
]
176195
for file in files:
177-
with self.subTest(file):
178-
generic = os.path.join(self.path, "_ingredients", os.path.basename(file))
179-
if not os.path.exists(generic):
196+
with self.subTest(file=str(file)):
197+
generic = self.path.join("_ingredients/", forceDirectory=True).join(file.basename())
198+
if not generic.exists():
180199
continue
181200
special_subsets = lsst.pipe.base.Pipeline.from_uri(file).subsets.keys()
182201
generic_subsets = lsst.pipe.base.Pipeline.from_uri(generic).subsets.keys()

0 commit comments

Comments
 (0)