Skip to content

Commit

Permalink
fix: Fix the abort case and test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanwilter committed Sep 9, 2024
1 parent 0cdfddb commit 285ef76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import os
import re
import tempfile
from collections.abc import Generator
from pathlib import Path
Expand All @@ -17,6 +18,11 @@ def pytest_report_header():
return f">>>\tVersion: {version}\n"


def remove_ansi_codes(text):
ansi_escape = re.compile(r"\x1B[@-_][0-?]*[ -/]*[@-~]")
return ansi_escape.sub("", text)


@pytest.fixture(scope="module")
def runner():
return CliRunner()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from process_dcm.const import RESERVED_CSV
from process_dcm.main import app, process_task
from process_dcm.utils import get_md5
from tests.conftest import remove_ansi_codes


def test_main_defaults(runner):
Expand Down Expand Up @@ -110,8 +111,12 @@ def test_main_abort(runner):
# Expect the typer.Abort exception to be raised
args = ["tests/example-dcms", "--verbose", "--keep", "p", "--mapping", RESERVED_CSV, "-v"]
result = runner.invoke(app, args)

# Strip ANSI codes from the output
output = remove_ansi_codes(result.stdout)

assert result.exit_code == 1
assert result.stdout == "Can't use reserved CSV file name: patient_2_study_id.csv\nAborted.\n"
assert output == "Can't use reserved CSV file name: patient_2_study_id.csv\nAborted.\n"


# skip this test for CI
Expand Down

0 comments on commit 285ef76

Please sign in to comment.