Skip to content
Snippets Groups Projects
Commit 175de19f authored by Todd Gamblin's avatar Todd Gamblin
Browse files

tests: test html output for `spack list`

- make list test use SpackCommand
- convert to pytest
- add a test for HTML output
parent f476e60c
No related branches found
No related tags found
No related merge requests found
...@@ -22,84 +22,59 @@ ...@@ -22,84 +22,59 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
import argparse
import pytest 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() from spack.main import SpackCommand
def mock_name_only(monkeypatch, pkg_names):
def name_only(x): list = SpackCommand('list')
pkg_names.extend(x)
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([]) output = list('py-')
spack.cmd.list.list(parser, args) 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): @pytest.mark.maybeslow
args = parser.parse_args(['py-*']) def test_list_search_description():
spack.cmd.list.list(parser, args) 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-']) def test_list_tags():
spack.cmd.list.list(parser, args) 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_format_name_only():
def test_list_search_description(self, parser, pkg_names): output = list('--format', 'name_only')
args = parser.parse_args(['--search-description', 'xml']) assert 'cloverleaf3d' in output
spack.cmd.list.list(parser, args) assert 'hdf5' in output
assert pkg_names
assert 'expat' in pkg_names
def test_list_tags(self, parser, pkg_names): @pytest.mark.maybeslow
args = parser.parse_args(['--tags', 'proxy-app']) def test_list_format_rst():
spack.cmd.list.list(parser, args) 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 @pytest.mark.maybeslow
def test_list_formatter(self, parser, pkg_names): def test_list_format_html():
# TODO: Test the output of the commands output = list('--format', 'html')
args = parser.parse_args(['--format', 'name_only']) assert '<div class="section" id="cloverleaf3d">' in output
spack.cmd.list.list(parser, args) assert '<h1>cloverleaf3d' in output
args = parser.parse_args(['--format', 'rst']) assert '<div class="section" id="hdf5">' in output
spack.cmd.list.list(parser, args) assert '<h1>hdf5' in output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment