forked from DIRACGrid/dirac-cwl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workflows.py
More file actions
734 lines (679 loc) · 25.9 KB
/
test_workflows.py
File metadata and controls
734 lines (679 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
import re
import shutil
import subprocess
import threading
import time
from pathlib import Path
import pytest
from typer.testing import CliRunner
from dirac_cwl_proto import app
def strip_ansi_codes(text: str) -> str:
"""Remove ANSI color codes from text."""
return re.sub(r"\x1b\[[0-9;]*m", "", text)
@pytest.fixture()
def cli_runner():
return CliRunner()
@pytest.fixture()
def cleanup():
def _cleanup():
shutil.rmtree("filecatalog", ignore_errors=True)
shutil.rmtree("sandboxstore", ignore_errors=True)
shutil.rmtree("workernode", ignore_errors=True)
_cleanup()
yield
_cleanup()
# -----------------------------------------------------------------------------
# Job tests
# -----------------------------------------------------------------------------
@pytest.mark.parametrize(
"cwl_file, inputs",
[
# --- Hello World example ---
# There is no input expected
("test/workflows/helloworld/description_basic.cwl", []),
# An input is expected but not required (default value is used)
("test/workflows/helloworld/description_with_inputs.cwl", []),
# A string input is passed
(
"test/workflows/helloworld/description_with_inputs.cwl",
[
"test/workflows/helloworld/type_dependencies/job/inputs-helloworld_with_inputs1.yaml"
],
),
# Multiple string inputs are passed
(
"test/workflows/helloworld/description_with_inputs.cwl",
[
"test/workflows/helloworld/type_dependencies/job/inputs-helloworld_with_inputs1.yaml",
"test/workflows/helloworld/type_dependencies/job/inputs-helloworld_with_inputs2.yaml",
"test/workflows/helloworld/type_dependencies/job/inputs-helloworld_with_inputs3.yaml",
],
),
# --- Test metadata example ---
# A string input is passed
(
"test/workflows/test_meta/test_meta.cwl",
[
"test/workflows/test_meta/override_dirac_hints.yaml",
],
),
# --- Crypto example ---
# Complete
(
"test/workflows/crypto/description.cwl",
["test/workflows/crypto/type_dependencies/job/inputs-crypto_complete.yaml"],
),
# Caesar only
(
"test/workflows/crypto/caesar.cwl",
["test/workflows/crypto/type_dependencies/job/inputs-crypto_complete.yaml"],
),
# ROT13 only
(
"test/workflows/crypto/rot13.cwl",
["test/workflows/crypto/type_dependencies/job/inputs-crypto_complete.yaml"],
),
# Base64 only
(
"test/workflows/crypto/base64.cwl",
["test/workflows/crypto/type_dependencies/job/inputs-crypto_complete.yaml"],
),
# MD5 only
(
"test/workflows/crypto/md5.cwl",
["test/workflows/crypto/type_dependencies/job/inputs-crypto_complete.yaml"],
),
# --- Pi example ---
# Complete
(
"test/workflows/pi/description.cwl",
["test/workflows/pi/type_dependencies/job/inputs-pi_complete.yaml"],
),
# Simulate only
("test/workflows/pi/pisimulate.cwl", []),
# Gather only
(
"test/workflows/pi/pigather.cwl",
["test/workflows/pi/type_dependencies/job/inputs-pi_gather.yaml"],
),
# --- Merge example ---
# Complete
("test/workflows/merge/description.cwl", []),
# --- LHCb example ---
# Complete
(
"test/workflows/lhcb/description.cwl",
["test/workflows/lhcb/type_dependencies/job/inputs-lhcb_complete.yaml"],
),
# Simulate only
(
"test/workflows/lhcb/lhcbsimulate.cwl",
["test/workflows/lhcb/type_dependencies/job/inputs-lhcb_simulate.yaml"],
),
# Reconstruct only
(
"test/workflows/lhcb/lhcbreconstruct.cwl",
["test/workflows/lhcb/type_dependencies/job/inputs-lhcb_reconstruct.yaml"],
),
# --- Mandelbrot example ---
# Complete
(
"test/workflows/mandelbrot/description.cwl",
[
"test/workflows/mandelbrot/type_dependencies/job/inputs-mandelbrot_complete.yaml"
],
),
# Image production only
("test/workflows/mandelbrot/image-prod.cwl", []),
# Image merge only
(
"test/workflows/mandelbrot/image-merge.cwl",
[
"test/workflows/mandelbrot/type_dependencies/job/inputs-mandelbrot_imagemerge.yaml"
],
),
# --- Gaussian fit example ---
# Data generation only
(
"test/workflows/gaussian_fit/data_generation/data-generation.cwl",
[
"test/workflows/gaussian_fit/type_dependencies/job/inputs-data-generation.yaml"
],
),
# Gaussian fit only
(
"test/workflows/gaussian_fit/gaussian_fit/gaussian-fit.cwl",
[
"test/workflows/gaussian_fit/type_dependencies/job/inputs-gaussian-fit.yaml"
],
),
],
)
def test_run_job_success(cli_runner, cleanup, cwl_file, inputs):
# CWL file is the first argument
command = ["job", "submit", cwl_file]
# Add the input file(s)
for input in inputs:
command.extend(["--parameter-path", input])
result = cli_runner.invoke(app, command)
# Remove ANSI color codes for assertion
clean_output = strip_ansi_codes(result.stdout)
assert "CLI: Job(s) done" in clean_output, f"Failed to run the job: {result.stdout}"
@pytest.mark.parametrize(
"cwl_file, inputs, expected_error",
[
# The description file is malformed: class attribute is unknown
(
"test/workflows/malformed_description/description_malformed_class.cwl",
[],
"`class`containsundefinedreferenceto",
),
# The description file is malformed: baseCommand is unknown
(
"test/workflows/malformed_description/description_malformed_command.cwl",
[],
"invalidfield`baseComand`",
),
# The description file points to a non-existent file (subworkflow)
(
"test/workflows/bad_references/reference_doesnotexists.cwl",
[],
"Nosuchfileordirectory",
),
# The description file points to another file point to it (circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
# The description file points to itself (another circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
# The configuration file is malformed: the hints are overridden more than once
(
"test/workflows/test_meta/test_meta.cwl",
[
"test/workflows/test_meta/override_dirac_hints_twice.yaml",
],
"Failedtovalidatetheparameter",
),
],
)
def test_run_job_validation_failure(
cli_runner, cleanup, cwl_file, inputs, expected_error
):
command = ["job", "submit", cwl_file]
for input in inputs:
command.extend(["--parameter-path", input])
result = cli_runner.invoke(app, command)
clean_stdout = strip_ansi_codes(result.stdout)
assert "Job(s) done" not in clean_stdout, "The job did complete successfully."
# Check all possible output sources
clean_output = re.sub(r"\s+", "", result.stdout)
try:
clean_stderr = re.sub(r"\s+", "", result.stderr or "")
except (ValueError, AttributeError):
clean_stderr = ""
clean_exception = re.sub(
r"\s+", "", str(result.exception) if result.exception else ""
)
# Handle different possible error messages for circular references
if expected_error == "Recursingintostep":
# Accept multiple possible error patterns for circular references
circular_ref_patterns = [
"Recursingintostep",
"maximumrecursiondepthexceeded",
"RecursionError",
"circularreference",
]
error_found = any(
pattern in clean_output
or pattern in clean_stderr
or pattern in clean_exception
for pattern in circular_ref_patterns
)
assert error_found, (
f"None of the expected circular reference error patterns found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)
else:
error_found = (
expected_error in clean_output
or expected_error in clean_stderr
or expected_error in clean_exception
)
assert error_found, (
f"Expected error '{expected_error}' not found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)
def test_run_job_parallely():
error_margin_percentage = 0.10
# This command forces the process 'dirac-cwl' to execute ONLY in
# one core of the machine, independently of how many there are
# phisically available.
# This simulates a sequential execution of the worklflow.
command = [
"taskset",
"-c",
"0",
"dirac-cwl",
"job",
"submit",
"test/workflows/parallel/description.cwl",
]
start = time.time()
subprocess.run(command)
end = time.time()
sequential_time = end - start
command = [
"dirac-cwl",
"job",
"submit",
"test/workflows/parallel/description.cwl",
]
start = time.time()
subprocess.run(command)
end = time.time()
parallel_time = end - start
min_time = (1 - error_margin_percentage) * sequential_time / 2
max_time = (1 + error_margin_percentage) * sequential_time / 2
# Parallel time should be aproximately half the time.
assert (parallel_time > min_time) and (parallel_time < max_time), (
"Difference between parallel and sequential time is too large",
f"Sequential: {sequential_time} # Parallel: {parallel_time}",
f"Sequential time should be twice the parallel time with an error of {int(error_margin_percentage*100)}%",
)
# -----------------------------------------------------------------------------
# Transformation tests
# -----------------------------------------------------------------------------
@pytest.mark.parametrize(
"cwl_file, metadata",
[
# --- Hello World example ---
# There is no input expected
("test/workflows/helloworld/description_basic.cwl", None),
# --- Crypto example ---
# Complete
("test/workflows/crypto/description.cwl", None),
# Caesar only
("test/workflows/crypto/caesar.cwl", None),
# ROT13 only
("test/workflows/crypto/rot13.cwl", None),
# Base64 only
("test/workflows/crypto/base64.cwl", None),
# MD5 only
("test/workflows/crypto/md5.cwl", None),
# --- Pi example ---
# There is no input expected
(
"test/workflows/pi/pisimulate.cwl",
"test/workflows/pi/type_dependencies/transformation/metadata-pi_simulate.yaml",
),
# --- Pi v2 example ---
# There is no input expected
(
"test/workflows/merge/pisimulate_v2.cwl",
"test/workflows/merge/type_dependencies/transformation/metadata-pi_simulate_v2.yaml",
),
# --- LHCb example ---
(
"test/workflows/lhcb/lhcbsimulate.cwl",
"test/workflows/lhcb/type_dependencies/transformation/metadata-lhcb_simulate.yaml",
),
# --- Mandelbrot example ---
(
"test/workflows/mandelbrot/image-prod.cwl",
"test/workflows/mandelbrot/type_dependencies/transformation/metadata-mandelbrot_imageprod.yaml",
),
# --- Gaussian fit example ---
# Data generation workflow
(
"test/workflows/gaussian_fit/data_generation/data-generation-workflow.cwl",
"test/workflows/gaussian_fit/type_dependencies/transformation/inputs-data-generation.yaml",
),
],
)
def test_run_nonblocking_transformation_success(
cli_runner, cleanup, cwl_file, metadata
):
# CWL file is the first argument
command = ["transformation", "submit", cwl_file]
# Add the metadata file
if metadata:
command.extend(["--metadata-path", metadata])
result = cli_runner.invoke(app, command)
clean_output = strip_ansi_codes(result.stdout)
assert (
"Transformation done" in clean_output
), f"Failed to run the transformation: {result.stdout}"
@pytest.mark.parametrize(
"cwl_file, metadata, destination_source_input_data",
[
# --- Pi example ---
(
"test/workflows/pi/pigather.cwl",
"test/workflows/pi/type_dependencies/transformation/metadata-pi_gather.yaml",
{
"filecatalog/pi/100": [
"test/workflows/pi/type_dependencies/job/result_1.sim",
"test/workflows/pi/type_dependencies/job/result_2.sim",
"test/workflows/pi/type_dependencies/job/result_3.sim",
"test/workflows/pi/type_dependencies/job/result_4.sim",
"test/workflows/pi/type_dependencies/job/result_5.sim",
]
},
),
# --- LHCb example ---
(
"test/workflows/lhcb/lhcbreconstruct.cwl",
"test/workflows/lhcb/type_dependencies/transformation/metadata-lhcb_reconstruct.yaml",
{
"filecatalog/lhcb/456/123/simulation": [
"test/workflows/lhcb/type_dependencies/job/Gauss_123_456_1.sim",
"test/workflows/lhcb/type_dependencies/job/Gauss_456_456_1.sim",
"test/workflows/lhcb/type_dependencies/job/Gauss_789_456_1.sim",
]
},
),
# --- Mandelbrot example ---
(
"test/workflows/mandelbrot/image-merge.cwl",
"test/workflows/mandelbrot/type_dependencies/transformation/metadata-mandelbrot_imagemerge.yaml",
{
"filecatalog/mandelbrot/images/raw/1920x1080/": [
"test/workflows/mandelbrot/type_dependencies/transformation/data_1.txt",
"test/workflows/mandelbrot/type_dependencies/transformation/data_2.txt",
"test/workflows/mandelbrot/type_dependencies/transformation/data_3.txt",
]
},
),
# Gaussian fit workflow
(
"test/workflows/gaussian_fit/gaussian_fit/gaussian-fit-workflow.cwl",
"test/workflows/gaussian_fit/type_dependencies/transformation/inputs-gaussian-fit.yaml",
{
"filecatalog/gaussian_fit/data-generation-1/": [
"test/workflows/gaussian_fit/type_dependencies/transformation/data-generation-1/data_gen1.txt",
],
"filecatalog/gaussian_fit/data-generation-2/": [
"test/workflows/gaussian_fit/type_dependencies/transformation/data-generation-2/data_gen2.txt",
],
},
),
],
)
def test_run_blocking_transformation_success(
cli_runner, cleanup, cwl_file, metadata, destination_source_input_data
):
# Define a function to run the transformation command and return the result
def run_transformation():
command = ["transformation", "submit", cwl_file]
if metadata:
command.extend(["--metadata-path", metadata])
return cli_runner.invoke(app, command)
# Start running the transformation in a separate thread and capture the result
transformation_result = None
def run_and_capture():
nonlocal transformation_result
transformation_result = run_transformation()
transformation_thread = threading.Thread(target=run_and_capture)
transformation_thread.start()
# Give it some time to ensure the command is waiting for input files
time.sleep(5)
# Ensure the command is waiting (e.g., it hasn't finished yet)
assert (
transformation_thread.is_alive()
), "The transformation should be waiting for files."
for destination, inputs in destination_source_input_data.items():
# Copy the input data to the destination
destination = Path(destination)
destination.mkdir(parents=True, exist_ok=True)
for input in inputs:
shutil.copy(input, destination)
# Wait for the thread to finish
transformation_thread.join(timeout=60)
# Check if the transformation completed successfully
assert (
transformation_result is not None
), "The transformation result was not captured."
clean_transformation_output = strip_ansi_codes(transformation_result.stdout)
assert (
"Transformation done" in clean_transformation_output
), "The transformation did not complete successfully."
@pytest.mark.parametrize(
"cwl_file, metadata, expected_error",
[
# The description file is malformed: class attribute is unknown
(
"test/workflows/malformed_description/description_malformed_class.cwl",
None,
"`class`containsundefinedreferenceto",
),
# The description file is malformed: baseCommand is unknown
(
"test/workflows/malformed_description/description_malformed_command.cwl",
None,
"invalidfield`baseComand`",
),
# The description file points to a non-existent file (subworkflow)
(
"test/workflows/bad_references/reference_doesnotexists.cwl",
[],
"Nosuchfileordirectory",
),
# The description file points to another file point to it (circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
# The description file points to itself (another circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
],
)
def test_run_transformation_validation_failure(
cli_runner, cwl_file, cleanup, metadata, expected_error
):
command = ["transformation", "submit", cwl_file]
if metadata:
command.extend(["--metadata-path", metadata])
result = cli_runner.invoke(app, command)
clean_stdout = strip_ansi_codes(result.stdout)
assert (
"Transformation done" not in clean_stdout
), "The transformation did complete successfully."
# Check all possible output sources
clean_output = re.sub(r"\s+", "", result.stdout)
try:
clean_stderr = re.sub(r"\s+", "", result.stderr or "")
except (ValueError, AttributeError):
clean_stderr = ""
clean_exception = re.sub(
r"\s+", "", str(result.exception) if result.exception else ""
)
# Handle multiple possible error patterns for circular references
if expected_error == "Recursingintostep":
# Check for various circular reference error patterns
circular_ref_patterns = [
"Recursingintostep",
"RecursionError",
"maximumrecursiondepthexceeded",
"circularreference",
]
error_found = any(
pattern in clean_output
or pattern in clean_stderr
or pattern in clean_exception
for pattern in circular_ref_patterns
)
assert error_found, (
f"None of the expected circular reference error patterns were found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)
else:
error_found = (
expected_error in clean_output
or expected_error in clean_stderr
or expected_error in clean_exception
)
assert error_found, (
f"Expected error '{expected_error}' not found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)
# -----------------------------------------------------------------------------
# Production tests
# -----------------------------------------------------------------------------
@pytest.mark.parametrize(
"cwl_file, metadata",
[
# --- Crypto example ---
# Complete
("test/workflows/crypto/description.cwl", None),
# --- Pi example ---
# There is no input expected
(
"test/workflows/pi/description.cwl",
"test/workflows/pi/type_dependencies/production/metadata-pi_complete.yaml",
),
# --- Merge example ---
# There is no input expected
(
"test/workflows/merge/description.cwl",
"test/workflows/merge/type_dependencies/production/metadata-merge_complete.yaml",
),
# --- LHCb example ---
# Complete
(
"test/workflows/lhcb/description.cwl",
"test/workflows/lhcb/type_dependencies/production/metadata-lhcb_complete.yaml",
),
# --- Mandelbrot example ---
(
"test/workflows/mandelbrot/description.cwl",
"test/workflows/mandelbrot/type_dependencies/production/metadata-mandelbrot_complete.yaml",
),
# --- Gaussian fit example ---
# Complete
(
"test/workflows/gaussian_fit/main-workflow.cwl",
"test/workflows/gaussian_fit/type_dependencies/production/metadata-gaussian-fit-complete.yaml",
),
],
)
def test_run_simple_production_success(cli_runner, cleanup, cwl_file, metadata):
# CWL file is the first argument
command = ["production", "submit", cwl_file]
# Add the metadata file
if metadata:
command.extend(["--steps-metadata-path", metadata])
result = cli_runner.invoke(app, command)
clean_output = strip_ansi_codes(result.stdout)
assert (
"Production done" in clean_output
), f"Failed to run the production: {result.stdout}"
@pytest.mark.parametrize(
"cwl_file, metadata, expected_error",
[
# The description file is malformed: class attribute is unknown
(
"test/workflows/malformed_description/description_malformed_class.cwl",
None,
"`class`containsundefinedreferenceto",
),
# The description file is malformed: baseCommand is unknown
(
"test/workflows/malformed_description/description_malformed_command.cwl",
None,
"invalidfield`baseComand`",
),
# The description file points to a non-existent file (subworkflow)
(
"test/workflows/bad_references/reference_doesnotexists.cwl",
[],
"Nosuchfileordirectory",
),
# The description file points to another file point to it (circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
# The description file points to itself (another circular dependency)
(
"test/workflows/bad_references/reference_circular1.cwl",
[],
"Recursingintostep",
),
# The workflow is a CommandLineTool instead of a Workflow
(
"test/workflows/helloworld/description_basic.cwl",
None,
"InputshouldbeaninstanceofWorkflow",
),
# The metadata has an unexistent step name
(
"test/workflows/mandelbrot/description.cwl",
"test/workflows/mandelbrot/type_dependencies/production/malformed-wrong-stepname_metadata-mandelbrot_complete.yaml",
"Thefollowingstepsaremissingfromthetaskworkflow:{'this-step-doesnot-exist'}",
),
# The metadata has an unexistent type
(
"test/workflows/mandelbrot/description.cwl",
"test/workflows/mandelbrot/type_dependencies/production/malformed-nonexisting-type_metadata-mandelbrot_complete.yaml",
"Unknownexecutionhooksplugin:'MandelBrotDoesNotExist'",
),
],
)
def test_run_production_validation_failure(
cli_runner, cleanup, cwl_file, metadata, expected_error
):
command = ["production", "submit", cwl_file]
if metadata:
command.extend(["--steps-metadata-path", metadata])
result = cli_runner.invoke(app, command)
clean_stdout = strip_ansi_codes(result.stdout)
assert (
"Transformation done" not in clean_stdout
), "The transformation did complete successfully."
# Check all possible output sources
clean_output = re.sub(r"\s+", "", f"{result.stdout}")
try:
clean_stderr = re.sub(r"\s+", "", result.stderr or "")
except (ValueError, AttributeError):
clean_stderr = ""
clean_exception = re.sub(r"\s+", "", f"{result.exception}")
if expected_error == "Recursingintostep":
# Check for various circular reference error patterns
circular_ref_patterns = [
"Recursingintostep",
"RecursionError",
"maximumrecursiondepthexceeded",
"circularreference",
]
error_found = any(
pattern in clean_output
or pattern in clean_stderr
or pattern in clean_exception
for pattern in circular_ref_patterns
)
assert error_found, (
f"None of the expected circular reference error patterns were found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)
else:
error_found = (
expected_error in clean_output
or expected_error in clean_stderr
or expected_error in clean_exception
)
assert error_found, (
f"Expected error '{expected_error}' not found in "
f"stdout: {clean_output}, stderr: {clean_stderr}, exception: {clean_exception}"
)