|
10 | 10 | from dirac_cwl_proto import app |
11 | 11 |
|
12 | 12 |
|
| 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 | + |
13 | 18 | @pytest.fixture() |
14 | 19 | def cli_runner(): |
15 | 20 | return CliRunner() |
@@ -165,9 +170,9 @@ def test_run_job_success(cli_runner, cleanup, cwl_file, inputs): |
165 | 170 | command.extend(["--parameter-path", input]) |
166 | 171 |
|
167 | 172 | 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}" |
171 | 176 |
|
172 | 177 |
|
173 | 178 | @pytest.mark.parametrize( |
@@ -220,7 +225,8 @@ def test_run_job_validation_failure( |
220 | 225 | for input in inputs: |
221 | 226 | command.extend(["--parameter-path", input]) |
222 | 227 | 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." |
224 | 230 |
|
225 | 231 | # Check all possible output sources |
226 | 232 | clean_output = re.sub(r"\s+", "", result.stdout) |
@@ -325,8 +331,9 @@ def test_run_nonblocking_transformation_success( |
325 | 331 | command.extend(["--metadata-path", metadata]) |
326 | 332 |
|
327 | 333 | result = cli_runner.invoke(app, command) |
| 334 | + clean_output = strip_ansi_codes(result.stdout) |
328 | 335 | assert ( |
329 | | - "Transformation done" in result.stdout |
| 336 | + "Transformation done" in clean_output |
330 | 337 | ), f"Failed to run the transformation: {result.stdout}" |
331 | 338 |
|
332 | 339 |
|
@@ -428,8 +435,9 @@ def run_and_capture(): |
428 | 435 | assert ( |
429 | 436 | transformation_result is not None |
430 | 437 | ), "The transformation result was not captured." |
| 438 | + clean_transformation_output = strip_ansi_codes(transformation_result.stdout) |
431 | 439 | assert ( |
432 | | - "Transformation done" in transformation_result.stdout |
| 440 | + "Transformation done" in clean_transformation_output |
433 | 441 | ), "The transformation did not complete successfully." |
434 | 442 |
|
435 | 443 |
|
@@ -475,8 +483,9 @@ def test_run_transformation_validation_failure( |
475 | 483 | if metadata: |
476 | 484 | command.extend(["--metadata-path", metadata]) |
477 | 485 | result = cli_runner.invoke(app, command) |
| 486 | + clean_stdout = strip_ansi_codes(result.stdout) |
478 | 487 | assert ( |
479 | | - "Transformation done" not in result.stdout |
| 488 | + "Transformation done" not in clean_stdout |
480 | 489 | ), "The transformation did complete successfully." |
481 | 490 |
|
482 | 491 | # Check all possible output sources |
@@ -570,8 +579,9 @@ def test_run_simple_production_success(cli_runner, cleanup, cwl_file, metadata): |
570 | 579 | command.extend(["--steps-metadata-path", metadata]) |
571 | 580 |
|
572 | 581 | result = cli_runner.invoke(app, command) |
| 582 | + clean_output = strip_ansi_codes(result.stdout) |
573 | 583 | assert ( |
574 | | - "Production done" in result.stdout |
| 584 | + "Production done" in clean_output |
575 | 585 | ), f"Failed to run the production: {result.stdout}" |
576 | 586 |
|
577 | 587 |
|
@@ -636,8 +646,9 @@ def test_run_production_validation_failure( |
636 | 646 | command.extend(["--steps-metadata-path", metadata]) |
637 | 647 | result = cli_runner.invoke(app, command) |
638 | 648 |
|
| 649 | + clean_stdout = strip_ansi_codes(result.stdout) |
639 | 650 | assert ( |
640 | | - "Transformation done" not in result.stdout |
| 651 | + "Transformation done" not in clean_stdout |
641 | 652 | ), "The transformation did complete successfully." |
642 | 653 |
|
643 | 654 | # Check all possible output sources |
|
0 commit comments