forked from nipreps/mriqc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI entry point test. Add `argv` to `main()` for easier testing.
- Loading branch information
1 parent
207356d
commit d9ab100
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
] | ||
) |