Source code for tests.test_manager_ips
# Copyright Kevin Deldycke <[email protected]> and contributors.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""IPS exact-match tests.
They replay what IPS printed on OpenIndiana Hipster, so they need neither IPS nor
an illumos host.
"""
from __future__ import annotations
from meta_package_manager.managers.ips import IPS
INSTALLED_OUTPUT = """\
SUNWcs 0.5.11-2026.0.0.23029 i--
SUNWcsd 0.5.11-2026.0.0.23029 i--
archiver/gnu-tar 1.35-2023.0.0.0 i--
audio/audio-utilities 0.5.11-2026.0.0.23029 i--
audio/lame 3.100-2025.0.0.3 i--
"""
"""Five rows of `pkg list -H --no-refresh`."""
SEARCH_OUTPUT = (
"pkg:/[email protected]\topenindiana.org\n"
"pkg:/archiver/[email protected]\topenindiana.org\n"
"pkg:/archiver/[email protected]\topenindiana.org\n"
"pkg:/developer/[email protected]\topenindiana.org\n"
"pkg:/library/perl-5/[email protected]\topenindiana.org\n"
)
"""`pkg search -H -p tar`, whose columns are tab-separated."""
[docs]
def replaying(monkeypatch, output: str) -> IPS:
"""A manager whose every command prints `output`."""
manager = IPS()
monkeypatch.setattr(manager, "run_cli", lambda *args, **kwargs: output)
return manager
[docs]
def test_installed_rows_carry_the_bare_name(monkeypatch):
"""Each name is split into its path and its last component."""
manager = replaying(monkeypatch, INSTALLED_OUTPUT)
packages = list(manager.installed)
assert [(p.id, p.name) for p in packages] == [
("SUNWcs", "SUNWcs"),
("SUNWcsd", "SUNWcsd"),
("archiver/gnu-tar", "gnu-tar"),
("audio/audio-utilities", "audio-utilities"),
("audio/lame", "lame"),
]
assert [p.id for p in packages if p.matches("gnu-tar", exact=True)] == [
"archiver/gnu-tar"
]
[docs]
def test_exact_search_matches_the_bare_name(monkeypatch):
"""An exact query names the package without the path of its name."""
manager = replaying(monkeypatch, SEARCH_OUTPUT)
results = manager.refiltered_search("archive-tar", extended=False, exact=True)
assert [package.id for package in results] == ["library/perl-5/archive-tar"]