Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This file is part of ctrl_mpexec. 

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 program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22"""Simple unit test for cmdLineFwk module. 

23""" 

24 

25import click 

26from types import SimpleNamespace 

27import contextlib 

28import copy 

29from dataclasses import dataclass 

30import logging 

31import os 

32import pickle 

33import shutil 

34import tempfile 

35from typing import NamedTuple 

36import unittest 

37 

38from lsst.ctrl.mpexec.cmdLineFwk import CmdLineFwk 

39from lsst.ctrl.mpexec.cli.opt import run_options 

40from lsst.ctrl.mpexec.cli.utils import ( 

41 _ACTION_ADD_TASK, 

42 _ACTION_CONFIG, 

43 _ACTION_CONFIG_FILE, 

44 _ACTION_ADD_INSTRUMENT, 

45 PipetaskCommand, 

46) 

47from lsst.daf.butler import Config, Quantum, Registry 

48from lsst.daf.butler.registry import RegistryConfig 

49from lsst.obs.base import Instrument 

50import lsst.pex.config as pexConfig 

51from lsst.pipe.base import (Pipeline, PipelineTask, PipelineTaskConfig, 

52 QuantumGraph, TaskDef, TaskFactory, 

53 PipelineTaskConnections) 

54import lsst.pipe.base.connectionTypes as cT 

55import lsst.utils.tests 

56from lsst.pipe.base.tests.simpleQGraph import (AddTaskFactoryMock, makeSimpleQGraph) 

57from lsst.utils.tests import temporaryDirectory 

58 

59 

60logging.basicConfig(level=logging.INFO) 

61 

62# Have to monkey-patch Instrument.fromName() to not retrieve non-existing 

63# instrument from registry, these tests can run fine without actual instrument 

64# and implementing full mock for Instrument is too complicated. 

65Instrument.fromName = lambda name, reg: None 65 ↛ exitline 65 didn't run the lambda on line 65

66 

67 

68@contextlib.contextmanager 

69def makeTmpFile(contents=None, suffix=None): 

70 """Context manager for generating temporary file name. 

71 

72 Temporary file is deleted on exiting context. 

73 

74 Parameters 

75 ---------- 

76 contents : `bytes` 

77 Data to write into a file. 

78 """ 

79 fd, tmpname = tempfile.mkstemp(suffix=suffix) 

80 if contents: 

81 os.write(fd, contents) 

82 os.close(fd) 

83 yield tmpname 

84 with contextlib.suppress(OSError): 

85 os.remove(tmpname) 

86 

87 

88@contextlib.contextmanager 

89def makeSQLiteRegistry(create=True): 

90 """Context manager to create new empty registry database. 

91 

92 Yields 

93 ------ 

94 config : `RegistryConfig` 

95 Registry configuration for initialized registry database. 

96 """ 

97 with temporaryDirectory() as tmpdir: 

98 uri = f"sqlite:///{tmpdir}/gen3.sqlite" 

99 config = RegistryConfig() 

100 config["db"] = uri 

101 if create: 

102 Registry.createFromConfig(config) 

103 yield config 

104 

105 

106class SimpleConnections(PipelineTaskConnections, dimensions=(), 

107 defaultTemplates={"template": "simple"}): 

108 schema = cT.InitInput(doc="Schema", 

109 name="{template}schema", 

110 storageClass="SourceCatalog") 

111 

112 

113class SimpleConfig(PipelineTaskConfig, pipelineConnections=SimpleConnections): 

114 field = pexConfig.Field(dtype=str, doc="arbitrary string") 

115 

116 def setDefaults(self): 

117 PipelineTaskConfig.setDefaults(self) 

118 

119 

120class TaskOne(PipelineTask): 

121 ConfigClass = SimpleConfig 

122 _DefaultName = "taskOne" 

123 

124 

125class TaskTwo(PipelineTask): 

126 ConfigClass = SimpleConfig 

127 _DefaultName = "taskTwo" 

128 

129 

130class TaskFactoryMock(TaskFactory): 

131 def loadTaskClass(self, taskName): 

132 if taskName == "TaskOne": 

133 return TaskOne, "TaskOne" 

134 elif taskName == "TaskTwo": 

135 return TaskTwo, "TaskTwo" 

136 

137 def makeTask(self, taskClass, name, config, overrides, butler): 

138 if config is None: 

139 config = taskClass.ConfigClass() 

140 if overrides: 

141 overrides.applyTo(config) 

142 return taskClass(config=config, butler=butler, name=name) 

143 

144 

145def _makeArgs(registryConfig=None, **kwargs): 

146 """Return parsed command line arguments. 

147 

148 By default butler_config is set to `Config` populated with some defaults, 

149 it can be overridden completely by keyword argument. 

150 

151 Parameters 

152 ---------- 

153 cmd : `str`, optional 

154 Produce arguments for this pipetask command. 

155 registryConfig : `RegistryConfig`, optional 

156 Override for registry configuration. 

157 **kwargs 

158 Overrides for other arguments. 

159 """ 

160 # Use a mock to get the default value of arguments to 'run'. 

161 

162 mock = unittest.mock.Mock() 

163 

164 @click.command(cls=PipetaskCommand) 

165 @run_options() 

166 def fake_run(ctx, **kwargs): 

167 """Fake "pipetask run" command for gathering input arguments. 

168 

169 The arguments & options should always match the arguments & options in 

170 the "real" command function `lsst.ctrl.mpexec.cli.cmd.run`. 

171 """ 

172 mock(**kwargs) 

173 

174 runner = click.testing.CliRunner() 

175 result = runner.invoke(fake_run) 

176 if result.exit_code != 0: 

177 raise RuntimeError(f"Failure getting default args from 'fake_run': {result}") 

178 mock.assert_called_once() 

179 args = mock.call_args[1] 

180 args["enableLsstDebug"] = args.pop("debug") 

181 if "pipeline_actions" not in args: 

182 args["pipeline_actions"] = [] 

183 args = SimpleNamespace(**args) 

184 

185 # override butler_config with our defaults 

186 args.butler_config = Config() 

187 if registryConfig: 

188 args.butler_config["registry"] = registryConfig 

189 # The default datastore has a relocatable root, so we need to specify 

190 # some root here for it to use 

191 args.butler_config.configFile = "." 

192 # override arguments from keyword parameters 

193 for key, value in kwargs.items(): 

194 setattr(args, key, value) 

195 return args 

196 

197 

198class FakeTaskDef(NamedTuple): 

199 name: str 

200 

201 

202@dataclass(frozen=True) 

203class FakeDSRef: 

204 datasetType: str 

205 dataId: tuple 

206 

207 

208def _makeQGraph(): 

209 """Make a trivial QuantumGraph with one quantum. 

210 

211 The only thing that we need to do with this quantum graph is to pickle 

212 it, the quanta in this graph are not usable for anything else. 

213 

214 Returns 

215 ------- 

216 qgraph : `~lsst.pipe.base.QuantumGraph` 

217 """ 

218 

219 # The task name in TaskDef needs to be a real importable name, use one 

220 # that is sure to exist. 

221 taskDef = TaskDef(taskName="lsst.pipe.base.Struct", config=SimpleConfig()) 

222 quanta = [Quantum(taskName="lsst.pipe.base.Struct", 

223 inputs={FakeTaskDef("A"): FakeDSRef("A", (1, 2))})] # type: ignore 

224 qgraph = QuantumGraph({taskDef: set(quanta)}) 

225 return qgraph 

226 

227 

228class CmdLineFwkTestCase(unittest.TestCase): 

229 """A test case for CmdLineFwk 

230 """ 

231 

232 def testMakePipeline(self): 

233 """Tests for CmdLineFwk.makePipeline method 

234 """ 

235 fwk = CmdLineFwk() 

236 

237 # make empty pipeline 

238 args = _makeArgs() 

239 pipeline = fwk.makePipeline(args) 

240 self.assertIsInstance(pipeline, Pipeline) 

241 self.assertEqual(len(pipeline), 0) 

242 

243 # few tests with serialization 

244 with makeTmpFile() as tmpname: 

245 # make empty pipeline and store it in a file 

246 args = _makeArgs(save_pipeline=tmpname) 

247 pipeline = fwk.makePipeline(args) 

248 self.assertIsInstance(pipeline, Pipeline) 

249 

250 # read pipeline from a file 

251 args = _makeArgs(pipeline=tmpname) 

252 pipeline = fwk.makePipeline(args) 

253 self.assertIsInstance(pipeline, Pipeline) 

254 self.assertEqual(len(pipeline), 0) 

255 

256 # single task pipeline 

257 actions = [ 

258 _ACTION_ADD_TASK("TaskOne:task1") 

259 ] 

260 args = _makeArgs(pipeline_actions=actions) 

261 pipeline = fwk.makePipeline(args) 

262 self.assertIsInstance(pipeline, Pipeline) 

263 self.assertEqual(len(pipeline), 1) 

264 

265 # many task pipeline 

266 actions = [ 

267 _ACTION_ADD_TASK("TaskOne:task1a"), 

268 _ACTION_ADD_TASK("TaskTwo:task2"), 

269 _ACTION_ADD_TASK("TaskOne:task1b") 

270 ] 

271 args = _makeArgs(pipeline_actions=actions) 

272 pipeline = fwk.makePipeline(args) 

273 self.assertIsInstance(pipeline, Pipeline) 

274 self.assertEqual(len(pipeline), 3) 

275 

276 # single task pipeline with config overrides, cannot use TaskOne, need 

277 # something that can be imported with `doImport()` 

278 actions = [ 

279 _ACTION_ADD_TASK("lsst.pipe.base.tests.simpleQGraph.AddTask:task"), 

280 _ACTION_CONFIG("task:addend=100") 

281 ] 

282 args = _makeArgs(pipeline_actions=actions) 

283 pipeline = fwk.makePipeline(args) 

284 taskDefs = list(pipeline.toExpandedPipeline()) 

285 self.assertEqual(len(taskDefs), 1) 

286 self.assertEqual(taskDefs[0].config.addend, 100) 

287 

288 overrides = b"config.addend = 1000\n" 

289 with makeTmpFile(overrides) as tmpname: 

290 actions = [ 

291 _ACTION_ADD_TASK("lsst.pipe.base.tests.simpleQGraph.AddTask:task"), 

292 _ACTION_CONFIG_FILE("task:" + tmpname) 

293 ] 

294 args = _makeArgs(pipeline_actions=actions) 

295 pipeline = fwk.makePipeline(args) 

296 taskDefs = list(pipeline.toExpandedPipeline()) 

297 self.assertEqual(len(taskDefs), 1) 

298 self.assertEqual(taskDefs[0].config.addend, 1000) 

299 

300 # Check --instrument option, for now it only checks that it does not 

301 # crash. 

302 actions = [ 

303 _ACTION_ADD_TASK("lsst.pipe.base.tests.simpleQGraph.AddTask:task"), 

304 _ACTION_ADD_INSTRUMENT("Instrument") 

305 ] 

306 args = _makeArgs(pipeline_actions=actions) 

307 pipeline = fwk.makePipeline(args) 

308 

309 def testMakeGraphFromSave(self): 

310 """Tests for CmdLineFwk.makeGraph method. 

311 

312 Only most trivial case is tested that does not do actual graph 

313 building. 

314 """ 

315 fwk = CmdLineFwk() 

316 

317 with makeTmpFile(suffix=".qgraph") as tmpname, makeSQLiteRegistry() as registryConfig: 

318 

319 # make non-empty graph and store it in a file 

320 qgraph = _makeQGraph() 

321 with open(tmpname, "wb") as saveFile: 

322 qgraph.save(saveFile) 

323 args = _makeArgs(qgraph=tmpname, registryConfig=registryConfig, execution_butler_location=None) 

324 qgraph = fwk.makeGraph(None, args) 

325 self.assertIsInstance(qgraph, QuantumGraph) 

326 self.assertEqual(len(qgraph), 1) 

327 

328 # will fail if graph id does not match 

329 args = _makeArgs( 

330 qgraph=tmpname, 

331 qgraph_id="R2-D2 is that you?", 

332 registryConfig=registryConfig, 

333 execution_butler_location=None 

334 ) 

335 with self.assertRaisesRegex(ValueError, "graphID does not match"): 

336 fwk.makeGraph(None, args) 

337 

338 # save with wrong object type 

339 with open(tmpname, "wb") as saveFile: 

340 pickle.dump({}, saveFile) 

341 args = _makeArgs(qgraph=tmpname, registryConfig=registryConfig, execution_butler_location=None) 

342 with self.assertRaises(ValueError): 

343 fwk.makeGraph(None, args) 

344 

345 # reading empty graph from pickle should work but makeGraph() 

346 # will return None and make a warning 

347 qgraph = QuantumGraph(dict()) 

348 with open(tmpname, "wb") as saveFile: 

349 qgraph.save(saveFile) 

350 args = _makeArgs(qgraph=tmpname, registryConfig=registryConfig, execution_butler_location=None) 

351 with self.assertWarnsRegex(UserWarning, "QuantumGraph is empty"): 

352 # this also tests that warning is generated for empty graph 

353 qgraph = fwk.makeGraph(None, args) 

354 self.assertIs(qgraph, None) 

355 

356 def testShowPipeline(self): 

357 """Test for --show options for pipeline. 

358 """ 

359 fwk = CmdLineFwk() 

360 

361 actions = [ 

362 _ACTION_ADD_TASK("lsst.pipe.base.tests.simpleQGraph.AddTask:task"), 

363 _ACTION_CONFIG("task:addend=100") 

364 ] 

365 args = _makeArgs(pipeline_actions=actions) 

366 pipeline = fwk.makePipeline(args) 

367 

368 args.show = ["pipeline"] 

369 fwk.showInfo(args, pipeline) 

370 args.show = ["config"] 

371 fwk.showInfo(args, pipeline) 

372 args.show = ["history=task::addend"] 

373 fwk.showInfo(args, pipeline) 

374 args.show = ["tasks"] 

375 fwk.showInfo(args, pipeline) 

376 

377 

378class CmdLineFwkTestCaseWithButler(unittest.TestCase): 

379 """A test case for CmdLineFwk 

380 """ 

381 

382 def setUp(self): 

383 super().setUpClass() 

384 self.root = tempfile.mkdtemp() 

385 

386 def tearDown(self): 

387 shutil.rmtree(self.root, ignore_errors=True) 

388 super().tearDownClass() 

389 

390 def testSimpleQGraph(self): 

391 """Test successfull execution of trivial quantum graph. 

392 """ 

393 

394 nQuanta = 5 

395 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

396 

397 self.assertEqual(len(qgraph.taskGraph), 5) 

398 self.assertEqual(len(qgraph), nQuanta) 

399 

400 args = _makeArgs() 

401 fwk = CmdLineFwk() 

402 taskFactory = AddTaskFactoryMock() 

403 

404 # run whole thing 

405 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

406 self.assertEqual(taskFactory.countExec, nQuanta) 

407 

408 def testSimpleQGraphSkipExisting(self): 

409 """Test continuing execution of trivial quantum graph with 

410 ``--skip-existing``. 

411 """ 

412 

413 nQuanta = 5 

414 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

415 

416 self.assertEqual(len(qgraph.taskGraph), 5) 

417 self.assertEqual(len(qgraph), nQuanta) 

418 

419 args = _makeArgs() 

420 fwk = CmdLineFwk() 

421 taskFactory = AddTaskFactoryMock(stopAt=3) 

422 

423 # run first three quanta 

424 with self.assertRaises(RuntimeError): 

425 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

426 self.assertEqual(taskFactory.countExec, 3) 

427 

428 # run remaining ones 

429 taskFactory.stopAt = -1 

430 args.skip_existing = True 

431 args.extend_run = True 

432 args.no_versions = True 

433 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

434 self.assertEqual(taskFactory.countExec, nQuanta) 

435 

436 def testSimpleQGraphOutputsFail(self): 

437 """Test continuing execution of trivial quantum graph with partial 

438 outputs. 

439 """ 

440 

441 nQuanta = 5 

442 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

443 

444 # should have one task and number of quanta 

445 self.assertEqual(len(qgraph), nQuanta) 

446 

447 args = _makeArgs() 

448 fwk = CmdLineFwk() 

449 taskFactory = AddTaskFactoryMock(stopAt=3) 

450 

451 # run first three quanta 

452 with self.assertRaises(RuntimeError): 

453 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

454 self.assertEqual(taskFactory.countExec, 3) 

455 

456 # drop one of the two outputs from one task 

457 ref1 = butler.registry.findDataset("add2_dataset2", instrument="INSTR", detector=0) 

458 self.assertIsNotNone([ref1]) 

459 # also drop the metadata output 

460 ref2 = butler.registry.findDataset("task1_metadata", instrument="INSTR", detector=0) 

461 self.assertIsNotNone(ref2) 

462 butler.pruneDatasets([ref1, ref2], disassociate=True, unstore=True, purge=True) 

463 

464 taskFactory.stopAt = -1 

465 args.skip_existing = True 

466 args.extend_run = True 

467 args.no_versions = True 

468 excRe = "Registry inconsistency while checking for existing outputs.*" 

469 with self.assertRaisesRegex(RuntimeError, excRe): 

470 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

471 

472 def testSimpleQGraphClobberOutputs(self): 

473 """Test continuing execution of trivial quantum graph with 

474 --clobber-outputs. 

475 """ 

476 

477 nQuanta = 5 

478 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

479 

480 # should have one task and number of quanta 

481 self.assertEqual(len(qgraph), nQuanta) 

482 

483 args = _makeArgs() 

484 fwk = CmdLineFwk() 

485 taskFactory = AddTaskFactoryMock(stopAt=3) 

486 

487 # run first three quanta 

488 with self.assertRaises(RuntimeError): 

489 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

490 self.assertEqual(taskFactory.countExec, 3) 

491 

492 # drop one of the two outputs from one task 

493 ref1 = butler.registry.findDataset("add2_dataset2", instrument="INSTR", detector=0) 

494 self.assertIsNotNone(ref1) 

495 # also drop the metadata output 

496 ref2 = butler.registry.findDataset("task1_metadata", instrument="INSTR", detector=0) 

497 self.assertIsNotNone(ref2) 

498 butler.pruneDatasets([ref1, ref2], disassociate=True, unstore=True, purge=True) 

499 

500 taskFactory.stopAt = -1 

501 args.skip_existing = True 

502 args.extend_run = True 

503 args.clobber_outputs = True 

504 args.no_versions = True 

505 fwk.runPipeline(qgraph, taskFactory, args, butler=butler) 

506 # number of executed quanta is incremented 

507 self.assertEqual(taskFactory.countExec, nQuanta + 1) 

508 

509 def testSimpleQGraphReplaceRun(self): 

510 """Test repeated execution of trivial quantum graph with 

511 --replace-run. 

512 """ 

513 

514 # need non-memory registry in this case 

515 nQuanta = 5 

516 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root, inMemory=False) 

517 

518 # should have one task and number of quanta 

519 self.assertEqual(len(qgraph), nQuanta) 

520 

521 fwk = CmdLineFwk() 

522 taskFactory = AddTaskFactoryMock() 

523 

524 # run whole thing 

525 args = _makeArgs( 

526 butler_config=self.root, 

527 input="test", 

528 output="output", 

529 output_run="output/run1") 

530 # deep copy is needed because quanta are updated in place 

531 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

532 self.assertEqual(taskFactory.countExec, nQuanta) 

533 

534 # need to refresh collections explicitly (or make new butler/registry) 

535 butler.registry.refresh() 

536 collections = set(butler.registry.queryCollections(...)) 

537 self.assertEqual(collections, {"test", "output", "output/run1"}) 

538 

539 # number of datasets written by pipeline: 

540 # - nQuanta of init_outputs 

541 # - nQuanta of configs 

542 # - packages (single dataset) 

543 # - nQuanta * two output datasets 

544 # - nQuanta of metadata 

545 # - nQuanta of log output 

546 n_outputs = nQuanta * 6 + 1 

547 refs = butler.registry.queryDatasets(..., collections="output/run1") 

548 self.assertEqual(len(list(refs)), n_outputs) 

549 

550 # re-run with --replace-run (--inputs is ignored, as long as it hasn't 

551 # changed) 

552 args.replace_run = True 

553 args.output_run = "output/run2" 

554 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

555 

556 butler.registry.refresh() 

557 collections = set(butler.registry.queryCollections(...)) 

558 self.assertEqual(collections, {"test", "output", "output/run1", "output/run2"}) 

559 

560 # new output collection 

561 refs = butler.registry.queryDatasets(..., collections="output/run2") 

562 self.assertEqual(len(list(refs)), n_outputs) 

563 

564 # old output collection is still there 

565 refs = butler.registry.queryDatasets(..., collections="output/run1") 

566 self.assertEqual(len(list(refs)), n_outputs) 

567 

568 # re-run with --replace-run and --prune-replaced=unstore 

569 args.replace_run = True 

570 args.prune_replaced = "unstore" 

571 args.output_run = "output/run3" 

572 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

573 

574 butler.registry.refresh() 

575 collections = set(butler.registry.queryCollections(...)) 

576 self.assertEqual(collections, {"test", "output", "output/run1", "output/run2", "output/run3"}) 

577 

578 # new output collection 

579 refs = butler.registry.queryDatasets(..., collections="output/run3") 

580 self.assertEqual(len(list(refs)), n_outputs) 

581 

582 # old output collection is still there, and it has all datasets but 

583 # they are not in datastore 

584 refs = butler.registry.queryDatasets(..., collections="output/run2") 

585 refs = list(refs) 

586 self.assertEqual(len(refs), n_outputs) 

587 with self.assertRaises(FileNotFoundError): 

588 butler.get(refs[0], collections="output/run2") 

589 

590 # re-run with --replace-run and --prune-replaced=purge 

591 # This time also remove --input; passing the same inputs that we 

592 # started with and not passing inputs at all should be equivalent. 

593 args.input = None 

594 args.replace_run = True 

595 args.prune_replaced = "purge" 

596 args.output_run = "output/run4" 

597 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

598 

599 butler.registry.refresh() 

600 collections = set(butler.registry.queryCollections(...)) 

601 # output/run3 should disappear now 

602 self.assertEqual(collections, {"test", "output", "output/run1", "output/run2", "output/run4"}) 

603 

604 # new output collection 

605 refs = butler.registry.queryDatasets(..., collections="output/run4") 

606 self.assertEqual(len(list(refs)), n_outputs) 

607 

608 # Trying to run again with inputs that aren't exactly what we started 

609 # with is an error, and the kind that should not modify the data repo. 

610 with self.assertRaises(ValueError): 

611 args.input = ["test", "output/run2"] 

612 args.prune_replaced = None 

613 args.replace_run = True 

614 args.output_run = "output/run5" 

615 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

616 butler.registry.refresh() 

617 collections = set(butler.registry.queryCollections(...)) 

618 self.assertEqual(collections, {"test", "output", "output/run1", "output/run2", "output/run4"}) 

619 with self.assertRaises(ValueError): 

620 args.input = ["output/run2", "test"] 

621 args.prune_replaced = None 

622 args.replace_run = True 

623 args.output_run = "output/run6" 

624 fwk.runPipeline(copy.deepcopy(qgraph), taskFactory, args) 

625 butler.registry.refresh() 

626 collections = set(butler.registry.queryCollections(...)) 

627 self.assertEqual(collections, {"test", "output", "output/run1", "output/run2", "output/run4"}) 

628 

629 def testSubgraph(self): 

630 """Test successfull execution of trivial quantum graph. 

631 """ 

632 nQuanta = 5 

633 nNodes = 2 

634 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

635 

636 # Select first two nodes for execution. This depends on node ordering 

637 # which I assume is the same as execution order. 

638 nodeIds = [node.nodeId.number for node in qgraph] 

639 nodeIds = nodeIds[:nNodes] 

640 

641 self.assertEqual(len(qgraph.taskGraph), 5) 

642 self.assertEqual(len(qgraph), nQuanta) 

643 

644 with makeTmpFile(suffix=".qgraph") as tmpname, makeSQLiteRegistry() as registryConfig: 

645 with open(tmpname, "wb") as saveFile: 

646 qgraph.save(saveFile) 

647 

648 args = _makeArgs(qgraph=tmpname, qgraph_node_id=nodeIds, registryConfig=registryConfig, 

649 execution_butler_location=None) 

650 fwk = CmdLineFwk() 

651 

652 # load graph, should only read a subset 

653 qgraph = fwk.makeGraph(pipeline=None, args=args) 

654 self.assertEqual(len(qgraph), nNodes) 

655 

656 def testShowGraph(self): 

657 """Test for --show options for quantum graph. 

658 """ 

659 fwk = CmdLineFwk() 

660 

661 nQuanta = 2 

662 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

663 

664 args = _makeArgs(show=["graph"]) 

665 fwk.showInfo(args, pipeline=None, graph=qgraph) 

666 

667 def testShowGraphWorkflow(self): 

668 fwk = CmdLineFwk() 

669 

670 nQuanta = 2 

671 butler, qgraph = makeSimpleQGraph(nQuanta, root=self.root) 

672 

673 args = _makeArgs(show=["workflow"]) 

674 fwk.showInfo(args, pipeline=None, graph=qgraph) 

675 

676 # TODO: cannot test "uri" option presently, it instanciates 

677 # butler from command line options and there is no way to pass butler 

678 # mock to that code. 

679 

680 

681class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

682 pass 

683 

684 

685def setup_module(module): 

686 lsst.utils.tests.init() 

687 

688 

689if __name__ == "__main__": 689 ↛ 690line 689 didn't jump to line 690, because the condition on line 689 was never true

690 lsst.utils.tests.init() 

691 unittest.main()