forked from packaging/fedpkg
Drop all usage of six
We no longer support Python 2, so there's no need for it. This also drops some early Python 3-era compatibility things there is no longer any need for. Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
parent
cca0ca9cee
commit
6787fe01cd
13 changed files with 137 additions and 160 deletions
|
|
@ -4,7 +4,7 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
from six.moves.configparser import ConfigParser
|
||||
from configparser import ConfigParser
|
||||
|
||||
if __name__ == '__main__':
|
||||
module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import pyrpkg
|
|||
import os
|
||||
import git
|
||||
import re
|
||||
import six
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
|
|
@ -265,7 +264,7 @@ class Commands(pyrpkg.Commands):
|
|||
"""Returns the latest commit message on the current branch"""
|
||||
|
||||
try:
|
||||
commitmsg = six.next(self.repo.iter_commits()).message
|
||||
commitmsg = next(self.repo.iter_commits()).message
|
||||
except TypeError:
|
||||
commitmsg = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -15,17 +15,12 @@ import logging
|
|||
import os
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
import fedpkg
|
||||
import fedpkg.utils
|
||||
import pyrpkg
|
||||
import pyrpkg.utils
|
||||
|
||||
if six.PY3: # SafeConfigParser == ConfigParser, former deprecated in >= 3.2
|
||||
from six.moves.configparser import ConfigParser
|
||||
else:
|
||||
from six.moves.configparser import SafeConfigParser as ConfigParser
|
||||
from configparser import ConfigParser
|
||||
|
||||
|
||||
cli_name = os.path.basename(sys.argv[0])
|
||||
|
|
|
|||
|
|
@ -26,12 +26,10 @@ try:
|
|||
import importlib.metadata
|
||||
except ImportError:
|
||||
import pkg_resources
|
||||
import six
|
||||
from pyrpkg import rpkgError
|
||||
from pyrpkg.cli import cliClient
|
||||
from six.moves import configparser
|
||||
from six.moves.configparser import NoOptionError, NoSectionError
|
||||
from six.moves.urllib_parse import urlparse
|
||||
import configparser
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from fedpkg.bugzilla import BugzillaClient
|
||||
from fedpkg.completers import (build_arches, distgit_branches, fedpkg_packages,
|
||||
|
|
@ -793,7 +791,7 @@ class fedpkgClient(cliClient):
|
|||
return {
|
||||
'staging': self.config.getboolean(section, 'staging'),
|
||||
}
|
||||
except (ValueError, NoOptionError, NoSectionError) as e:
|
||||
except (ValueError, configparser.NoOptionError, configparser.NoSectionError) as e:
|
||||
self.log.error(str(e))
|
||||
raise rpkgError('Could not get bodhi options. It seems configuration is changed. '
|
||||
'Please try to reinstall %s or consult developers to see what '
|
||||
|
|
@ -863,10 +861,9 @@ class fedpkgClient(cliClient):
|
|||
nvr = "FILL_IN_NVR_HERE"
|
||||
bodhi_args = {
|
||||
'nvr': nvr,
|
||||
'bugs': six.u(''),
|
||||
'display_name': six.u(''),
|
||||
'descr': six.u(
|
||||
'Here is where you give an explanation of your update.'),
|
||||
'bugs': '',
|
||||
'display_name': '',
|
||||
'descr': 'Here is where you give an explanation of your update.',
|
||||
'request': self.args.request,
|
||||
'autokarma': str(self.args.autokarma),
|
||||
'stable_karma': self.args.stable_karma,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ import git
|
|||
import requests
|
||||
from pyrpkg import rpkgError
|
||||
from requests.exceptions import ConnectionError
|
||||
from six.moves.configparser import NoOptionError, NoSectionError
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from configparser import NoOptionError, NoSectionError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
def query_bodhi(server_url, timeout=60):
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ dependencies = [
|
|||
"openidc-client",
|
||||
"python-bugzilla",
|
||||
"rpkg",
|
||||
"six",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
|
|
|||
|
|
@ -3,4 +3,3 @@ bodhi-client
|
|||
openidc-client
|
||||
python-bugzilla
|
||||
rpkg
|
||||
six
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@
|
|||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import six
|
||||
|
||||
from fedpkg.bugzilla import BugzillaClient
|
||||
from pyrpkg import rpkgError
|
||||
from utils import unittest
|
||||
|
|
@ -60,8 +58,8 @@ class TestGetReviewBug(unittest.TestCase):
|
|||
Bugzilla.return_value.getbug.side_effect = ValueError
|
||||
|
||||
bzc = BugzillaClient('http://bugzilla.example.com')
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The Bugzilla bug could not be verified.',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The Bugzilla bug could not be verified.',
|
||||
bzc.get_review_bug, 123, 'rpms', 'mypkg')
|
||||
|
||||
@patch('bugzilla.Bugzilla')
|
||||
|
|
@ -69,8 +67,8 @@ class TestGetReviewBug(unittest.TestCase):
|
|||
Bugzilla.return_value.getbug.return_value = Mock()
|
||||
|
||||
bzc = BugzillaClient('http://bugzilla.example.com')
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'not the proper type',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'not the proper type',
|
||||
bzc.get_review_bug, 123, 'xxx', 'mypkg')
|
||||
|
||||
@patch('bugzilla.Bugzilla')
|
||||
|
|
@ -80,6 +78,6 @@ class TestGetReviewBug(unittest.TestCase):
|
|||
bzc = BugzillaClient('http://bugzilla.example.com')
|
||||
# namespace container requires bug component is Container Review,
|
||||
# but fake bug has a different component.
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'not the proper type',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'not the proper type',
|
||||
bzc.get_review_bug, 123, 'container', 'mypkg')
|
||||
|
|
|
|||
137
test/test_cli.py
137
test/test_cli.py
|
|
@ -16,6 +16,7 @@ import json
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
from configparser import NoOptionError, NoSectionError
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from os import rmdir
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
|
|
@ -32,10 +33,6 @@ try:
|
|||
except ImportError:
|
||||
from pkg_resources import get_distribution as distribution
|
||||
|
||||
import six
|
||||
from six.moves import StringIO
|
||||
from six.moves.configparser import NoOptionError, NoSectionError
|
||||
|
||||
import fedpkg.cli
|
||||
from fedpkg.bugzilla import BugzillaClient
|
||||
from fedpkg.cli import check_bodhi_version
|
||||
|
|
@ -89,19 +86,19 @@ class TestIsUpdateAborted(CliTestCase):
|
|||
|
||||
def test_all_line_are_commented_out(self):
|
||||
with io.open(self.bodhi_template, 'w', encoding='utf-8') as f:
|
||||
f.write(six.u('# line 1\n#line 2\n#line 3\n'))
|
||||
f.write('# line 1\n#line 2\n#line 3\n')
|
||||
|
||||
self.assertTrue(self._is_update_aborted())
|
||||
|
||||
def test_template_is_ok(self):
|
||||
with io.open(self.bodhi_template, 'w', encoding='utf-8') as f:
|
||||
f.write(six.u('[fedpkg-1.34-1.fc28]\ntype=\nnotes=abc\n'))
|
||||
f.write('[fedpkg-1.34-1.fc28]\ntype=\nnotes=abc\n')
|
||||
|
||||
self.assertFalse(self._is_update_aborted())
|
||||
|
||||
def test_template_content_is_broken(self):
|
||||
with io.open(self.bodhi_template, 'w', encoding='utf-8') as f:
|
||||
f.write(six.u('#[fedpkg-1.34-1.fc28]\ntype=\nnotes=abc\n'))
|
||||
f.write('#[fedpkg-1.34-1.fc28]\ntype=\nnotes=abc\n')
|
||||
|
||||
self.assertTrue(self._is_update_aborted())
|
||||
|
||||
|
|
@ -142,7 +139,7 @@ class TestUpdate(CliTestCase):
|
|||
self.clog_patcher.start()
|
||||
|
||||
# Logs will be read in the tests which do not specify --notes option
|
||||
self.fake_clog = list(six.moves.map(six.u, [
|
||||
self.fake_clog = [
|
||||
'Add tests for command update',
|
||||
'New command update - #1000', # invalid bug id format
|
||||
'Fix tests - #2000, #notabug', # both invalid bug id format
|
||||
|
|
@ -150,7 +147,7 @@ class TestUpdate(CliTestCase):
|
|||
'fix: rh#10001',
|
||||
'Fixes: rhbz#20001',
|
||||
' close: fedora#30001', # test whitespace at the beginning
|
||||
]))
|
||||
]
|
||||
clog_file = os.path.join(self.cloned_repo_path, 'clog')
|
||||
with io.open(clog_file, 'w', encoding='utf-8') as f:
|
||||
f.write(os.linesep.join(self.fake_clog))
|
||||
|
|
@ -216,7 +213,7 @@ class TestUpdate(CliTestCase):
|
|||
expected_data = {
|
||||
'autokarma': 'True',
|
||||
'bugs': '10001,20001,30001',
|
||||
'display_name': six.u(''),
|
||||
'display_name': '',
|
||||
'builds': ' {0} '.format(self.mock_nvr.return_value),
|
||||
'close_bugs': True,
|
||||
'request': 'testing',
|
||||
|
|
@ -259,7 +256,7 @@ class TestUpdate(CliTestCase):
|
|||
else:
|
||||
self.assertTrue(self.fake_clog[0] in bodhi_template)
|
||||
rest_clog = os.linesep.join([
|
||||
six.u('# {0}').format(line) for line in self.fake_clog[1:]
|
||||
'# {0}'.format(line) for line in self.fake_clog[1:]
|
||||
])
|
||||
self.assertTrue(rest_clog in bodhi_template)
|
||||
|
||||
|
|
@ -269,21 +266,21 @@ class TestUpdate(CliTestCase):
|
|||
|
||||
with patch.object(cli.config, 'get',
|
||||
side_effect=NoOptionError('url', 'bodhi')):
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Could not get bodhi options.', cli.update)
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Could not get bodhi options.', cli.update)
|
||||
|
||||
with patch.object(cli.config, 'get',
|
||||
side_effect=NoSectionError('bodhi')):
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Could not get bodhi options.', cli.update)
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Could not get bodhi options.', cli.update)
|
||||
|
||||
@patch('os.path.isfile', return_value=False)
|
||||
def test_fail_if_bodhi_template_is_not_a_file(self, isfile):
|
||||
cli_cmd = ['fedpkg', '--path', self.cloned_repo_path, 'update']
|
||||
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'No bodhi update details saved',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'No bodhi update details saved',
|
||||
self.assert_bodhi_update, cli)
|
||||
|
||||
self.mock_run_command.assert_called_once_with(
|
||||
|
|
@ -323,8 +320,8 @@ class TestUpdate(CliTestCase):
|
|||
cli_cmd = ['fedpkg', '--path', self.cloned_repo_path, 'update']
|
||||
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Could not generate update request',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Could not generate update request',
|
||||
self.assert_bodhi_update, cli)
|
||||
|
||||
def test_create_update_in_stage_bodhi(self):
|
||||
|
|
@ -340,30 +337,30 @@ class TestUpdate(CliTestCase):
|
|||
def test_missing_update_type_in_template(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(self, rpkgError, 'Missing update type',
|
||||
self.assert_bodhi_update, cli)
|
||||
self.assertRaisesRegex(rpkgError, 'Missing update type',
|
||||
self.assert_bodhi_update, cli)
|
||||
|
||||
def test_incorrect_update_type_in_template(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(self, rpkgError, 'Incorrect update type',
|
||||
self.assert_bodhi_update, cli, update_type='xxx')
|
||||
self.assertRaisesRegex(rpkgError, 'Incorrect update type',
|
||||
self.assert_bodhi_update, cli, update_type='xxx')
|
||||
|
||||
def test_incorrect_request_type_in_template(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(self, rpkgError, 'Incorrect request type',
|
||||
self.assert_bodhi_update, cli,
|
||||
update_type='enhancement',
|
||||
request_type='xxx')
|
||||
self.assertRaisesRegex(rpkgError, 'Incorrect request type',
|
||||
self.assert_bodhi_update, cli,
|
||||
update_type='enhancement',
|
||||
request_type='xxx')
|
||||
|
||||
def test_incorrect_suggest_type_in_template(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path, 'update']
|
||||
cli = self.get_cli(cli_cmd)
|
||||
six.assertRaisesRegex(self, rpkgError, 'Incorrect suggest type',
|
||||
self.assert_bodhi_update, cli,
|
||||
update_type='enhancement',
|
||||
suggest='123')
|
||||
self.assertRaisesRegex(rpkgError, 'Incorrect suggest type',
|
||||
self.assert_bodhi_update, cli,
|
||||
update_type='enhancement',
|
||||
suggest='123')
|
||||
|
||||
def test_create_with_cli_options(self):
|
||||
cli_cmd = [
|
||||
|
|
@ -413,7 +410,7 @@ class TestUpdate(CliTestCase):
|
|||
self.assert_bodhi_update(
|
||||
cli, update_type='bugfix', notes='Line 1\nLine 2\nLine 3')
|
||||
|
||||
@patch('sys.stderr', new=six.StringIO())
|
||||
@patch('sys.stderr', new=io.StringIO())
|
||||
def test_invalid_stable_karma_option(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.get_cli([
|
||||
|
|
@ -427,7 +424,7 @@ class TestUpdate(CliTestCase):
|
|||
'update', '--stable-karma', '-3'
|
||||
])
|
||||
|
||||
@patch('sys.stderr', new=six.StringIO())
|
||||
@patch('sys.stderr', new=io.StringIO())
|
||||
def test_invalid_unstable_karma_option(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.get_cli([
|
||||
|
|
@ -441,7 +438,7 @@ class TestUpdate(CliTestCase):
|
|||
'update', '--unstable-karma', '3'
|
||||
])
|
||||
|
||||
@patch('sys.stderr', new=six.StringIO())
|
||||
@patch('sys.stderr', new=io.StringIO())
|
||||
def test_invalid_bug(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.get_cli([
|
||||
|
|
@ -493,7 +490,7 @@ class TestRequestRepo(CliTestCase):
|
|||
return self.new_cli(name=name, cfg=cfg, user_cfg=user_cfg)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo(self, mock_request_post, mock_bz):
|
||||
"""Tests a standard request-repo call"""
|
||||
self.mock_bug.summary = ('Review Request: testpkg - a description')
|
||||
|
|
@ -531,7 +528,7 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo_override(self, mock_request_post, mock_bz):
|
||||
"""Tests a request-repo call with an overridden repo name"""
|
||||
mock_bz.getbug.return_value = self.mock_bug
|
||||
|
|
@ -569,7 +566,7 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo_module(self, mock_request_post, mock_bz):
|
||||
"""Tests a request-repo call for a new module"""
|
||||
self.mock_bug.product = 'Fedora Modules'
|
||||
|
|
@ -608,7 +605,7 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo_container(self, mock_request_post, mock_bz):
|
||||
"""Tests a request-repo call for a new container"""
|
||||
self.mock_bug.product = 'Fedora Container Images'
|
||||
|
|
@ -650,7 +647,7 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo_with_optional_details(
|
||||
self, mock_request_post, mock_bz):
|
||||
"""Tests a request-repo call with the optional details"""
|
||||
|
|
@ -690,7 +687,7 @@ class TestRequestRepo(CliTestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('requests.post')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_repo_exception(self, mock_request_post, mock_bz):
|
||||
"""Tests a request-repo call with the exception flag"""
|
||||
mock_rv = Mock()
|
||||
|
|
@ -935,7 +932,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Tests request-branch"""
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -981,7 +978,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_existing_branch(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Tests request-existing-branch"""
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -1008,7 +1005,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_override(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Tests request-branch with an overridden package and branch name"""
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -1051,7 +1048,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_epel_branch_override(
|
||||
self, mock_grb, mock_request_post, mock_request_get
|
||||
):
|
||||
|
|
@ -1100,7 +1097,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_module(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Tests request-branch for a new module branch"""
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -1178,14 +1175,14 @@ class TestRequestBranch(CliTestCase):
|
|||
'fedora-scm-requests/issue/2')
|
||||
self.assertEqual(output, expected_output)
|
||||
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_with_global_option_name_and_namespace(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
'--name', 'nethack', '--namespace', 'container',
|
||||
'request-branch', 'f27']
|
||||
self.assert_request_branch_container(cli_cmd)
|
||||
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_with_its_own_option_repo_and_namespace(self):
|
||||
cli_cmd = ['fedpkg-stage', '--path', self.cloned_repo_path,
|
||||
'request-branch',
|
||||
|
|
@ -1196,7 +1193,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('fedpkg.cli.verify_sls')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_sls(self, mock_verify_sls, mock_grb,
|
||||
mock_request_post, mock_request_get):
|
||||
"""Tests request-branch with service levels"""
|
||||
|
|
@ -1299,7 +1296,7 @@ class TestRequestBranch(CliTestCase):
|
|||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_branch_all_releases(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Tests request-branch with the '--all-releases' option """
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -1489,13 +1486,13 @@ https://pagure.stg.example.com/releng/fedora-scm-requests/issue/3"""
|
|||
'supported arches, therefore, it cannot be in EPEL. If this is a '
|
||||
'mistake or you have an exception, please contact the Release '
|
||||
'Engineering team.')
|
||||
with six.assertRaisesRegex(self, rpkgError, expected_error):
|
||||
with self.assertRaisesRegex(rpkgError, expected_error):
|
||||
cli.request_branch()
|
||||
|
||||
@patch('requests.get')
|
||||
@patch('requests.post')
|
||||
@patch('fedpkg.cli.get_release_branches')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_with_repo_option(self, mock_grb, mock_request_post, mock_request_get):
|
||||
"""Test request branch with option --repo"""
|
||||
mock_grb.return_value = {'fedora': ['f25', 'f26', 'f27'],
|
||||
|
|
@ -1550,7 +1547,7 @@ class TestRequestTestsRepo(CliTestCase):
|
|||
|
||||
@patch('requests.post')
|
||||
@patch('requests.get')
|
||||
@patch('sys.stdout', new=StringIO())
|
||||
@patch('sys.stdout', new=io.StringIO())
|
||||
def test_request_tests_repo(self, mock_request_get, mock_request_post):
|
||||
"""Tests request-tests-repo"""
|
||||
|
||||
|
|
@ -1626,8 +1623,8 @@ try:
|
|||
def test_no_2_x_version_installed(self, distribution):
|
||||
distribution.side_effect = importlib.metadata.PackageNotFoundError
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
||||
check_bodhi_version)
|
||||
|
||||
except ImportError:
|
||||
|
|
@ -1640,8 +1637,8 @@ except ImportError:
|
|||
def test_no_2_x_version_installed(self, get_distribution):
|
||||
get_distribution.side_effect = pkg_resources.DistributionNotFound
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, r'bodhi-client < 2\.0 is not supported\.',
|
||||
check_bodhi_version)
|
||||
|
||||
|
||||
|
|
@ -1693,8 +1690,8 @@ class TestBodhiOverride(CliTestCase):
|
|||
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
cli = self.new_cli()
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Build {0} does not exist'.format(build_nvr),
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Build {0} does not exist'.format(build_nvr),
|
||||
cli.create_buildroot_override)
|
||||
|
||||
self.kojisession.getBuild.assert_called_once_with(build_nvr)
|
||||
|
|
@ -1836,7 +1833,7 @@ class TestBodhiOverride(CliTestCase):
|
|||
|
||||
for cmd, expected_output in cli_cmds:
|
||||
with patch('sys.argv', new=cmd):
|
||||
with patch('sys.stderr', new=StringIO()):
|
||||
with patch('sys.stderr', new=io.StringIO()):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.new_cli()
|
||||
output = sys.stderr.getvalue()
|
||||
|
|
@ -1889,8 +1886,8 @@ class TestBodhiOverrideExtend(CliTestCase):
|
|||
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
cli = self.new_cli()
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Build somepkg-1.54-2.fc28 does not exist.',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Build somepkg-1.54-2.fc28 does not exist.',
|
||||
cli.extend_buildroot_override)
|
||||
|
||||
@patch('fedpkg.BodhiClient.list_overrides')
|
||||
|
|
@ -2105,8 +2102,8 @@ class TestBodhiOverrideExtend(CliTestCase):
|
|||
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
cli = self.new_cli()
|
||||
six.assertRaisesRegex(self, rpkgError, '',
|
||||
cli.extend_buildroot_override)
|
||||
self.assertRaisesRegex(rpkgError, '',
|
||||
cli.extend_buildroot_override)
|
||||
|
||||
@freeze_time('2018-07-22')
|
||||
@patch('fedpkg.BodhiClient.list_overrides')
|
||||
|
|
@ -2134,8 +2131,8 @@ class TestBodhiOverrideExtend(CliTestCase):
|
|||
]
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
cli = self.new_cli()
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError,
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
'specified expiration date .+ should be future date',
|
||||
cli.extend_buildroot_override)
|
||||
|
||||
|
|
@ -2145,7 +2142,7 @@ class TestBodhiOverrideExtend(CliTestCase):
|
|||
'override', 'extend', '2019/01/10', 'rpkg-1.10-1.fc28'
|
||||
]
|
||||
with patch('sys.argv', new=cli_cmd):
|
||||
with patch('sys.stderr', new=StringIO()):
|
||||
with patch('sys.stderr', new=io.StringIO()):
|
||||
with self.assertRaises(SystemExit):
|
||||
self.new_cli()
|
||||
output = sys.stderr.getvalue()
|
||||
|
|
@ -2173,7 +2170,7 @@ class TestReadReleasesFromLocalConfig(CliTestCase):
|
|||
error_msg = 'given path \'{0}\' doesn\'t exist'.format(self.cloned_repo_path)
|
||||
validate_path.side_effect = argparse.ArgumentTypeError(error_msg)
|
||||
with patch('sys.argv', new=self.fake_cmd):
|
||||
with patch('sys.stderr', new=six.StringIO()):
|
||||
with patch('sys.stderr', new=io.StringIO()):
|
||||
# argparse.ArgumentTypeError turns to SystemExit
|
||||
with self.assertRaises(SystemExit):
|
||||
self.new_cli()
|
||||
|
|
@ -2197,8 +2194,8 @@ class TestReadReleasesFromLocalConfig(CliTestCase):
|
|||
with patch('fedpkg.cli.configparser.ConfigParser.read') as read:
|
||||
read.return_value = []
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, '.+ not accessible',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, '.+ not accessible',
|
||||
cli.read_releases_from_local_config, self.active_releases)
|
||||
|
||||
def test_get_expanded_releases(self):
|
||||
|
|
@ -2344,7 +2341,7 @@ class TestReleasesInfo(CliTestCase):
|
|||
def assert_output_releases(self, expected_output, option=[]):
|
||||
with patch('sys.argv', ['fedpkg', 'releases-info'] + option):
|
||||
cli = self.new_cli()
|
||||
with patch('sys.stdout', new=six.StringIO()):
|
||||
with patch('sys.stdout', new=io.StringIO()):
|
||||
cli.show_releases_info()
|
||||
output = sys.stdout.getvalue().strip()
|
||||
self.assertEqual(expected_output, output)
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@
|
|||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import six
|
||||
from six.moves import builtins
|
||||
import builtins
|
||||
|
||||
from pyrpkg.errors import rpkgError
|
||||
from utils import CommandTestCase
|
||||
|
|
@ -411,8 +410,8 @@ class TestFindRawhideBranch(CommandTestCase):
|
|||
# As the code shows, any error will be caught
|
||||
koji_session.getBuildTarget.side_effect = ValueError
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Unable to find rawhide target',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Unable to find rawhide target',
|
||||
self.cmd._findrawhidebranch)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import configparser
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
import six
|
||||
from pyrpkg.errors import rpkgError
|
||||
from six.moves import configparser
|
||||
from utils import unittest
|
||||
|
||||
from fedpkg.cli import fedpkgClient
|
||||
|
|
@ -130,8 +129,7 @@ class RetireTestCase(unittest.TestCase):
|
|||
|
||||
args = ['fedpkg', '--release=rawhide', 'disable-monitoring']
|
||||
client = self._fake_client(args)
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
"The following error occurred while disabling monitoring: Invalid or expired token\n"
|
||||
"For invalid or expired tokens please set a new token",
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@
|
|||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
from configparser import NoOptionError, NoSectionError
|
||||
import json
|
||||
|
||||
import six
|
||||
from requests.exceptions import ConnectionError
|
||||
from six.moves.configparser import NoOptionError, NoSectionError
|
||||
|
||||
from fedpkg import utils
|
||||
from freezegun import freeze_time
|
||||
|
|
@ -123,15 +122,15 @@ class TestAssertNewTestsRepo(unittest.TestCase):
|
|||
def test_should_raise_error_if_connection_error_to_distgit(self, get):
|
||||
get.side_effect = ConnectionError
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The error was',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The error was',
|
||||
utils.assert_new_tests_repo, 'testrepo', 'http://distgit/')
|
||||
|
||||
def test_test_repo_exists(self, get):
|
||||
get.return_value = Mock(ok=True)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'Repository .+ already exists',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'Repository .+ already exists',
|
||||
utils.assert_new_tests_repo, 'testrepo', 'http://distgit/')
|
||||
|
||||
def test_keep_quiet_if_repo_not_exist(self, get):
|
||||
|
|
@ -155,23 +154,21 @@ class TestGetPagureToken(unittest.TestCase):
|
|||
config = Mock()
|
||||
|
||||
config.get.side_effect = NoOptionError('token', 'fedpkg.pagure')
|
||||
six.assertRaisesRegex(self,
|
||||
rpkgError, "Missing option 'token' in the section 'fedpkg.pagure'",
|
||||
utils.config_get_safely,
|
||||
config,
|
||||
'fedpkg.pagure', 'token')
|
||||
self.assertRaisesRegex(rpkgError, "Missing option 'token' in the section 'fedpkg.pagure'",
|
||||
utils.config_get_safely,
|
||||
config,
|
||||
'fedpkg.pagure', 'token')
|
||||
|
||||
config.get.side_effect = NoSectionError('fedpkg.pagure')
|
||||
six.assertRaisesRegex(self, rpkgError, "Missing section 'fedpkg.pagure'",
|
||||
utils.config_get_safely, config, 'fedpkg.pagure', 'token')
|
||||
self.assertRaisesRegex(rpkgError, "Missing section 'fedpkg.pagure'",
|
||||
utils.config_get_safely, config, 'fedpkg.pagure', 'token')
|
||||
|
||||
|
||||
class TestVerifySLS(unittest.TestCase):
|
||||
"""Test verify_sls"""
|
||||
|
||||
def test_sl_date_format_is_invalid(self):
|
||||
six.assertRaisesRegex(
|
||||
self,
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
"The EOL date .+ is in an invalid format",
|
||||
utils.verify_sls,
|
||||
|
|
@ -233,22 +230,22 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_raise_error_if_connection_error(self, get):
|
||||
get.side_effect = ConnectionError
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The error was:',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The error was:',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel7')
|
||||
|
||||
def test_raise_error_if_GET_response_not_ok(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel7')
|
||||
|
||||
def test_correct_url_epel7(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel7')
|
||||
get.assert_called_once_with(
|
||||
'https://infrastructure.fedoraproject.org/repo/json/pkg_el7.json',
|
||||
|
|
@ -257,8 +254,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_correct_url_epel8(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel8')
|
||||
get.assert_called_once_with(
|
||||
'https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json',
|
||||
|
|
@ -267,8 +264,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_correct_url_epel8_next(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel8-next')
|
||||
get.assert_called_once_with(
|
||||
'https://infrastructure.fedoraproject.org/repo/json/pkg_el8.json',
|
||||
|
|
@ -277,8 +274,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_correct_url_epel9(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel9')
|
||||
get.assert_called_once_with(
|
||||
'https://composes.stream.centos.org/production/'
|
||||
|
|
@ -288,8 +285,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_correct_url_epel10(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel10')
|
||||
get.assert_called_once_with(
|
||||
'https://composes.stream.centos.org/stream-10/production'
|
||||
|
|
@ -299,8 +296,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
def test_correct_url_epel10_10(self, get):
|
||||
get.return_value = Mock(ok=False, status_code=404)
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The status code was: 404',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The status code was: 404',
|
||||
utils.assert_valid_epel_package, 'pkg', 'epel10.10')
|
||||
get.assert_called_once_with(
|
||||
'https://composes.stream.centos.org/stream-10/production'
|
||||
|
|
@ -320,8 +317,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'is built on all supported arches',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'is built on all supported arches',
|
||||
utils.assert_valid_epel_package, 'pkg1', 'el6')
|
||||
|
||||
def test_should_not_have_epel_branch_for_el7_pkg(self, get):
|
||||
|
|
@ -337,8 +334,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'is built on all supported arches',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'is built on all supported arches',
|
||||
utils.assert_valid_epel_package, 'pkg1', 'epel7')
|
||||
|
||||
def test_raise_error_if_package_has_noarch_only(self, get):
|
||||
|
|
@ -353,8 +350,8 @@ class TestAssertValidEPELPackage(unittest.TestCase):
|
|||
}
|
||||
}
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'This package is already an EL package',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'This package is already an EL package',
|
||||
utils.assert_valid_epel_package, 'pkg1', 'epel7')
|
||||
|
||||
|
||||
|
|
@ -366,8 +363,8 @@ class TestNewPagureIssue(unittest.TestCase):
|
|||
post.side_effect = ConnectionError
|
||||
logger = Mock()
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The connection to Pagure failed',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The connection to Pagure failed',
|
||||
utils.new_pagure_issue,
|
||||
logger, 'http://distgit/', '123456', 'new package', {'repo': 'pkg1'}, 'fedpkg')
|
||||
|
||||
|
|
@ -377,8 +374,8 @@ class TestNewPagureIssue(unittest.TestCase):
|
|||
post.return_value = rv
|
||||
logger = Mock()
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError,
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
'The following error occurred while creating a new issue',
|
||||
utils.new_pagure_issue,
|
||||
logger, 'http://distgit/', '123456', 'new package', {'repo': 'pkg1'}, 'fedpkg')
|
||||
|
|
@ -392,8 +389,8 @@ class TestNewPagureIssue(unittest.TestCase):
|
|||
post.return_value = rv
|
||||
logger = Mock()
|
||||
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError,
|
||||
self.assertRaisesRegex(
|
||||
rpkgError,
|
||||
'\nFor invalid or expired tokens please '
|
||||
'set a new token in your user configuration with:'
|
||||
'\n\n\tfedpkg set-pagure-token <token>\n',
|
||||
|
|
@ -446,16 +443,16 @@ class TestQueryBodhi(unittest.TestCase):
|
|||
get.side_effect = ConnectionError
|
||||
|
||||
result = utils.query_bodhi('http://localhost/')
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The connection to BODHI failed',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The connection to BODHI failed',
|
||||
list, result)
|
||||
|
||||
def test_response_not_ok(self, get):
|
||||
get.return_value.ok = False
|
||||
|
||||
result = utils.query_bodhi('http://localhost/')
|
||||
six.assertRaisesRegex(
|
||||
self, rpkgError, 'The following error occurred',
|
||||
self.assertRaisesRegex(
|
||||
rpkgError, 'The following error occurred',
|
||||
list, result)
|
||||
|
||||
def test_read_yield_data_normally(self, get):
|
||||
|
|
@ -576,6 +573,6 @@ class TestGetFedoraReleaseState(unittest.TestCase):
|
|||
def test_config_does_not_have_option(self):
|
||||
config = Mock()
|
||||
config.get.side_effect = NoOptionError('releases_service', 'fedpkg.bodhi')
|
||||
six.assertRaisesRegex(self, rpkgError, r"Could not get release state for Fedora \(F30M\): "
|
||||
"No option 'releases_service' in section: 'fedpkg.bodhi'.",
|
||||
utils.get_fedora_release_state, config, 'fedpkg', 'F30M')
|
||||
self.assertRaisesRegex(rpkgError, r"Could not get release state for Fedora \(F30M\): "
|
||||
"No option 'releases_service' in section: 'fedpkg.bodhi'.",
|
||||
utils.get_fedora_release_state, config, 'fedpkg', 'F30M')
|
||||
|
|
|
|||
|
|
@ -10,14 +10,13 @@
|
|||
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
|
||||
# the full text of the license.
|
||||
|
||||
import configparser
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
from six.moves import configparser
|
||||
|
||||
import fedpkg.cli
|
||||
import pyrpkg
|
||||
from fedpkg import Commands
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue