-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add tests for --version and version
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Test version-checking commands""" | ||
import pytest | ||
import sys | ||
|
||
from unittest import mock | ||
|
||
from cpac import __version__ | ||
from cpac.__main__ import run | ||
from .CONSTANTS import set_commandline_args | ||
|
||
wrapper_version_string = f'cpac (convenience wrapper) version {__version__}' | ||
|
||
|
||
def startswith_cpac_version(captured): | ||
"""Check if captured text starts with cpac version | ||
Parameters | ||
---------- | ||
captured : str | ||
Returns | ||
------- | ||
bool | ||
""" | ||
return captured.out.strip().startswith(wrapper_version_string) | ||
|
||
|
||
@pytest.mark.parametrize('argsep', [' ', '=']) | ||
def test_cpac_version(argsep, capsys, platform=None, tag=None): | ||
r"""Test `cpac version`""" | ||
def run_test(argv, platform): | ||
with mock.patch.object(sys, 'argv', argv): | ||
run() | ||
captured = capsys.readouterr() | ||
assert startswith_cpac_version(captured) | ||
assert 'C-PAC version ' in captured.out | ||
if platform is not None: | ||
assert platform.title() in captured.out | ||
else: | ||
assert 'Docker' in captured.out | ||
args = set_commandline_args(platform, tag, argsep) | ||
argv = 'version' | ||
|
||
|
||
def test_cpac__version(capsys): | ||
r"""Test `cpac --version`""" | ||
with mock.patch.object(sys, 'argv', ['cpac', '--version']): | ||
with pytest.raises(SystemExit): | ||
run() | ||
captured = capsys.readouterr() | ||
assert startswith_cpac_version(captured) |