Skip to content

Commit

Permalink
Merge pull request nipreps#1294 from jhlegarreta/AddCLIEntryPointTest
Browse files Browse the repository at this point in the history
ENH: Add CLI entry point test
  • Loading branch information
oesteban authored Jul 11, 2024
2 parents 207356d + d9ab100 commit a4e4c1f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mriqc/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""Definition of the command line interface's (CLI) entry point."""


def main():
def main(argv=None):
"""Entry point for MRIQC's CLI."""
import atexit
import gc
Expand All @@ -40,7 +40,7 @@ def main():
config.settings.start_time = time.time()

# Run parser
parse_args()
parse_args(argv)

if config.execution.pdb:
from mriqc.utils.debug import setup_exceptionhook
Expand Down
64 changes: 64 additions & 0 deletions mriqc/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2024 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#

import sys

import pytest

from mriqc.__main__ import main


@pytest.fixture(autouse=True)
def set_command(monkeypatch):
with monkeypatch.context() as m:
m.setattr(sys, 'argv', ['mriqc'])
yield


def test_help(capsys):
with pytest.raises(SystemExit):
main(['--help'])
captured = capsys.readouterr()
assert captured.out.startswith('usage: mriqc [-h]')


def test_main(tmp_path):
bids_dir = tmp_path / 'data/sub-01'
out_path = tmp_path / 'out'

with pytest.raises(SystemExit):
main([str(bids_dir), str(out_path)])

analysis_level = 'participant'
species = 'human'

with pytest.raises(SystemExit):
main(
[
str(bids_dir),
str(out_path),
analysis_level,
'--species',
species,
]
)

0 comments on commit a4e4c1f

Please sign in to comment.