|
Packit |
6f3914 |
# -*- coding: utf-8 -*-
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# Copyright (C) 2014-2018 Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit |
6f3914 |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit |
6f3914 |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit |
6f3914 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
6f3914 |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit |
6f3914 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit |
6f3914 |
# Public License for more details. You should have received a copy of the
|
|
Packit |
6f3914 |
# GNU General Public License along with this program; if not, write to the
|
|
Packit |
6f3914 |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit |
6f3914 |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit |
6f3914 |
# source code or documentation are not subject to the GNU General Public
|
|
Packit |
6f3914 |
# License and may only be used or replicated with the express permission of
|
|
Packit |
6f3914 |
# Red Hat, Inc.
|
|
Packit |
6f3914 |
#
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
from __future__ import absolute_import
|
|
Packit |
6f3914 |
from __future__ import print_function
|
|
Packit |
6f3914 |
from __future__ import unicode_literals
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import dnf.cli.commands.repoquery
|
|
Packit |
6f3914 |
import dnf.exceptions
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import tests.support
|
|
Packit |
6f3914 |
from tests.support import mock
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
EXPECTED_INFO_FORMAT = """\
|
|
Packit |
6f3914 |
Name : foobar
|
|
Packit |
6f3914 |
Version : 1.0.1
|
|
Packit |
6f3914 |
Release : 1.f20
|
|
Packit |
6f3914 |
Architecture: x86_64
|
|
Packit |
6f3914 |
Size : 100
|
|
Packit |
6f3914 |
License : BSD
|
|
Packit |
6f3914 |
Source RPM : foo-1.0.1-1.f20.src.rpm
|
|
Packit |
6f3914 |
Build Date : 1970-01-01 00:02
|
|
Packit |
6f3914 |
Packager : Eastford
|
|
Packit |
6f3914 |
URL : foorl.net
|
|
Packit |
6f3914 |
Summary : it.
|
|
Packit |
6f3914 |
Description :
|
|
Packit |
6f3914 |
A desc.A desc.A desc.A desc.A desc.A desc.A desc.A desc.\n"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
EXPECTED_FILELIST_FORMAT = """\
|
|
Packit |
6f3914 |
/tmp/foobar
|
|
Packit |
6f3914 |
/var/foobar\
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
EXPECTED_SOURCERPM_FORMAT = """\
|
|
Packit |
6f3914 |
foo-1.0.1-1.f20.src.rpm"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class PkgStub(object):
|
|
Packit |
6f3914 |
def __init__(self):
|
|
Packit |
6f3914 |
self.arch = 'x86_64'
|
|
Packit |
6f3914 |
self.buildtime = 120
|
|
Packit |
6f3914 |
self.description = 'A desc.' * 8
|
|
Packit |
6f3914 |
self.license = 'BSD'
|
|
Packit |
6f3914 |
self.name = 'foobar'
|
|
Packit |
6f3914 |
self.packager = 'Eastford'
|
|
Packit |
6f3914 |
self.release = '1.f20'
|
|
Packit |
6f3914 |
self.reponame = '@System'
|
|
Packit |
6f3914 |
self._size = 100
|
|
Packit |
6f3914 |
self.sourcerpm = 'foo-1.0.1-1.f20.src.rpm'
|
|
Packit |
6f3914 |
self.summary = 'it.'
|
|
Packit |
6f3914 |
self.url = 'foorl.net'
|
|
Packit |
6f3914 |
self.version = '1.0.1'
|
|
Packit |
6f3914 |
self.files = ['/tmp/foobar', '/var/foobar']
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class ArgParseTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def setUp(self):
|
|
Packit |
6f3914 |
self.cmd = dnf.cli.commands.repoquery.RepoQueryCommand(
|
|
Packit |
6f3914 |
tests.support.CliStub(tests.support.BaseCliStub()))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_parse(self):
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['--whatrequires', 'prudence'])
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.opts.whatprovides, [])
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.opts.whatrequires, ['prudence'])
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.opts.queryformat,
|
|
Packit |
6f3914 |
dnf.cli.commands.repoquery.QFORMAT_DEFAULT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('argparse.ArgumentParser.print_help', lambda x: x)
|
|
Packit |
6f3914 |
def test_conflict(self):
|
|
Packit |
6f3914 |
with self.assertRaises(SystemExit) as sysexit, \
|
|
Packit |
6f3914 |
tests.support.patch_std_streams() as (stdout, stderr):
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['--conflicts', '%{name}', '--provides'])
|
|
Packit |
6f3914 |
self.assertEqual(sysexit.exception.code, 1)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_options(self):
|
|
Packit |
6f3914 |
for arg in ('conflicts', 'enhances', 'provides',
|
|
Packit |
6f3914 |
'recommends', 'requires', 'suggests', 'supplements'):
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['--' + arg])
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.opts.packageatr, arg)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_file(self):
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['/var/foobar'])
|
|
Packit |
6f3914 |
self.assertIsNone(self.cmd.opts.file)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class FilelistFormatTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def test_filelist(self):
|
|
Packit |
6f3914 |
self.cmd = dnf.cli.commands.repoquery.RepoQueryCommand(
|
|
Packit |
6f3914 |
tests.support.CliStub(tests.support.BaseCliStub()))
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['-l'])
|
|
Packit |
6f3914 |
pkg = dnf.cli.commands.repoquery.PackageWrapper(PkgStub())
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.build_format_fn(self.cmd.opts, pkg),
|
|
Packit |
6f3914 |
EXPECTED_FILELIST_FORMAT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class SourceRPMFormatTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def test_info(self):
|
|
Packit |
6f3914 |
self.cmd = dnf.cli.commands.repoquery.RepoQueryCommand(
|
|
Packit |
6f3914 |
tests.support.CliStub(tests.support.BaseCliStub()))
|
|
Packit |
6f3914 |
tests.support.command_configure(self.cmd, ['--source'])
|
|
Packit |
6f3914 |
pkg = dnf.cli.commands.repoquery.PackageWrapper(PkgStub())
|
|
Packit |
6f3914 |
self.assertEqual(self.cmd.build_format_fn(self.cmd.opts, pkg),
|
|
Packit |
6f3914 |
EXPECTED_SOURCERPM_FORMAT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class OutputTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def test_output(self):
|
|
Packit |
6f3914 |
pkg = PkgStub()
|
|
Packit |
6f3914 |
fmt = dnf.cli.commands.repoquery.rpm2py_format(
|
|
Packit |
6f3914 |
'%{name}-%{version}-%{release}.%{arch} (%{reponame})')
|
|
Packit |
6f3914 |
self.assertEqual(fmt.format(pkg), 'foobar-1.0.1-1.f20.x86_64 (@System)')
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_illegal_attr(self):
|
|
Packit |
6f3914 |
pkg = PkgStub()
|
|
Packit |
6f3914 |
with self.assertRaises(AttributeError) as ctx:
|
|
Packit |
6f3914 |
dnf.cli.commands.repoquery.rpm2py_format('%{notfound}').format(pkg)
|
|
Packit |
6f3914 |
self.assertEqual(str(ctx.exception),
|
|
Packit |
6f3914 |
"'PkgStub' object has no attribute 'notfound'")
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class Rpm2PyFormatTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def test_rpm2py_format(self):
|
|
Packit |
6f3914 |
fmt = dnf.cli.commands.repoquery.rpm2py_format('%{name}')
|
|
Packit |
6f3914 |
self.assertEqual(fmt, '{0.name}')
|
|
Packit |
6f3914 |
fmt = dnf.cli.commands.repoquery.rpm2py_format('%40{name}')
|
|
Packit |
6f3914 |
self.assertEqual(fmt, '{0.name:<40}')
|
|
Packit |
6f3914 |
fmt = dnf.cli.commands.repoquery.rpm2py_format('%-40{name}')
|
|
Packit |
6f3914 |
self.assertEqual(fmt, '{0.name:>40}')
|
|
Packit |
6f3914 |
fmt = dnf.cli.commands.repoquery.rpm2py_format(
|
|
Packit |
6f3914 |
'%{name}-%{repoid} :: %-40{arch}')
|
|
Packit |
6f3914 |
self.assertEqual(fmt, '{0.name}-{0.repoid} :: {0.arch:>40}')
|