isabl-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/test_app.py ADDED
@@ -0,0 +1,1254 @@
1
+ from os.path import isfile
2
+ from os.path import join
3
+ import uuid
4
+
5
+ from cached_property import cached_property
6
+ from click.testing import CliRunner
7
+ import pytest
8
+
9
+ from isabl_cli import AbstractApplication
10
+ from isabl_cli import api
11
+ from isabl_cli import exceptions
12
+ from isabl_cli import factories
13
+ from isabl_cli import options
14
+ from isabl_cli.settings import _DEFAULTS
15
+ from isabl_cli.settings import get_application_settings
16
+
17
+
18
+ class NonSequencingApplication(AbstractApplication):
19
+ NAME = str(uuid.uuid4())
20
+ VERSION = "STILL_TESTING"
21
+
22
+
23
+ class ExperimentsFromDefaulCLIApplication(AbstractApplication):
24
+ NAME = str(uuid.uuid4())
25
+ VERSION = "STILL_TESTING"
26
+ ASSEMBLY = "GRCh4000"
27
+ SPECIES = "HUMAN"
28
+
29
+ cli_options = [
30
+ options.TARGETS,
31
+ options.ANALYSES,
32
+ options.PAIR,
33
+ options.PAIRS,
34
+ options.PAIRS_FROM_FILE,
35
+ options.NULLABLE_REFERENCES,
36
+ ]
37
+
38
+ def validate_experiments(self, targets, references):
39
+ assert not any("raise validation error" in target.notes for target in targets)
40
+
41
+ def get_command(*_): # pylint: disable=no-method-argument
42
+ return ""
43
+
44
+
45
+ class BaseMockApplication(AbstractApplication):
46
+ NAME = str(uuid.uuid4())
47
+ VERSION = "STILL_TESTING"
48
+ ASSEMBLY = "GRCh4000"
49
+ SPECIES = "HUMAN"
50
+
51
+ cli_help = "This is a test application"
52
+ cli_options = [options.TARGETS]
53
+ application_url = "http://www.fake-test-app.org"
54
+ application_settings = {
55
+ "foo": "bar",
56
+ "test_reference": None,
57
+ "from_system_settings": None,
58
+ }
59
+ application_inputs = {"bar": None}
60
+
61
+ # this is commented out to test get_experiments_from_default_cli_options
62
+ # def get_experiments_from_cli_options(self, targets):
63
+ # return [([i], []) for i in targets]
64
+
65
+ def validate_experiments(self, targets, references):
66
+ self.validate_one_target_no_references(targets, references)
67
+
68
+ if targets[0]["identifier"] == "0":
69
+ raise AssertionError("Invalid Center ID")
70
+
71
+ return True
72
+
73
+ def get_dependencies(self, targets, references, settings):
74
+ return [], {"bar": "foo"}
75
+
76
+ def get_command(self, analysis, inputs, settings):
77
+ if settings.restart:
78
+ return "echo successfully restarted"
79
+
80
+ if analysis["targets"][0]["identifier"] == "1":
81
+ return "exit 1"
82
+
83
+ assert inputs["bar"] == "foo"
84
+
85
+ return f"echo {analysis['targets'][0]['system_id']}"
86
+
87
+ def merge_project_analyses(self, analysis, analyses):
88
+ with open(join(analysis["storage_url"], "test.merge"), "w") as f:
89
+ f.write(str(len(analyses)))
90
+
91
+ def merge_individual_analyses(self, analysis, analyses):
92
+ with open(join(analysis["storage_url"], "test.merge"), "w") as f:
93
+ f.write(str(len(analyses)))
94
+
95
+
96
+ class MockApplication(BaseMockApplication):
97
+
98
+ application_results = {
99
+ "analysis_result_key": {
100
+ "frontend_type": "number",
101
+ "description": "A random description",
102
+ "verbose_name": "The Test Result",
103
+ }
104
+ }
105
+ application_project_level_results = {
106
+ "project_result_file": {
107
+ "frontend_type": "text-file",
108
+ "description": "A random description",
109
+ "verbose_name": "The Test Result",
110
+ }
111
+ }
112
+
113
+ application_individual_level_results = {
114
+ "individual_result_file": {
115
+ "frontend_type": "text-file",
116
+ "description": "A random description",
117
+ "verbose_name": "The Test Result",
118
+ }
119
+ }
120
+
121
+ def get_analysis_results(self, analysis):
122
+ return {"analysis_result_key": 1}
123
+
124
+ def get_project_analysis_results(self, analysis):
125
+ # please note that ipdb wont work here as this function will
126
+ # be submitted by a subprocess call
127
+ return {"project_result_file": join(analysis["storage_url"], "test.merge")}
128
+
129
+ def get_individual_analysis_results(self, analysis):
130
+ # please note that ipdb wont work here as this function will
131
+ # be submitted by a subprocess call
132
+ return {"individual_result_file": join(analysis["storage_url"], "test.merge")}
133
+
134
+
135
+ class MockApplicationWithPatternResults(BaseMockApplication):
136
+
137
+ """Application with results found using the 'pattern' field."""
138
+
139
+ NAME = "TESTING RESULT PATTERN MATCHING"
140
+
141
+ application_results = {
142
+ "analysis_result_file": {
143
+ "frontend_type": "number",
144
+ "description": "A random description",
145
+ "verbose_name": "The Test Result",
146
+ "pattern": "test.pattern",
147
+ }
148
+ }
149
+
150
+ application_project_level_results = {
151
+ "project_result_file": {
152
+ "frontend_type": "text-file",
153
+ "description": "A random description",
154
+ "verbose_name": "The Test Result",
155
+ "pattern": "test.project.merge",
156
+ }
157
+ }
158
+
159
+ application_individual_level_results = {
160
+ "individual_result_file": {
161
+ "frontend_type": "text-file",
162
+ "description": "A random description",
163
+ "verbose_name": "The Test Result",
164
+ "pattern": "test.*.merge",
165
+ "exclude": "test.exclude.merge",
166
+ }
167
+ }
168
+
169
+ def get_command(self, analysis, inputs, settings):
170
+ nested_dir = join(analysis["storage_url"], "nested")
171
+ pattern_file = join(nested_dir, "test.pattern")
172
+ return f"mkdir -p {nested_dir} && echo 'Test' > {pattern_file}"
173
+
174
+ def merge_project_analyses(self, analysis, analyses):
175
+ with open(join(analysis["storage_url"], "test.project.merge"), "w") as f:
176
+ f.write(str(len(analyses)))
177
+
178
+ def merge_individual_analyses(self, analysis, analyses):
179
+ for i in ["test.individual.merge", "test.exclude.merge"]:
180
+ with open(join(analysis["storage_url"], i), "w") as f:
181
+ f.write(str(len(analyses)))
182
+
183
+
184
+ class UniquePerIndividualApplication(AbstractApplication):
185
+ NAME = "UNIQUE_PER_INDIVIDUAL"
186
+ VERSION = "STILL_TESTING"
187
+ ASSEMBLY = "GRCh4000"
188
+ SPECIES = "HUMAN"
189
+
190
+ cli_options = [options.TARGETS]
191
+ unique_analysis_per_individual = True
192
+ application_results = {
193
+ "analysis_result_key": {
194
+ "frontend_type": "string",
195
+ "description": "A random description",
196
+ "verbose_name": "The Test Result",
197
+ }
198
+ }
199
+
200
+ def validate_experiments(self, targets, references):
201
+ return True
202
+
203
+ def get_experiments_from_cli_options(self, targets):
204
+ return [([i], []) for i in targets]
205
+
206
+ def get_command(self, analysis, inputs, settings):
207
+ return f"echo {analysis.individual_level_analysis.system_id}"
208
+
209
+ def get_analysis_results(self, analysis):
210
+ return {"analysis_result_key": analysis.individual_level_analysis.system_id}
211
+
212
+
213
+ class UniquePerIndividualProtectResultsFalse(UniquePerIndividualApplication):
214
+ NAME = "UNIQUE_PER_INDIVIDUAL_NO_PROTECT"
215
+ application_protect_results = False
216
+
217
+
218
+ def submit_merge(instance, application, command):
219
+ assert "merge-individual-analyses" in command
220
+ assert isinstance(application, MockApplication)
221
+ assert instance.pk == 1
222
+ raise ValueError("stop testing here")
223
+
224
+
225
+ def test_custom_submit_merge():
226
+ _DEFAULTS["SUBMIT_MERGE_ANALYSIS"] = "tests.test_app.submit_merge"
227
+
228
+ with pytest.raises(ValueError) as error:
229
+ MockApplication().submit_merge_analysis(api.IsablDict(pk=1, species="HUMAN"))
230
+
231
+ assert "stop testing here" in str(error)
232
+ _DEFAULTS["SUBMIT_MERGE_ANALYSIS"] = None
233
+
234
+
235
+ def test_assembly_is_not_required():
236
+ app = NonSequencingApplication()
237
+ assert str(app) == f"{app.NAME} {app.VERSION}"
238
+ assert app.primary_key == NonSequencingApplication().primary_key
239
+
240
+
241
+ def test_get_application_settings():
242
+ # test can use reference data id
243
+ assert (
244
+ "genome fasta path"
245
+ == get_application_settings(
246
+ defaults=dict(inner_dict=dict(reference="reference_data_id:genome_fasta")),
247
+ settings=dict(),
248
+ reference_data=dict(genome_fasta=dict(url="genome fasta path")),
249
+ import_strings={},
250
+ ).inner_dict.reference
251
+ )
252
+
253
+ # test can use import strings
254
+ assert (
255
+ join
256
+ == get_application_settings(
257
+ defaults=dict(inner_dict=dict(os_methods=[])),
258
+ settings=dict(inner_dict=dict(os_methods=["os.path.join", "os.listdir"])),
259
+ reference_data=dict(),
260
+ import_strings={"os_methods"},
261
+ ).inner_dict.os_methods[0]
262
+ )
263
+
264
+ # test inner keys are validated (unexpected settings)
265
+ with pytest.raises(exceptions.ConfigurationError) as error:
266
+ get_application_settings(
267
+ defaults=dict(inner_dict=dict(correct_name=[])),
268
+ settings=dict(inner_dict=dict(wrong_name=[])),
269
+ reference_data=dict(),
270
+ import_strings=set(),
271
+ )
272
+
273
+ assert "Got unexpected setting 'wrong_name' for 'inner_dict'" in str(error.value)
274
+
275
+ # test can skip keys validation
276
+ assert (
277
+ get_application_settings(
278
+ defaults=dict(inner_dict=dict(correct_name=[], skip_check=True)),
279
+ settings=dict(inner_dict=dict(different_name_but_ok=None)),
280
+ reference_data=dict(),
281
+ import_strings=set(),
282
+ ).inner_dict.different_name_but_ok
283
+ is None
284
+ )
285
+
286
+ # test keys are not checked for list of dicts
287
+ assert (
288
+ get_application_settings(
289
+ defaults=dict(dicts_list=[dict(any_setting_name_works=True)]),
290
+ settings=dict(dicts_list=[dict(thats_right=True)]),
291
+ reference_data=dict(),
292
+ import_strings=set(),
293
+ )
294
+ .dicts_list[0]
295
+ .thats_right
296
+ is True
297
+ )
298
+
299
+ # test not implemented settings
300
+ with pytest.raises(exceptions.ConfigurationError) as error:
301
+ get_application_settings(
302
+ defaults=dict(
303
+ inner=dict(required_setting=NotImplemented),
304
+ reference="reference_data_id:foo",
305
+ ),
306
+ settings=dict(inner=dict(required=None)),
307
+ reference_data=dict(),
308
+ import_strings=set(),
309
+ )
310
+
311
+ assert "Missing required setting: 'required_setting'" in str(error.value)
312
+ assert "Missing required setting: 'reference'" in str(error.value)
313
+
314
+ # expected dict, got other
315
+ with pytest.raises(exceptions.ConfigurationError) as error:
316
+ get_application_settings(
317
+ defaults=dict(dict_setting=dict(foo="bar")),
318
+ settings=dict(dict_setting="not a dict"),
319
+ reference_data=dict(),
320
+ import_strings=set(),
321
+ )
322
+
323
+ assert "Invalid setting expected dict, got: " in str(error.value)
324
+
325
+
326
+ def test_application_settings(tmpdir):
327
+ application = MockApplication()
328
+
329
+ # test __repr__
330
+ assert (
331
+ str(application)
332
+ == f"{application.NAME} {application.VERSION} ({application.ASSEMBLY})"
333
+ )
334
+
335
+ # test get settings from reference data id
336
+ application.application_settings["test_reference"] = "reference_data_id:test_id"
337
+ application.assembly["reference_data"]["test_id"] = dict(url="FOO")
338
+ assert application.settings.test_reference == "FOO"
339
+ assert application.settings.from_system_settings is None
340
+ application.application_settings["test_reference"] = None
341
+
342
+ # assert can patch databased settings
343
+ application.patch_application_settings(from_system_settings="set")
344
+ assert application.settings.from_system_settings == "set"
345
+
346
+ # run it again just to get coverage when evaluating that no API update is needed
347
+ application.patch_application_settings(from_system_settings="set")
348
+
349
+ # test bad settings
350
+ application = MockApplication()
351
+ application.application.settings = {} # avoid default errors
352
+ application.application_settings = {
353
+ "test_reference": "reference_data_id:invalid_key",
354
+ "needs_to_be_implemented": NotImplemented,
355
+ }
356
+ with pytest.raises(exceptions.ConfigurationError) as error:
357
+ application.settings
358
+
359
+ assert "Missing required setting: 'test_reference'" in str(error.value)
360
+ assert "Missing required setting: 'needs_to_be_implemented'" in str(error.value)
361
+
362
+
363
+ def test_unique_analysis_per_individual_app(tmpdir):
364
+ individual = factories.IndividualFactory(species="HUMAN")
365
+ sample = factories.SampleFactory(individual=individual)
366
+ project = api.create_instance("projects", **factories.ProjectFactory())
367
+ experiments = [
368
+ factories.ExperimentFactory(
369
+ identifier=str(i), sample=sample, projects=[project]
370
+ )
371
+ for i in range(4)
372
+ ]
373
+
374
+ experiments = [api.create_instance("experiments", **i) for i in experiments]
375
+ tuples = [(experiments, [])]
376
+ application = UniquePerIndividualApplication()
377
+ ran_analyses, _, __ = application.run(tuples, commit=True)
378
+
379
+ assert len(ran_analyses) == 1
380
+ assert "analysis_result_key" in ran_analyses[0][0]["results"]
381
+ assert len(ran_analyses[0][0].targets) == 4
382
+ assert (
383
+ ran_analyses[0][0]["results"].analysis_result_key
384
+ == experiments[0].sample.individual.system_id
385
+ )
386
+
387
+ application = UniquePerIndividualProtectResultsFalse()
388
+ ran_analyses, _, __ = application.run(tuples, commit=True)
389
+ assert len(ran_analyses) == 1
390
+ assert "analysis_result_key" in ran_analyses[0][0]["results"]
391
+ assert len(ran_analyses[0][0].targets) == 4
392
+
393
+ # test application_protect_results false
394
+ tuples = [(experiments[:2], [])]
395
+ application = UniquePerIndividualProtectResultsFalse()
396
+ ran_analyses, _, __ = application.run(tuples, commit=True)
397
+
398
+ assert len(ran_analyses) == 1
399
+ assert "analysis_result_key" in ran_analyses[0][0]["results"]
400
+ assert len(ran_analyses[0][0].targets) == 2
401
+
402
+ # test application_protect_results reduce add more samples - dont remove this test
403
+ tuples = [(experiments, [])]
404
+ application = UniquePerIndividualProtectResultsFalse()
405
+ ran_analyses, _, __ = application.run(tuples, commit=True)
406
+
407
+ assert len(ran_analyses) == 1
408
+ assert "analysis_result_key" in ran_analyses[0][0]["results"]
409
+ assert len(ran_analyses[0][0].targets) == 4
410
+
411
+ runner = CliRunner()
412
+ command = UniquePerIndividualApplication.as_cli_command()
413
+ result = runner.invoke(
414
+ command, ["-fi", "system_id", experiments[0].system_id], catch_exceptions=False
415
+ )
416
+ assert experiments[0].system_id in result.output
417
+
418
+
419
+ def test_engine(tmpdir):
420
+ _DEFAULTS["DEFAULT_LINUX_GROUP"] = "not_a_group"
421
+
422
+ individual = factories.IndividualFactory(species="HUMAN")
423
+ sample = factories.SampleFactory(individual=individual)
424
+ project = api.create_instance("projects", **factories.ProjectFactory())
425
+
426
+ experiments = [
427
+ factories.ExperimentFactory(
428
+ identifier=str(i), sample=sample, projects=[project]
429
+ )
430
+ for i in range(4)
431
+ ]
432
+
433
+ experiments = [api.create_instance("experiments", **i) for i in experiments]
434
+ tuples = [([i], []) for i in experiments]
435
+
436
+ command = MockApplication.as_cli_command()
437
+ application = MockApplication()
438
+ ran_analyses, _, __ = application.run(tuples, commit=True)
439
+ target = api.Experiment(ran_analyses[1][0].targets[0].pk)
440
+
441
+ assert "analysis_result_key" in ran_analyses[1][0]["results"].keys()
442
+ assert "analysis_result_key" in ran_analyses[2][0]["results"].keys()
443
+ assert f'analysis: {ran_analyses[1][0]["pk"]}' in application.get_job_name(
444
+ ran_analyses[1][0]
445
+ )
446
+
447
+ bam = join(tmpdir, "fake.bam")
448
+ application.update_experiment_bam_file(experiments[0], bam, ran_analyses[0][0].pk)
449
+ assert bam in application.get_bams([experiments[0]])
450
+
451
+ # get coverage for when there is no need to update the bam again
452
+ assert application.update_experiment_bam_file(
453
+ experiments[0], bam, ran_analyses[0][0].pk
454
+ )
455
+
456
+ with pytest.raises(exceptions.ValidationError) as error:
457
+ application.validate_bams(experiments)
458
+
459
+ assert (
460
+ f"{experiments[1].system_id} has no registered bam for "
461
+ f"{application.assembly.name}" in str(error.value)
462
+ )
463
+
464
+ with pytest.raises(exceptions.ValidationError) as error:
465
+ application.validate_bedfiles(experiments)
466
+
467
+ assert f"{experiments[0].system_id} has no registered bedfile" in str(error.value)
468
+
469
+ # test that get results work as expected
470
+ assert application.get_results(
471
+ result_key="analysis_result_key",
472
+ experiment=target,
473
+ application_key=application.primary_key,
474
+ ) == [(1, ran_analyses[1][0].pk)]
475
+
476
+ # check assertion error is raised when an invalid result is searched for
477
+ with pytest.raises(AssertionError) as error:
478
+ application.get_results(
479
+ result_key="invalid_result_key",
480
+ experiment=target,
481
+ application_key=application.primary_key,
482
+ )
483
+
484
+ assert "Result 'invalid_result_key' not found for analysis" in str(error.value)
485
+
486
+ # test options
487
+ runner = CliRunner()
488
+ result = runner.invoke(command, ["--help"], catch_exceptions=False)
489
+ assert "This is a test application" in result.output
490
+ assert "--commit" in result.output
491
+ assert "--force" in result.output
492
+ assert "--quiet" in result.output
493
+ assert "--restart" in result.output
494
+ assert "--url" in result.output
495
+
496
+ runner = CliRunner()
497
+ result = runner.invoke(command, ["--url"], catch_exceptions=False)
498
+ assert "http://www.fake-test-app.org" in result.output
499
+
500
+ # test get experiments from default cli options
501
+ runner = CliRunner()
502
+ result = runner.invoke(
503
+ command, ["-fi", "system_id", experiments[0].system_id], catch_exceptions=False
504
+ )
505
+ assert experiments[0].system_id in result.output
506
+
507
+ # check project level results
508
+ pks = ",".join(str(i["pk"]) for i in experiments)
509
+ args = ["-fi", "pk__in", pks]
510
+ result = runner.invoke(command, args, catch_exceptions=False)
511
+ analysis = application.get_project_level_auto_merge_analysis(project)
512
+ merged = join(analysis["storage_url"], "test.merge")
513
+
514
+ assert analysis["status"] == "SUCCEEDED", f"Project Analysis failed {analysis}"
515
+ assert "FAILED" in result.output
516
+ assert "SUCCEEDED" in result.output
517
+ assert "SKIPPED 3" in result.output
518
+ assert "INVALID 1" in result.output
519
+ assert isfile(merged)
520
+ assert "project_result_file" in analysis["results"]
521
+
522
+ with open(merged) as f:
523
+ assert f.read().strip() == "2"
524
+
525
+ # check individual level results
526
+ analysis = application.get_individual_level_auto_merge_analysis(individual)
527
+ merged = join(analysis["storage_url"], "test.merge")
528
+ assert analysis["status"] == "SUCCEEDED", f"Individual Analysis failed {analysis}"
529
+ assert isfile(merged)
530
+ assert "individual_result_file" in analysis["results"]
531
+
532
+ with open(merged) as f:
533
+ assert f.read().strip() == "2"
534
+
535
+ # check passing command line args
536
+ args = ["-fi", "pk__in", pks, "--commit", "--force"]
537
+ result = runner.invoke(command, args)
538
+ assert "--commit not required when using --force" in result.output
539
+
540
+ args = ["-fi", "pk__in", pks, "--restart", "--force"]
541
+ result = runner.invoke(command, args)
542
+ assert "cant use --force and --restart together" in result.output
543
+
544
+ args = ["-fi", "pk__in", pks, "--force"]
545
+ result = runner.invoke(command, args)
546
+ assert "trashing:" in result.output
547
+
548
+ args = ["-fi", "pk__in", pks, "--restart", "--quiet"]
549
+ result = runner.invoke(command, args)
550
+ assert "FAILED" not in result.output
551
+
552
+ with open(join(ran_analyses[0][0].storage_url, "head_job.log")) as f:
553
+ assert "successfully restarted" in f.read()
554
+
555
+ MockApplication.cli_allow_force = False
556
+ MockApplication.cli_allow_restart = False
557
+ result = runner.invoke(
558
+ MockApplication.as_cli_command(), ["--help"], catch_exceptions=False
559
+ )
560
+ assert "--force" not in result.output
561
+ assert "--restart" not in result.output
562
+
563
+ # Test results are available, which should be matched by patterns
564
+ application = MockApplicationWithPatternResults()
565
+ ran_analyses, _, __ = application.run(tuples, commit=True)
566
+
567
+ for output in ran_analyses:
568
+ analysis, *_ = output
569
+ if analysis["status"] == "SUCCEEDED":
570
+ expected_file = join(analysis["storage_url"], "nested", "test.pattern")
571
+ assert "analysis_result_file" in analysis["results"]
572
+ assert analysis["results"]["analysis_result_file"] == expected_file
573
+
574
+ analysis = application.get_project_level_auto_merge_analysis(project)
575
+ merged = join(analysis["storage_url"], "test.project.merge")
576
+ assert "project_result_file" in analysis["results"]
577
+ assert analysis["results"]["project_result_file"] == merged
578
+
579
+ analysis = application.get_individual_level_auto_merge_analysis(individual)
580
+ merged = join(analysis["storage_url"], "test.individual.merge")
581
+ assert "individual_result_file" in analysis["results"]
582
+ assert analysis["results"]["individual_result_file"] == merged
583
+
584
+
585
+ def test_validate_is_pair():
586
+ application = AbstractApplication()
587
+ application.validate_is_pair([{"pk": 1}], [{"pk": 2}])
588
+
589
+ with pytest.raises(AssertionError) as error:
590
+ application.validate_is_pair([{"pk": 1}, {"pk": 2}], [{"pk": 3}])
591
+
592
+ assert "Pairs only." in str(error.value)
593
+
594
+ with pytest.raises(AssertionError) as error:
595
+ application.validate_is_pair([{"pk": 1}], [{"pk": 1}])
596
+
597
+ assert "Target can't be same as reference." in str(error.value)
598
+
599
+
600
+ def test_validate_reference_genome(tmpdir):
601
+ reference = tmpdir.join("reference.fasta")
602
+ required = ".fai", ".amb", ".ann", ".bwt", ".pac", ".sa"
603
+ application = AbstractApplication()
604
+
605
+ with pytest.raises(AssertionError) as error:
606
+ application.validate_reference_genome(reference.strpath)
607
+
608
+ assert "Missing indexes please run" in str(error.value)
609
+
610
+ for i in required:
611
+ tmp = tmpdir.join("reference.fasta" + i)
612
+ tmp.write("foo")
613
+
614
+ with pytest.raises(AssertionError) as error:
615
+ application.validate_reference_genome(reference.strpath)
616
+
617
+ assert "samtools dict -a" in str(error.value)
618
+
619
+
620
+ def test_validate_fastq_only():
621
+ application = AbstractApplication()
622
+ targets = [{"raw_data": [], "system_id": "FOO"}]
623
+
624
+ with pytest.raises(AssertionError) as error:
625
+ application.validate_has_raw_data(targets)
626
+
627
+ assert "FOO" in str(error.value)
628
+
629
+ targets = [
630
+ {"raw_data": [{"file_type": "BAM"}], "system_id": "FOO"},
631
+ {"raw_data": [{"file_type": "FASTQ_R1"}], "system_id": "BAR"},
632
+ ]
633
+
634
+ with pytest.raises(AssertionError) as error:
635
+ application.validate_single_data_type(targets)
636
+
637
+ assert "FOO" in str(error.value)
638
+
639
+ targets = [{"raw_data": [{"file_type": "BAM"}], "system_id": "FOO"}]
640
+
641
+ with pytest.raises(AssertionError) as error:
642
+ application.validate_fastq_only(targets)
643
+
644
+ assert "Only FASTQ supported" in str(error.value)
645
+
646
+
647
+ def test_validate_methods():
648
+ application = AbstractApplication()
649
+ targets = [{"technique": {"method": "FOO"}, "system_id": "FOO BAR"}]
650
+
651
+ with pytest.raises(AssertionError) as error:
652
+ application.validate_methods(targets, "BAR")
653
+
654
+ assert "Only 'BAR' method(s) allowed" in str(error.value)
655
+
656
+
657
+ def test_validate_pdx_only():
658
+ application = AbstractApplication()
659
+ targets = [{"custom_fields": {"is_pdx": False}, "system_id": "FOO"}]
660
+
661
+ with pytest.raises(AssertionError) as error:
662
+ application.validate_pdx_only(targets)
663
+
664
+ assert "is not PDX" in str(error.value)
665
+
666
+
667
+ def test_validate_are_normals():
668
+ application = AbstractApplication()
669
+ targets = [
670
+ api.isablfy(
671
+ {"sample": {"category": "TUMOR", "system_id": "FOO"}, "system_id": "FOO"}
672
+ )
673
+ ]
674
+
675
+ with pytest.raises(AssertionError) as error:
676
+ application.validate_are_normals(targets)
677
+
678
+ assert "is not NORMAL" in str(error.value)
679
+
680
+
681
+ def test_validate_dna_rna_only():
682
+ application = AbstractApplication()
683
+ targets = [{"technique": {"category": "DNA"}, "system_id": "FOO"}]
684
+
685
+ with pytest.raises(AssertionError) as error:
686
+ application.validate_rna_only(targets)
687
+
688
+ assert "is not RNA" in str(error.value)
689
+
690
+ targets = [{"technique": {"category": "RNA"}, "system_id": "FOO"}]
691
+
692
+ with pytest.raises(AssertionError) as error:
693
+ application.validate_dna_only(targets)
694
+
695
+ assert "is not DNA" in str(error.value)
696
+
697
+
698
+ def test_validate_species():
699
+ application = MockApplication()
700
+ targets = [{"sample": {"individual": {"species": "MOUSE"}}, "system_id": "FOO"}]
701
+
702
+ with pytest.raises(AssertionError) as error:
703
+ application.validate_species(targets)
704
+
705
+ assert "species not supported" in str(error.value)
706
+
707
+
708
+ def test_validate_one_target_no_references():
709
+ application = AbstractApplication()
710
+ targets = [{}]
711
+ references = []
712
+ application.validate_one_target_no_references(targets, references)
713
+
714
+ with pytest.raises(AssertionError) as error:
715
+ references.append({})
716
+ application.validate_one_target_no_references(targets, references)
717
+
718
+ assert "No reference experiments" in str(error.value)
719
+
720
+
721
+ def test_validate_atleast_onetarget_onereference():
722
+ application = AbstractApplication()
723
+ targets = [{}]
724
+ references = [{}]
725
+ application.validate_at_least_one_target_one_reference(targets, references)
726
+
727
+ with pytest.raises(AssertionError) as error:
728
+ targets = []
729
+ application.validate_at_least_one_target_one_reference(targets, references)
730
+
731
+ assert "References and targets required" in str(error.value)
732
+
733
+
734
+ def test_validate_targets_not_in_references():
735
+ application = AbstractApplication()
736
+ targets = [{"pk": 1, "system_id": 1}]
737
+ references = [{"pk": 2, "system_id": 2}]
738
+ application.validate_targets_not_in_references(targets, references)
739
+
740
+ with pytest.raises(AssertionError) as error:
741
+ references = targets
742
+ application.validate_targets_not_in_references(targets, references)
743
+
744
+ assert "1 was also used as reference" in str(error.value)
745
+
746
+
747
+ def test_validate_dna_tuples():
748
+ application = AbstractApplication()
749
+ targets = [{"system_id": 1, "technique": {"category": "DNA"}}]
750
+ references = [{"system_id": 2, "technique": {"category": "DNA"}}]
751
+ application.validate_dna_only(targets + references)
752
+
753
+ with pytest.raises(AssertionError) as error:
754
+ targets[0]["technique"]["category"] = "RNA"
755
+ application.validate_dna_only(targets + references)
756
+
757
+ assert "category is not DNA" in str(error.value)
758
+
759
+
760
+ def test_validate_dna_pairs():
761
+ application = AbstractApplication()
762
+ targets = [{"pk": 1, "technique": {"category": "DNA"}}]
763
+ references = [{"pk": 2, "technique": {"category": "DNA"}}]
764
+ application.validate_dna_pairs(targets, references)
765
+
766
+
767
+ def test_validate_same_technique():
768
+ application = AbstractApplication()
769
+ targets = [{"system_id": 1, "technique": {"slug": "1"}}]
770
+ references = [{"system_id": 2, "technique": {"slug": "1"}}]
771
+ application.validate_same_technique(targets, references)
772
+
773
+ with pytest.raises(AssertionError) as error:
774
+ targets = [{"system_id": 1, "technique": {"slug": "2"}}]
775
+ application.validate_same_technique(targets, references)
776
+
777
+ assert "Same techniques required" in str(error.value)
778
+
779
+ with pytest.raises(AssertionError) as error:
780
+ references.append({"system_id": 3, "technique": {"slug": "2"}})
781
+ application.validate_same_technique(targets, references)
782
+
783
+ assert "Expected one technique, got:" in str(error.value)
784
+
785
+
786
+ def test_validate_same_platform():
787
+ application = AbstractApplication()
788
+ targets = [{"system_id": 1, "platform": {"slug": "1"}}]
789
+ references = [{"system_id": 2, "platform": {"slug": "1"}}]
790
+ application.validate_same_platform(targets, references)
791
+
792
+ with pytest.raises(AssertionError) as error:
793
+ targets = [{"system_id": 1, "platform": {"slug": "2"}}]
794
+ application.validate_same_platform(targets, references)
795
+
796
+ assert "Same platforms required" in str(error.value)
797
+
798
+ with pytest.raises(AssertionError) as error:
799
+ references.append({"system_id": 3, "platform": {"slug": "2"}})
800
+ application.validate_same_platform(targets, references)
801
+
802
+ assert "Expected one platform, got:" in str(error.value)
803
+
804
+
805
+ def test_validate_source():
806
+ application = AbstractApplication()
807
+ targets = [{"sample": {"system_id": "FOO", "source": "BLOOD"}}]
808
+ application.validate_source(targets, "BLOOD")
809
+
810
+ with pytest.raises(AssertionError) as error:
811
+ application.validate_source(targets, "BONE MARROW")
812
+
813
+ assert "Sample source for FOO does not match BONE MARROW." in str(error.value)
814
+
815
+
816
+ def test_get_experiments_from_default_cli_options(tmpdir):
817
+ app = ExperimentsFromDefaulCLIApplication()
818
+
819
+ experiments = []
820
+ for i in range(4):
821
+ experiment_factory = factories.ExperimentFactory()
822
+ experiment_factory["sample"]["individual"]["species"] = "HUMAN"
823
+ experiments.append(api.create_instance("experiments", **experiment_factory))
824
+
825
+ analysis = api.create_instance(
826
+ "analyses",
827
+ **{
828
+ **factories.AnalysisFactory(),
829
+ "targets": experiments,
830
+ "references": experiments,
831
+ },
832
+ )
833
+
834
+ pairs_file = tmpdir.join("pairs.txt")
835
+ pairs_file.write(experiments[1].system_id + "\t" + experiments[0].system_id + "\n")
836
+
837
+ command = ExperimentsFromDefaulCLIApplication.as_cli_command()
838
+ runner = CliRunner()
839
+
840
+ args = [
841
+ "--pair",
842
+ experiments[0].system_id,
843
+ experiments[1].system_id,
844
+ "--pairs",
845
+ experiments[2].system_id,
846
+ experiments[3].system_id,
847
+ "--targets-filters",
848
+ "pk",
849
+ experiments[3].pk,
850
+ "--references-filters",
851
+ "pk",
852
+ experiments[2].pk,
853
+ "--analyses-filters",
854
+ "pk",
855
+ analysis.pk,
856
+ "--pairs-from-file",
857
+ str(pairs_file),
858
+ ]
859
+
860
+ # get coverage for invalid experiments
861
+ api.patch_instance(
862
+ "experiments", experiments[0].system_id, notes="raise validation error"
863
+ )
864
+ result = runner.invoke(command, args, catch_exceptions=False)
865
+ assert experiments[0].system_id in result.output
866
+ assert "STAGED 3 | SKIPPED 0 | INVALID 2" in result.output, result.output
867
+
868
+ # revalidate experiment on existing analysis
869
+ api.patch_instance("experiments", experiments[0].system_id, notes="")
870
+ result = runner.invoke(command, args, catch_exceptions=False)
871
+ assert experiments[0].system_id in result.output
872
+ assert "STAGED 5 | SKIPPED 0 | INVALID 0" in result.output
873
+
874
+ # just get coverage for get_job_name
875
+ assert ExperimentsFromDefaulCLIApplication.get_job_name(analysis)
876
+
877
+
878
+ def test_validate_individuals():
879
+ # Test matched analyis
880
+ matched_application = AbstractApplication()
881
+
882
+ targets = [
883
+ {"system_id": 1, "sample": {"individual": {"pk": 1, "system_id": "ind1"}}}
884
+ ]
885
+ references = [
886
+ {"system_id": 2, "sample": {"individual": {"pk": 1, "system_id": "ind1"}}}
887
+ ]
888
+ matched_application.validate_individuals(targets, references)
889
+
890
+ with pytest.raises(AssertionError) as error:
891
+ targets = [
892
+ {"system_id": 1, "sample": {"individual": {"pk": 2, "system_id": "ind2"}}}
893
+ ]
894
+ matched_application.validate_individuals(targets, references)
895
+ assert "Same individual required:" in str(error.value)
896
+
897
+ # Test unmatched analysis
898
+ unmatched_application = AbstractApplication()
899
+ unmatched_application.IS_UNMATCHED = True
900
+
901
+ targets = [
902
+ {"system_id": 1, "sample": {"individual": {"pk": 1, "system_id": "ind1"}}}
903
+ ]
904
+ references = [
905
+ {"system_id": 2, "sample": {"individual": {"pk": 2, "system_id": "ind2"}}}
906
+ ]
907
+ unmatched_application.validate_individuals(targets, references)
908
+
909
+ with pytest.raises(AssertionError) as error:
910
+ targets = [
911
+ {"system_id": 1, "sample": {"individual": {"pk": 2, "system_id": "ind2"}}}
912
+ ]
913
+ unmatched_application.validate_individuals(targets, references)
914
+ assert "Different individuals required:" in str(error.value)
915
+
916
+
917
+ def test_notify_project_analyst():
918
+ # Test notification for project analysts
919
+ application = MockApplication()
920
+
921
+ project = api.create_instance("projects", **factories.ProjectFactory())
922
+ project["analyst"]
923
+ experiments = [factories.ExperimentFactory(projects=[project]) for i in range(4)]
924
+ experiments = [api.create_instance("experiments", **i) for i in experiments]
925
+ analysis = api.create_instance(
926
+ "analyses",
927
+ **{
928
+ **factories.AnalysisFactory(),
929
+ "targets": experiments,
930
+ "references": experiments,
931
+ },
932
+ )
933
+
934
+ assert application.notify_project_analyst(analysis, "test", "test").ok
935
+
936
+
937
+ ######## Test App Dependencies ###########
938
+
939
+
940
+ class MockFirstVersion(MockApplication):
941
+ NAME = "PRE-PROCESSING"
942
+ VERSION = "v1"
943
+
944
+ def get_analysis_results(self, analysis):
945
+ return {"analysis_result_key": 1}
946
+
947
+
948
+ class MockSecondVersion(MockApplication):
949
+ NAME = "PRE-PROCESSING"
950
+ VERSION = "v2"
951
+
952
+ def get_analysis_results(self, analysis):
953
+ return {"analysis_result_key": 2}
954
+
955
+ class PreProcessWithInProgress(MockApplication):
956
+ NAME = "PRE-PROCESSING"
957
+ VERSION = "v3"
958
+
959
+ def get_analysis_results(self, analysis):
960
+ return {"analysis_result_key": 3}
961
+
962
+ def get_after_completion_status(self, analysis):
963
+ return "IN_PROGRESS"
964
+
965
+
966
+ class PostMockApp(MockApplication):
967
+ application_inputs = {"dependency_key": NotImplemented}
968
+
969
+ def get_command(self, analysis, inputs, settings):
970
+ return f"echo {analysis['targets'][0]['system_id']}"
971
+
972
+ def get_analysis_results(self, analysis):
973
+ return {"analysis_result_key": 4}
974
+
975
+
976
+ class AppThatDependsOnFixedVersionV1(PostMockApp):
977
+ NAME = "POST-PROCESSING"
978
+ VERSION = "DEPENDS ON PRE-PROCESSING v1, FIXED WITH PK"
979
+
980
+ @cached_property
981
+ def dependencies_results(self):
982
+ return [
983
+ {
984
+ "app": MockFirstVersion(),
985
+ "result": "analysis_result_key",
986
+ "name": "dependency_key",
987
+ }
988
+ ]
989
+
990
+
991
+ class AppThatDependsOnFixedVersionV2(PostMockApp):
992
+ NAME = "POST-PROCESSING"
993
+ VERSION = "DEPENDS ON PRE-PROCESSING v2, FIXED WITH NAME AND VERSION"
994
+
995
+ @cached_property
996
+ def dependencies_results(self):
997
+ return [
998
+ {
999
+ "app_name": "PRE-PROCESSING",
1000
+ "app_version": "v2",
1001
+ "result": "analysis_result_key",
1002
+ "name": "dependency_key",
1003
+ }
1004
+ ]
1005
+
1006
+
1007
+ class AppThatDependsOnAnyVersion(PostMockApp):
1008
+ NAME = "POST-PROCESSING"
1009
+ VERSION = "DEPENDS ON PRE-PROCESSING, ANY VERSION"
1010
+
1011
+ @cached_property
1012
+ def dependencies_results(self):
1013
+ return [
1014
+ {
1015
+ "app_name": "PRE-PROCESSING",
1016
+ "result": "analysis_result_key",
1017
+ "name": "dependency_key",
1018
+ }
1019
+ ]
1020
+
1021
+
1022
+ class AppThatDependsOnAnyLatestVersion(PostMockApp):
1023
+ NAME = "POST-PROCESSING"
1024
+ VERSION = "DEPENDS ON PRE-PROCESSING, LATEST VERSION RUN"
1025
+
1026
+ @cached_property
1027
+ def dependencies_results(self):
1028
+ return [
1029
+ {
1030
+ "app_name": "PRE-PROCESSING",
1031
+ "app_version": "latest",
1032
+ "result": "analysis_result_key",
1033
+ "name": "dependency_key",
1034
+ }
1035
+ ]
1036
+
1037
+ class AppThatDependsOnAnyLatestVersionInProgress(PostMockApp):
1038
+ NAME = "POST-PROCESSING"
1039
+ VERSION = "DEPENDS ON PRE-PROCESSING, LATEST VERSION RUN IN PROGRESS STATUS"
1040
+
1041
+ @cached_property
1042
+ def dependencies_results(self):
1043
+ return [
1044
+ {
1045
+ "app_name": "PRE-PROCESSING",
1046
+ "app_version": "latest",
1047
+ "result": "analysis_result_key",
1048
+ "name": "dependency_key",
1049
+ "status": "IN_PROGRESS",
1050
+ }
1051
+ ]
1052
+
1053
+ class AppThatDependsOnAnyLatestVersionNoLinked(PostMockApp):
1054
+ NAME = "POST-PROCESSING"
1055
+ VERSION = "DEPENDS ON PRE-PROCESSING, LATEST VERSION. NO LINK"
1056
+
1057
+ @cached_property
1058
+ def dependencies_results(self):
1059
+ return [
1060
+ {
1061
+ "app_name": "PRE-PROCESSING",
1062
+ "app_version": "latest",
1063
+ "result": "analysis_result_key",
1064
+ "name": "dependency_key",
1065
+ "linked": False,
1066
+ }
1067
+ ]
1068
+
1069
+
1070
+ def test_get_dependencies():
1071
+ """Test dependencies when multiple versions of the same app exists."""
1072
+ individual = factories.IndividualFactory(species="HUMAN")
1073
+ sample = factories.SampleFactory(individual=individual)
1074
+ project = api.create_instance("projects", **factories.ProjectFactory())
1075
+ experiment = factories.ExperimentFactory(
1076
+ identifier="test-experiment", sample=sample, projects=[project]
1077
+ )
1078
+ experiment = api.create_instance("experiments", **experiment)
1079
+ tuples = [([experiment], [])]
1080
+
1081
+ # I) Run dependency VERSION v1, only 1 result exists
1082
+ # --------------------------------------------------
1083
+ application = MockFirstVersion()
1084
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1085
+ preprocess_analysis_v1, status = ran_analyses[0]
1086
+ assert status == "SUCCEEDED"
1087
+
1088
+ experiment = api.get_instance("experiments", experiment.system_id)
1089
+ tuples = [([experiment], [])]
1090
+
1091
+ # A) App that relies on strict v1 results succeeds
1092
+ application = AppThatDependsOnFixedVersionV1()
1093
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1094
+ postprocess_analysis, status = ran_analyses[0]
1095
+ assert status == "SUCCEEDED"
1096
+ assert postprocess_analysis.analyses[0] == preprocess_analysis_v1.pk
1097
+
1098
+ # B) App that relies on strict v2 is invalid, it doesn't have available results
1099
+ application = AppThatDependsOnFixedVersionV2()
1100
+ _, _, invalid_analyses = application.run(tuples, commit=True)
1101
+ _, validation_error = invalid_analyses[0]
1102
+ assert "No results found for application" in validation_error.message
1103
+
1104
+ # II) Run VERSION v2, now multiple results of different versions exist
1105
+ # --------------------------------------------------------------------
1106
+ application = MockSecondVersion()
1107
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1108
+ preprocess_analysis_v2, status = ran_analyses[0]
1109
+ assert status == "SUCCEEDED"
1110
+
1111
+ experiment = api.get_instance("experiments", experiment.system_id)
1112
+ tuples = [([experiment], [])]
1113
+
1114
+ # C) Invalid, multiple version results found but no version was specified
1115
+ application = AppThatDependsOnAnyVersion()
1116
+ _, _, invalid_analyses = application.run(tuples, commit=True)
1117
+ _, validation_error = invalid_analyses[0]
1118
+ assert "Multiple results returned" in validation_error.message
1119
+
1120
+ # D) Succeeds, multiple version results exist, latest used (v2)
1121
+ application = AppThatDependsOnAnyLatestVersion()
1122
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1123
+ analysis, status = ran_analyses[0]
1124
+ assert status == "SUCCEEDED"
1125
+ assert analysis.analyses[0] == preprocess_analysis_v2.pk
1126
+
1127
+ # E) New analysis doesn't link the previous analyses to it's run
1128
+ application = AppThatDependsOnAnyLatestVersionNoLinked()
1129
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1130
+ analysis, status = ran_analyses[0]
1131
+ assert status == "SUCCEEDED"
1132
+ assert not analysis.analyses
1133
+
1134
+ # III) Run VERSION v3, with IN_PROGRESS status
1135
+ # --------------------------------------------
1136
+ application = PreProcessWithInProgress()
1137
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1138
+ preprocess_analysis_v3, status = ran_analyses[0]
1139
+ assert status == "IN_PROGRESS"
1140
+
1141
+ experiment = api.get_instance("experiments", experiment.system_id)
1142
+ tuples = [([experiment], [])]
1143
+
1144
+ # F) Succeeds, using result from IN_PROGRESS analysis
1145
+ application = AppThatDependsOnAnyLatestVersionInProgress()
1146
+ ran_analyses, _, __ = application.run(tuples, commit=True)
1147
+ analysis, status = ran_analyses[0]
1148
+ assert status == "SUCCEEDED"
1149
+ assert analysis.analyses[0] == preprocess_analysis_v3.pk
1150
+
1151
+
1152
+ def test_ran_by_user(tmpdir, capsys):
1153
+ user = api.create_instance("users", **factories.UserFactory())
1154
+
1155
+ experiment = api.create_instance("experiments", **factories.ExperimentFactory())
1156
+
1157
+ application = MockApplication()
1158
+ api.create_instance(
1159
+ "analyses",
1160
+ storage_url=tmpdir.strpath,
1161
+ status="FAILED",
1162
+ ran_by=user.username,
1163
+ application=application.application,
1164
+ targets=[experiment],
1165
+ )
1166
+ ran_analyses, skipped_analyses, invalid_analyses = application.run(
1167
+ [([experiment], [])], commit=True, restart=True
1168
+ )
1169
+ assert len(ran_analyses) == 0
1170
+ assert len(skipped_analyses) == 0
1171
+ assert len(invalid_analyses) == 1
1172
+
1173
+ captured = capsys.readouterr()
1174
+ assert "Can't restart: started by different user. Consider --force" in captured.out
1175
+
1176
+
1177
+ def test_commit_description(tmpdir, capsys):
1178
+ user = api.create_instance("users", **factories.UserFactory())
1179
+
1180
+ # testing description on application_protect_results = False, with and without --commit
1181
+ experiment1 = api.create_instance("experiments", **factories.ExperimentFactory())
1182
+ experiment2 = api.create_instance("experiments", **factories.ExperimentFactory())
1183
+ experiment3 = api.create_instance("experiments", **factories.ExperimentFactory())
1184
+
1185
+ application = MockApplication()
1186
+ application.application_protect_results = False
1187
+ analysis = api.create_instance(
1188
+ "analyses",
1189
+ storage_url=tmpdir.strpath,
1190
+ status="FAILED",
1191
+ ran_by=user.username,
1192
+ application=application.application,
1193
+ targets=[experiment2],
1194
+ )
1195
+
1196
+ analysis = api.create_instance(
1197
+ "analyses",
1198
+ storage_url=tmpdir.strpath,
1199
+ status="SUCCEEDED",
1200
+ ran_by=user.username,
1201
+ application=application.application,
1202
+ targets=[experiment3],
1203
+ )
1204
+ ran_analyses, skipped_analyses, invalid_analyses = application.run(
1205
+ [([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=False
1206
+ )
1207
+
1208
+ captured = capsys.readouterr()
1209
+ assert "STAGED 1 | SKIPPED 2 | INVALID 0\n" in captured.out
1210
+ assert "2 analyses available to run:" in captured.out
1211
+ assert "\t1 STAGED" in captured.out
1212
+ assert "\t1 SUCCEEDED (Unprotected)" in captured.out
1213
+
1214
+ ran_analyses, skipped_analyses, invalid_analyses = application.run(
1215
+ [([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=True
1216
+ )
1217
+ captured = capsys.readouterr()
1218
+ assert "RAN 2 | SKIPPED 1 | INVALID 0" in captured.out
1219
+
1220
+ # testing description on application_protect_results = True, with and without --commit
1221
+ experiment1 = api.create_instance("experiments", **factories.ExperimentFactory())
1222
+ experiment2 = api.create_instance("experiments", **factories.ExperimentFactory())
1223
+ experiment3 = api.create_instance("experiments", **factories.ExperimentFactory())
1224
+
1225
+ application = MockApplication()
1226
+ application.application_protect_results = True
1227
+ api.create_instance(
1228
+ "analyses",
1229
+ storage_url=tmpdir.strpath,
1230
+ status="FAILED",
1231
+ ran_by=user.username,
1232
+ application=application.application,
1233
+ targets=[experiment2],
1234
+ )
1235
+
1236
+ api.create_instance(
1237
+ "analyses",
1238
+ storage_url=tmpdir.strpath,
1239
+ status="SUCCEEDED",
1240
+ ran_by=user.username,
1241
+ application=application.application,
1242
+ targets=[experiment3],
1243
+ )
1244
+ application.run(
1245
+ [([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=False
1246
+ )
1247
+ captured = capsys.readouterr()
1248
+ assert "STAGED 1 | SKIPPED 2 | INVALID 0\n" in captured.out
1249
+
1250
+ application.run(
1251
+ [([experiment1], []), ([experiment2], []), ([experiment3], [])], commit=True
1252
+ )
1253
+ captured = capsys.readouterr()
1254
+ assert "RAN 1 | SKIPPED 2 | INVALID 0" in captured.out