Simplify fixture used to test spack info
(#30456)
This commit is contained in:
parent
bdef031d4e
commit
a5e92893d3
@ -26,18 +26,14 @@ def parser():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def info_lines():
|
def print_buffer(monkeypatch):
|
||||||
lines = []
|
buffer = []
|
||||||
return lines
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def mock_print(monkeypatch, info_lines):
|
|
||||||
|
|
||||||
def _print(*args):
|
def _print(*args):
|
||||||
info_lines.extend(args)
|
buffer.extend(args)
|
||||||
|
|
||||||
monkeypatch.setattr(spack.cmd.info.color, 'cprint', _print, raising=False)
|
monkeypatch.setattr(spack.cmd.info.color, 'cprint', _print, raising=False)
|
||||||
|
return buffer
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('pkg', [
|
@pytest.mark.parametrize('pkg', [
|
||||||
@ -52,11 +48,11 @@ def test_it_just_runs(pkg):
|
|||||||
info(pkg)
|
info(pkg)
|
||||||
|
|
||||||
|
|
||||||
def test_info_noversion(mock_packages, info_lines, mock_print):
|
def test_info_noversion(mock_packages, print_buffer):
|
||||||
"""Check that a mock package with no versions or variants outputs None."""
|
"""Check that a mock package with no versions or variants outputs None."""
|
||||||
info('noversion')
|
info('noversion')
|
||||||
|
|
||||||
line_iter = info_lines.__iter__()
|
line_iter = iter(print_buffer)
|
||||||
for line in line_iter:
|
for line in line_iter:
|
||||||
if 'version' in line:
|
if 'version' in line:
|
||||||
has = [desc in line for desc in ['Preferred', 'Safe', 'Deprecated']]
|
has = [desc in line for desc in ['Preferred', 'Safe', 'Deprecated']]
|
||||||
@ -72,12 +68,11 @@ def test_info_noversion(mock_packages, info_lines, mock_print):
|
|||||||
('zlib', 'False'),
|
('zlib', 'False'),
|
||||||
('gcc', 'True (version, variants)'),
|
('gcc', 'True (version, variants)'),
|
||||||
])
|
])
|
||||||
@pytest.mark.usefixtures('mock_print')
|
def test_is_externally_detectable(pkg_query, expected, parser, print_buffer):
|
||||||
def test_is_externally_detectable(pkg_query, expected, parser, info_lines):
|
|
||||||
args = parser.parse_args(['--detectable', pkg_query])
|
args = parser.parse_args(['--detectable', pkg_query])
|
||||||
spack.cmd.info.info(parser, args)
|
spack.cmd.info.info(parser, args)
|
||||||
|
|
||||||
line_iter = info_lines.__iter__()
|
line_iter = iter(print_buffer)
|
||||||
for line in line_iter:
|
for line in line_iter:
|
||||||
if 'Externally Detectable' in line:
|
if 'Externally Detectable' in line:
|
||||||
is_externally_detectable = next(line_iter).strip()
|
is_externally_detectable = next(line_iter).strip()
|
||||||
@ -90,9 +85,7 @@ def test_is_externally_detectable(pkg_query, expected, parser, info_lines):
|
|||||||
'trilinos',
|
'trilinos',
|
||||||
'gcc' # This should ensure --test's c_names processing loop covered
|
'gcc' # This should ensure --test's c_names processing loop covered
|
||||||
])
|
])
|
||||||
@pytest.mark.usefixtures('mock_print')
|
def test_info_fields(pkg_query, parser, print_buffer):
|
||||||
def test_info_fields(pkg_query, parser, info_lines):
|
|
||||||
|
|
||||||
expected_fields = (
|
expected_fields = (
|
||||||
'Description:',
|
'Description:',
|
||||||
'Homepage:',
|
'Homepage:',
|
||||||
@ -108,5 +101,4 @@ def test_info_fields(pkg_query, parser, info_lines):
|
|||||||
spack.cmd.info.info(parser, args)
|
spack.cmd.info.info(parser, args)
|
||||||
|
|
||||||
for text in expected_fields:
|
for text in expected_fields:
|
||||||
match = [x for x in info_lines if text in x]
|
assert any(x for x in print_buffer if text in x)
|
||||||
assert match
|
|
||||||
|
Loading…
Reference in New Issue
Block a user