From 175de19f2d473d8e82959d1abfe8ea25812d76c3 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Sat, 19 May 2018 00:18:59 -0700 Subject: tests: test html output for `spack list` - make list test use SpackCommand - convert to pytest - add a test for HTML output --- lib/spack/spack/test/cmd/list.py | 99 +++++++++++++++------------------------- 1 file changed, 37 insertions(+), 62 deletions(-) diff --git a/lib/spack/spack/test/cmd/list.py b/lib/spack/spack/test/cmd/list.py index 72174c6b7b..dba6c12350 100644 --- a/lib/spack/spack/test/cmd/list.py +++ b/lib/spack/spack/test/cmd/list.py @@ -22,84 +22,59 @@ # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -import argparse - import pytest -import spack.cmd.list - - -@pytest.fixture(scope='module') -def parser(): - """Returns the parser for the module command""" - prs = argparse.ArgumentParser() - spack.cmd.list.setup_parser(prs) - return prs - - -@pytest.fixture() -def pkg_names(): - pkg_names = [] - return pkg_names - -@pytest.fixture() -def mock_name_only(monkeypatch, pkg_names): +from spack.main import SpackCommand - def name_only(x): - pkg_names.extend(x) +list = SpackCommand('list') - monkeypatch.setattr(spack.cmd.list, 'name_only', name_only) - monkeypatch.setitem(spack.cmd.list.formatters, 'name_only', name_only) +def test_list(): + output = list() + assert 'cloverleaf3d' in output + assert 'hdf5' in output -@pytest.mark.usefixtures('mock_name_only') -class TestListCommand(object): - def test_list(self, parser, pkg_names): +def test_list_filter(): + output = list('py-*') + assert 'py-numpy' in output + assert 'perl-file-copy-recursive' not in output - args = parser.parse_args([]) - spack.cmd.list.list(parser, args) + output = list('py-') + assert 'py-numpy' in output + assert 'perl-file-copy-recursive' in output - assert pkg_names - assert 'cloverleaf3d' in pkg_names - assert 'hdf5' in pkg_names - def test_list_filter(self, parser, pkg_names): - args = parser.parse_args(['py-*']) - spack.cmd.list.list(parser, args) +@pytest.mark.maybeslow +def test_list_search_description(): + output = list('--search-description', 'xml') + assert 'expat' in output - assert pkg_names - assert 'py-numpy' in pkg_names - assert 'perl-file-copy-recursive' not in pkg_names - args = parser.parse_args(['py-']) - spack.cmd.list.list(parser, args) +def test_list_tags(): + output = list('--tags', 'proxy-app') + assert 'cloverleaf3d' in output + assert 'hdf5' not in output - assert pkg_names - assert 'py-numpy' in pkg_names - assert 'perl-file-copy-recursive' in pkg_names - @pytest.mark.maybeslow - def test_list_search_description(self, parser, pkg_names): - args = parser.parse_args(['--search-description', 'xml']) - spack.cmd.list.list(parser, args) +def test_list_format_name_only(): + output = list('--format', 'name_only') + assert 'cloverleaf3d' in output + assert 'hdf5' in output - assert pkg_names - assert 'expat' in pkg_names - def test_list_tags(self, parser, pkg_names): - args = parser.parse_args(['--tags', 'proxy-app']) - spack.cmd.list.list(parser, args) +@pytest.mark.maybeslow +def test_list_format_rst(): + output = list('--format', 'rst') + assert '.. _cloverleaf3d:' in output + assert '.. _hdf5:' in output - assert pkg_names - assert 'cloverleaf3d' in pkg_names - assert 'hdf5' not in pkg_names - @pytest.mark.maybeslow - def test_list_formatter(self, parser, pkg_names): - # TODO: Test the output of the commands - args = parser.parse_args(['--format', 'name_only']) - spack.cmd.list.list(parser, args) +@pytest.mark.maybeslow +def test_list_format_html(): + output = list('--format', 'html') + assert '
' in output + assert '

cloverleaf3d' in output - args = parser.parse_args(['--format', 'rst']) - spack.cmd.list.list(parser, args) + assert '
' in output + assert '

hdf5' in output -- cgit v1.2.3-70-g09d2