Fix TypeError raised when _enc called with None (RhBug:1003220)
This commit is contained in:
parent
bd9b57606f
commit
7bdc9e170d
|
@ -834,6 +834,8 @@ class YumOutput:
|
|||
def _enc(self, s):
|
||||
"""Get the translated version from specspo and ensure that
|
||||
it's actually encoded in UTF-8."""
|
||||
if s is None:
|
||||
s = ''
|
||||
s = to_utf8(s)
|
||||
if len(s) > 0:
|
||||
for d in self.i18ndomains:
|
||||
|
|
|
@ -25,7 +25,22 @@ import optparse
|
|||
import os
|
||||
import unittest
|
||||
|
||||
OUTPUT="""\
|
||||
INFOOUTPUT_OUTPUT="""\
|
||||
Name : tour
|
||||
Arch : noarch
|
||||
Epoch : 0
|
||||
Version : 5
|
||||
Release : 0
|
||||
Size : 0.0
|
||||
Repo : None
|
||||
Summary : A summary of the package.
|
||||
URL : http://example.com
|
||||
License : GPL+
|
||||
Description :
|
||||
|
||||
"""
|
||||
|
||||
VERSIONS_OUTPUT="""\
|
||||
Installed: pepper-0:20-0.x86_64 at 1970-01-01 00:00
|
||||
Built : at 1970-01-01 00:00
|
||||
|
||||
|
@ -41,7 +56,30 @@ class VersionStringTest(unittest.TestCase):
|
|||
dnf.cli.cli.print_versions(['pepper', 'tour'], yumbase)
|
||||
written = ''.join([mc[1][0] for mc in stdout.method_calls
|
||||
if mc[0] == 'write'])
|
||||
self.assertEqual(written, OUTPUT)
|
||||
self.assertEqual(written, VERSIONS_OUTPUT)
|
||||
|
||||
class YumBaseCliTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.yumbase = dnf.cli.cli.YumBaseCli()
|
||||
self.pkg = support.MockPackage('tour-5-0.noarch')
|
||||
self.pkg.from_system = False
|
||||
self.pkg.size = 0
|
||||
self.pkg.pkgid = None
|
||||
self.pkg.repoid = None
|
||||
self.pkg.e = self.pkg.epoch
|
||||
self.pkg.v = self.pkg.version
|
||||
self.pkg.r = self.pkg.release
|
||||
self.pkg.summary = 'A summary of the package.'
|
||||
self.pkg.url = 'http://example.com'
|
||||
self.pkg.license = 'GPL+'
|
||||
self.pkg.description = None
|
||||
|
||||
def test_infoOutput_with_none_description(self):
|
||||
with mock.patch('sys.stdout') as stdout:
|
||||
self.yumbase.infoOutput(self.pkg)
|
||||
written = ''.join([mc[1][0] for mc in stdout.method_calls
|
||||
if mc[0] == 'write'])
|
||||
self.assertEqual(written, INFOOUTPUT_OUTPUT)
|
||||
|
||||
class CliTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue