-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Click with Typer for CLI tools (#978)
* Replace Click with Typer * Fix entry points
- Loading branch information
Showing
4 changed files
with
110 additions
and
81 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
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 |
---|---|---|
@@ -1,47 +1,40 @@ | ||
#!/usr/bin/env python | ||
"""Tests for CLI tool package.""" | ||
from click.testing import CliRunner | ||
from typer.testing import CliRunner | ||
from torchio.cli import apply_transform | ||
from torchio.cli import print_info | ||
|
||
from .utils import TorchioTestCase | ||
|
||
|
||
runner = CliRunner() | ||
|
||
|
||
class TestCLI(TorchioTestCase): | ||
"""Tests for CLI tool.""" | ||
def test_help(self): | ||
"""Test the CLI.""" | ||
runner = CliRunner() | ||
help_result = runner.invoke(apply_transform.main, ['--help']) | ||
assert help_result.exit_code == 0 | ||
assert 'Show this message and exit.' in help_result.output | ||
|
||
def test_cli_transform(self): | ||
image = str(self.get_image_path('cli')) | ||
runner = CliRunner() | ||
args = [ | ||
image, | ||
'RandomFlip', | ||
'--seed', '0', | ||
'--kwargs', 'axes=(0,1,2)', | ||
'--hide-progress', | ||
image, | ||
] | ||
result = runner.invoke(apply_transform.main, args) | ||
result = runner.invoke(apply_transform.app, args) | ||
assert result.exit_code == 0 | ||
assert result.output == '' | ||
assert result.output.strip() == '' | ||
|
||
def test_bad_transform(self): | ||
ValueError | ||
image = str(self.get_image_path('cli')) | ||
runner = CliRunner() | ||
args = [image, 'RandomRandom', image] | ||
result = runner.invoke(apply_transform.main, args) | ||
result = runner.invoke(apply_transform.app, args) | ||
assert result.exit_code == 1 | ||
|
||
def test_cli_hd(self): | ||
image = str(self.get_image_path('cli')) | ||
runner = CliRunner() | ||
args = [image] | ||
result = runner.invoke(print_info.main, args) | ||
result = runner.invoke(print_info.app, args) | ||
assert result.exit_code == 0 | ||
assert result.output == 'ScalarImage(shape: (1, 10, 20, 30); spacing: (1.00, 1.00, 1.00); orientation: RAS+; dtype: torch.DoubleTensor; memory: 46.9 KiB)\n' # noqa: E501 |