Skip to content

Commit

Permalink
✅ Add tests for --version and version
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Mar 17, 2022
1 parent ddee0c1 commit 506e8c5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_cpac_version.py
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)

0 comments on commit 506e8c5

Please sign in to comment.