|
Packit |
6f3914 |
# -*- coding: utf-8 -*-
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# Copyright (C) 2012-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 unicode_literals
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import libdnf.transaction
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import dnf.cli.output
|
|
Packit |
6f3914 |
import dnf.const
|
|
Packit |
6f3914 |
import dnf.transaction
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
import tests.support
|
|
Packit |
6f3914 |
from tests.support import mock
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
INFOOUTPUT_OUTPUT = """\
|
|
Packit |
6f3914 |
Name : tour
|
|
Packit |
6f3914 |
Epoch : 1
|
|
Packit |
6f3914 |
Version : 5
|
|
Packit |
6f3914 |
Release : 0
|
|
Packit |
6f3914 |
Architecture : noarch
|
|
Packit |
6f3914 |
Size : 0.0
|
|
Packit |
6f3914 |
Source : tour.src.rpm
|
|
Packit |
6f3914 |
Repository : None
|
|
Packit |
6f3914 |
Summary : A summary of the package.
|
|
Packit |
6f3914 |
URL : http://example.com
|
|
Packit |
6f3914 |
License : GPL+
|
|
Packit |
6f3914 |
Description :
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
LIST_TRANSACTION_OUTPUT = u"""\
|
|
Packit |
6f3914 |
================================================================================
|
|
Packit |
6f3914 |
Package Arch Version Repository Size
|
|
Packit |
6f3914 |
================================================================================
|
|
Packit |
6f3914 |
Upgrading:
|
|
Packit |
6f3914 |
pepper x86_64 20-1 updates 0
|
|
Packit |
6f3914 |
replacing hole.x86_64 1-1
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
Transaction Summary
|
|
Packit |
6f3914 |
================================================================================
|
|
Packit |
6f3914 |
Upgrade 1 Package
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class OutputFunctionsTest(tests.support.TestCase):
|
|
Packit |
6f3914 |
def test_make_lists(self):
|
|
Packit |
6f3914 |
return
|
|
Packit |
6f3914 |
goal = mock.Mock(get_reason=lambda x: libdnf.transaction.TransactionItemReason_USER)
|
|
Packit |
6f3914 |
ts = dnf.transaction.Transaction()
|
|
Packit |
6f3914 |
# ts = dnf.db.history.
|
|
Packit |
6f3914 |
ts.add_install('pepper-3', [])
|
|
Packit |
6f3914 |
ts.add_install('pepper-2', [])
|
|
Packit |
6f3914 |
lists = dnf.cli.output._make_lists(ts, goal)
|
|
Packit |
6f3914 |
self.assertEmpty(lists.erased)
|
|
Packit |
6f3914 |
self.assertEqual([tsi._active for tsi in lists.installed],
|
|
Packit |
6f3914 |
['pepper-2', 'pepper-3'])
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_spread(self):
|
|
Packit |
6f3914 |
fun = dnf.cli.output._spread_in_columns
|
|
Packit |
6f3914 |
self.assertEqual(fun(3, "tour", list(range(3))),
|
|
Packit |
6f3914 |
[('tour', 0, 1), ('', 2, '')])
|
|
Packit |
6f3914 |
self.assertEqual(fun(3, "tour", ()), [('tour', '', '')])
|
|
Packit |
6f3914 |
self.assertEqual(fun(5, "tour", list(range(8))),
|
|
Packit |
6f3914 |
[('tour', 0, 1, 2, 3), ('', 4, 5, 6, 7)])
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class OutputTest(tests.support.DnfBaseTestCase):
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
REPOS = ['updates']
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@staticmethod
|
|
Packit |
6f3914 |
def _keyboard_interrupt(*ignored):
|
|
Packit |
6f3914 |
raise KeyboardInterrupt
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@staticmethod
|
|
Packit |
6f3914 |
def _eof_error(*ignored):
|
|
Packit |
6f3914 |
raise EOFError
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def setUp(self):
|
|
Packit |
6f3914 |
super(OutputTest, self).setUp()
|
|
Packit |
6f3914 |
self.output = dnf.cli.output.Output(self.base, self.base.conf)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_col_widths(self, _real_term_width):
|
|
Packit |
6f3914 |
rows = (('pep', 'per', 'row',
|
|
Packit |
6f3914 |
'', 'lon', 'e'))
|
|
Packit |
6f3914 |
self.assertCountEqual(self.output._col_widths(rows), (-38, -37, -1))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output.P_', dnf.pycomp.NullTranslations().ungettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_list_transaction(self, _real_term_width):
|
|
Packit |
6f3914 |
return
|
|
Packit |
6f3914 |
sack = self.base.sack
|
|
Packit |
6f3914 |
q = sack.query().filter(name='pepper')
|
|
Packit |
6f3914 |
i = q.installed()[0]
|
|
Packit |
6f3914 |
u = q.available()[0]
|
|
Packit |
6f3914 |
obs = sack.query().filter(name='hole').installed()[0]
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
transaction = dnf.transaction.Transaction()
|
|
Packit |
6f3914 |
transaction.add_upgrade(u, i, [obs])
|
|
Packit |
6f3914 |
self.assertEqual(self.output.list_transaction(transaction),
|
|
Packit |
6f3914 |
LIST_TRANSACTION_OUTPUT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.i18n.ucd_input')
|
|
Packit |
6f3914 |
def test_userconfirm(self, input_fnc):
|
|
Packit |
6f3914 |
# with defaultyes==False
|
|
Packit |
6f3914 |
input_fnc.return_value = 'y'
|
|
Packit |
6f3914 |
self.assertTrue(self.output.userconfirm())
|
|
Packit |
6f3914 |
self.assertEqual(input_fnc.call_args, mock.call(u'Is this ok [y/N]: '))
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.return_value = 'n'
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.return_value = ''
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.side_effect = self._keyboard_interrupt
|
|
Packit |
6f3914 |
input_fnc.return_value = 'y'
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.side_effect = self._eof_error
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
# with defaultyes==True
|
|
Packit |
6f3914 |
self.output.conf.defaultyes = True
|
|
Packit |
6f3914 |
input_fnc.side_effect = None
|
|
Packit |
6f3914 |
input_fnc.return_value = ''
|
|
Packit |
6f3914 |
self.assertTrue(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.side_effect = self._keyboard_interrupt
|
|
Packit |
6f3914 |
input_fnc.return_value = ''
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.side_effect = self._eof_error
|
|
Packit |
6f3914 |
self.assertTrue(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def _to_unicode_mock(str):
|
|
Packit |
6f3914 |
return {'y': 'a', 'yes': 'ano', 'n': 'e', 'no': 'ee'}.get(str, str)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', _to_unicode_mock)
|
|
Packit |
6f3914 |
@mock.patch('dnf.i18n.ucd_input')
|
|
Packit |
6f3914 |
def test_userconfirm_translated(self, input_fnc):
|
|
Packit |
6f3914 |
input_fnc.return_value = 'ee'
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
input_fnc.return_value = 'ano'
|
|
Packit |
6f3914 |
self.assertTrue(self.output.userconfirm())
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class _InputGenerator(object):
|
|
Packit |
6f3914 |
INPUT = ['haha', 'dada', 'n']
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def __init__(self):
|
|
Packit |
6f3914 |
self.called = 0
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def __call__(self, msg):
|
|
Packit |
6f3914 |
ret = self.INPUT[self.called]
|
|
Packit |
6f3914 |
self.called += 1
|
|
Packit |
6f3914 |
return ret
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def test_userconfirm_bad_input(self):
|
|
Packit |
6f3914 |
input_fnc = self._InputGenerator()
|
|
Packit |
6f3914 |
with mock.patch('dnf.i18n.ucd_input', input_fnc):
|
|
Packit |
6f3914 |
self.assertFalse(self.output.userconfirm())
|
|
Packit |
6f3914 |
self.assertEqual(input_fnc.called, 3)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_infoOutput_with_none_description(self, _real_term_width):
|
|
Packit |
6f3914 |
pkg = tests.support.MockPackage('tour-5-0.noarch')
|
|
Packit |
6f3914 |
pkg._from_system = False
|
|
Packit |
6f3914 |
pkg._size = 0
|
|
Packit |
6f3914 |
pkg._pkgid = None
|
|
Packit |
6f3914 |
pkg.repoid = None
|
|
Packit |
6f3914 |
pkg.e = pkg.epoch = 1
|
|
Packit |
6f3914 |
pkg.v = pkg.version
|
|
Packit |
6f3914 |
pkg.r = pkg.release
|
|
Packit |
6f3914 |
pkg.sourcerpm = 'tour.src.rpm'
|
|
Packit |
6f3914 |
pkg.summary = 'A summary of the package.'
|
|
Packit |
6f3914 |
pkg.url = 'http://example.com'
|
|
Packit |
6f3914 |
pkg.license = 'GPL+'
|
|
Packit |
6f3914 |
pkg.description = None
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
with mock.patch('sys.stdout') as stdout:
|
|
Packit |
6f3914 |
print(self.output.infoOutput(pkg))
|
|
Packit |
6f3914 |
written = ''.join([mc[1][0] for mc in stdout.method_calls
|
|
Packit |
6f3914 |
if mc[0] == 'write'])
|
|
Packit |
6f3914 |
self.assertEqual(written, INFOOUTPUT_OUTPUT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
PKGS_IN_GROUPS_OUTPUT = u"""\
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
Group: Pepper's
|
|
Packit |
6f3914 |
Mandatory Packages:
|
|
Packit |
6f3914 |
hole
|
|
Packit |
6f3914 |
lotus
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
PKGS_IN_GROUPS_VERBOSE_OUTPUT = u"""\
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
Group: Pepper's
|
|
Packit |
6f3914 |
Group-Id: Peppers
|
|
Packit |
6f3914 |
Mandatory Packages:
|
|
Packit |
6f3914 |
hole-1-1.x86_64 @System
|
|
Packit |
6f3914 |
lotus-3-16.i686 main
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
GROUPS_IN_ENVIRONMENT_OUTPUT = """\
|
|
Packit |
6f3914 |
Environment Group: Sugar Desktop Environment
|
|
Packit |
6f3914 |
Description: A software playground for learning about learning.
|
|
Packit |
6f3914 |
Mandatory Groups:
|
|
Packit |
6f3914 |
Pepper's
|
|
Packit |
6f3914 |
Solid Ground
|
|
Packit |
6f3914 |
Optional Groups:
|
|
Packit |
6f3914 |
Base
|
|
Packit |
6f3914 |
"""
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
class GroupOutputTest(tests.support.DnfBaseTestCase):
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
REPOS = ['main']
|
|
Packit |
6f3914 |
COMPS = True
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
def setUp(self):
|
|
Packit |
6f3914 |
super(GroupOutputTest, self).setUp()
|
|
Packit |
6f3914 |
self.output = dnf.cli.output.Output(self.base, self.base.conf)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_group_info(self, _real_term_width):
|
|
Packit |
6f3914 |
group = self.base.comps.group_by_pattern('Peppers')
|
|
Packit |
6f3914 |
with tests.support.patch_std_streams() as (stdout, stderr):
|
|
Packit |
6f3914 |
self.output.display_pkgs_in_groups(group)
|
|
Packit |
6f3914 |
self.assertEqual(stdout.getvalue(), PKGS_IN_GROUPS_OUTPUT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_group_verbose_info(self, _real_term_width):
|
|
Packit |
6f3914 |
group = self.base.comps.group_by_pattern('Peppers')
|
|
Packit |
6f3914 |
self.base.set_debuglevel(dnf.const.VERBOSE_LEVEL)
|
|
Packit |
6f3914 |
with tests.support.patch_std_streams() as (stdout, stderr):
|
|
Packit |
6f3914 |
self.output.display_pkgs_in_groups(group)
|
|
Packit |
6f3914 |
self.assertEqual(stdout.getvalue(), PKGS_IN_GROUPS_VERBOSE_OUTPUT)
|
|
Packit |
6f3914 |
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.output._', dnf.pycomp.NullTranslations().ugettext)
|
|
Packit |
6f3914 |
@mock.patch('dnf.cli.term._real_term_width', return_value=80)
|
|
Packit |
6f3914 |
def test_environment_info(self, _real_term_width):
|
|
Packit |
6f3914 |
env = self.base.comps.environments[0]
|
|
Packit |
6f3914 |
with tests.support.patch_std_streams() as (stdout, stderr):
|
|
Packit |
6f3914 |
self.output.display_groups_in_environment(env)
|
|
Packit |
6f3914 |
self.assertEqual(stdout.getvalue(), GROUPS_IN_ENVIRONMENT_OUTPUT)
|