Source code for ramble.test.cmd.list

# Copyright 2022-2026 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import deprecation
import pytest

from ramble.main import RambleCommand

pytestmark = pytest.mark.usefixtures("mutable_config")

list = RambleCommand("list")


[docs] def test_list(): output = list() assert "hostname" in output
[docs] def test_list_filter(): output = list("host*") assert "hostname" in output
[docs] @pytest.mark.maybeslow def test_list_search_description(): output = list("--search-description", "example") assert "hostname" in output
[docs] def test_list_tags(): output = list("--tags", "test-app") assert "hostname" in output
[docs] def test_list_format_name_only(): output = list("--format", "name_only") assert "hostname" in output
[docs] def test_list_format_json(): import builtins import json output = list("--format", "json") data = json.loads(output) assert isinstance(data, builtins.list) assert {"name": "hostname"} in data base_output = list("--type", "base_classes", "--format", "json") base_data = json.loads(base_output) assert isinstance(base_data, builtins.list) assert {"name": "application-base"} in base_data
[docs] @deprecation.fail_if_not_removed def test_list_format_version_json(deprecated_call): import json with deprecated_call(): output = list("--format", "version_json") assert json.loads(output) == json.loads(list("--format", "json"))
[docs] @pytest.mark.maybeslow def test_list_format_html(): output = list("--format", "html") assert '<div class="section" id="gromacs">' in output assert "<dt>Workloads:</dt>" in output assert "<details>" in output assert "<summary>lignocellulose</summary>" in output assert "<dt>Executables:</dt>" in output assert "execute" in output assert "<dt>Variables:</dt>" in output assert "<dt>mdrun</dt>" in output # Assert on input_file descriptions assert "<dt>lignocellulose</dt>" in output assert "A model of cellulose and lignocellulosic biomass in an aqueous solution" in output assert "</details>" in output
[docs] @pytest.mark.maybeslow def test_list_base_html(): output = list("--type", "base_applications", "--format", "html") assert '<div class="section" id="hpl">' in output
[docs] @pytest.mark.parametrize( "type_arg", [ "applications", "application", "app", "base_applications", "base_application", "base-application", "modifiers", "modifier", "package_managers", "package_manager", "package-manager", "workflow_managers", "workflow_manager", ], ) def test_list_types(type_arg): output = list("--type", type_arg) assert output is not None assert len(output) > 0
[docs] def test_list_update(tmpdir): update_file = tmpdir.join("output") # not yet created when list is run list("--update", str(update_file)) assert update_file.exists() with update_file.open() as f: assert f.read() # created but older than any package with update_file.open("w") as f: f.write("empty\n") update_file.setmtime(0) list("--update", str(update_file)) assert update_file.exists() with update_file.open() as f: assert f.read() != "empty\n" # newer than any packages with update_file.open("w") as f: f.write("empty\n") list("--update", str(update_file)) assert update_file.exists() with update_file.open() as f: assert f.read() == "empty\n"
[docs] def test_list_update_empty_results(tmpdir): update_file = tmpdir.join("empty_output.html") list("--type", "base_package_managers", "--format", "html", "--update", str(update_file)) assert update_file.exists() with update_file.open() as f: content = f.read() assert "0 mainline base_package_managers" in content
[docs] def test_list_no_results_warning(): out = list("nonexistent_app_name_xyz") assert list.returncode == 0 assert "No applications found matching filter 'nonexistent_app_name_xyz'" in out out = list("--tags", "nonexistent_tag_xyz") assert list.returncode == 0 assert "No applications found matching tags 'nonexistent_tag_xyz'" in out out = list("--type", "modifiers", "nonexistent_mod_xyz") assert list.returncode == 0 assert "No modifiers found matching filter 'nonexistent_mod_xyz'" in out out = list("--tags", "nonexistent_tag", "nonexistent_app") assert list.returncode == 0 assert ( "No applications found matching filter 'nonexistent_app' and tags 'nonexistent_tag'" in out )