Skip to content

Commit 0e6b1b1

Browse files
committed
Fix sdtoutput interception
1 parent 03ad0a2 commit 0e6b1b1

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

test/test_workflows.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
from dirac_cwl_proto import app
1111

1212

13+
def strip_ansi_codes(text: str) -> str:
14+
"""Remove ANSI color codes from text."""
15+
return re.sub(r"\x1b\[[0-9;]*m", "", text)
16+
17+
1318
@pytest.fixture()
1419
def cli_runner():
1520
return CliRunner()
@@ -165,9 +170,9 @@ def test_run_job_success(cli_runner, cleanup, cwl_file, inputs):
165170
command.extend(["--parameter-path", input])
166171

167172
result = cli_runner.invoke(app, command)
168-
assert (
169-
"CLI: Job(s) done" in result.stdout
170-
), f"Failed to run the job: {result.stdout}"
173+
# Remove ANSI color codes for assertion
174+
clean_output = strip_ansi_codes(result.stdout)
175+
assert "CLI: Job(s) done" in clean_output, f"Failed to run the job: {result.stdout}"
171176

172177

173178
@pytest.mark.parametrize(
@@ -220,7 +225,8 @@ def test_run_job_validation_failure(
220225
for input in inputs:
221226
command.extend(["--parameter-path", input])
222227
result = cli_runner.invoke(app, command)
223-
assert "Job(s) done" not in result.stdout, "The job did complete successfully."
228+
clean_stdout = strip_ansi_codes(result.stdout)
229+
assert "Job(s) done" not in clean_stdout, "The job did complete successfully."
224230

225231
# Check all possible output sources
226232
clean_output = re.sub(r"\s+", "", result.stdout)
@@ -325,8 +331,9 @@ def test_run_nonblocking_transformation_success(
325331
command.extend(["--metadata-path", metadata])
326332

327333
result = cli_runner.invoke(app, command)
334+
clean_output = strip_ansi_codes(result.stdout)
328335
assert (
329-
"Transformation done" in result.stdout
336+
"Transformation done" in clean_output
330337
), f"Failed to run the transformation: {result.stdout}"
331338

332339

@@ -428,8 +435,9 @@ def run_and_capture():
428435
assert (
429436
transformation_result is not None
430437
), "The transformation result was not captured."
438+
clean_transformation_output = strip_ansi_codes(transformation_result.stdout)
431439
assert (
432-
"Transformation done" in transformation_result.stdout
440+
"Transformation done" in clean_transformation_output
433441
), "The transformation did not complete successfully."
434442

435443

@@ -475,8 +483,9 @@ def test_run_transformation_validation_failure(
475483
if metadata:
476484
command.extend(["--metadata-path", metadata])
477485
result = cli_runner.invoke(app, command)
486+
clean_stdout = strip_ansi_codes(result.stdout)
478487
assert (
479-
"Transformation done" not in result.stdout
488+
"Transformation done" not in clean_stdout
480489
), "The transformation did complete successfully."
481490

482491
# Check all possible output sources
@@ -570,8 +579,9 @@ def test_run_simple_production_success(cli_runner, cleanup, cwl_file, metadata):
570579
command.extend(["--steps-metadata-path", metadata])
571580

572581
result = cli_runner.invoke(app, command)
582+
clean_output = strip_ansi_codes(result.stdout)
573583
assert (
574-
"Production done" in result.stdout
584+
"Production done" in clean_output
575585
), f"Failed to run the production: {result.stdout}"
576586

577587

@@ -636,8 +646,9 @@ def test_run_production_validation_failure(
636646
command.extend(["--steps-metadata-path", metadata])
637647
result = cli_runner.invoke(app, command)
638648

649+
clean_stdout = strip_ansi_codes(result.stdout)
639650
assert (
640-
"Transformation done" not in result.stdout
651+
"Transformation done" not in clean_stdout
641652
), "The transformation did complete successfully."
642653

643654
# Check all possible output sources

0 commit comments

Comments
 (0)