fix py3 tests compatibility

This commit is contained in:
Tomas Kopecek 2019-02-19 13:56:16 +01:00 committed by Mike McLean
parent 7ad2fe348d
commit aefb2ddba7
4 changed files with 21 additions and 18 deletions

View file

@ -19,10 +19,10 @@ def load_plugin(plugin_type, plugin_name):
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(mod_name, CLI_FILENAME)
spec = importlib.util.spec_from_loader(loader.name, loader)
kojid = importlib.util.module_from_spec(spec)
spec.loader.exec_module(kojid)
loader.exec_module(kojid)
sys.modules[mod_name] = kojid
plugin = importlib.util.module_from_spec(spec)
spec.loader.exec_module(plugin)
loader.exec_module(plugin)
sys.modules[mod_name] = plugin
else:
import imp
plugin = imp.load_source(mod_name, CLI_FILENAME)

View file

@ -187,14 +187,14 @@ class TestProtonMsg(unittest.TestCase):
def test_send_queued_msgs_fail(self, getLogger, Container):
context.protonmsg_msgs = [('test.topic', {'testheader': 1}, 'test body')]
conf = tempfile.NamedTemporaryFile()
conf.write("""[broker]
conf.write(six.b("""[broker]
urls = amqps://broker1.example.com:5671 amqps://broker2.example.com:5671
cert = /etc/koji-hub/plugins/client.pem
cacert = /etc/koji-hub/plugins/ca.pem
topic_prefix = koji
connect_timeout = 10
send_timeout = 60
""")
"""))
conf.flush()
protonmsg.CONFIG_FILE = conf.name
protonmsg.CONFIG = None
@ -211,14 +211,14 @@ send_timeout = 60
def test_send_queued_msgs_success(self, getLogger, Container):
context.protonmsg_msgs = [('test.topic', {'testheader': 1}, 'test body')]
conf = tempfile.NamedTemporaryFile()
conf.write("""[broker]
conf.write(six.b("""[broker]
urls = amqps://broker1.example.com:5671 amqps://broker2.example.com:5671
cert = /etc/koji-hub/plugins/client.pem
cacert = /etc/koji-hub/plugins/ca.pem
topic_prefix = koji
connect_timeout = 10
send_timeout = 60
""")
"""))
conf.flush()
protonmsg.CONFIG_FILE = conf.name
protonmsg.CONFIG = None
@ -236,7 +236,7 @@ send_timeout = 60
def test_send_queued_msgs_test_mode(self, getLogger, Container):
context.protonmsg_msgs = [('test.topic', {'testheader': 1}, 'test body')]
conf = tempfile.NamedTemporaryFile()
conf.write("""[broker]
conf.write(six.b("""[broker]
urls = amqps://broker1.example.com:5671 amqps://broker2.example.com:5671
cert = /etc/koji-hub/plugins/client.pem
cacert = /etc/koji-hub/plugins/ca.pem
@ -244,7 +244,7 @@ topic_prefix = koji
connect_timeout = 10
send_timeout = 60
test_mode = on
""")
"""))
conf.flush()
protonmsg.CONFIG_FILE = conf.name
protonmsg.CONFIG = None

View file

@ -96,7 +96,7 @@ class FakeConfigParser(object):
class TestRunrootConfig(unittest.TestCase):
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_bad_config_paths0(self, safe_config_parser):
cp = FakeConfigParser()
del cp.CONFIG['path0']['mountpoint']
@ -109,7 +109,7 @@ class TestRunrootConfig(unittest.TestCase):
self.assertEqual(cm.exception.args[0],
"bad config: missing options in path0 section")
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_bad_config_absolute_path(self, safe_config_parser):
cp = FakeConfigParser()
cp.CONFIG['paths']['default_mounts'] = ''
@ -122,7 +122,7 @@ class TestRunrootConfig(unittest.TestCase):
self.assertEqual(cm.exception.args[0],
"bad config: all paths (default_mounts, safe_roots, path_subs) needs to be absolute: ")
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_valid_config(self, safe_config_parser):
safe_config_parser.return_value = FakeConfigParser()
session = mock.MagicMock()
@ -130,7 +130,7 @@ class TestRunrootConfig(unittest.TestCase):
options.workdir = '/tmp/nonexistentdirectory'
runroot.RunRootTask(123, 'runroot', {}, session, options)
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_valid_config_alt(self, safe_config_parser):
safe_config_parser.return_value = FakeConfigParser(CONFIG2)
session = mock.MagicMock()
@ -138,7 +138,7 @@ class TestRunrootConfig(unittest.TestCase):
options.workdir = '/tmp/nonexistentdirectory'
runroot.RunRootTask(123, 'runroot', {}, session, options)
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_pathnum_gaps(self, safe_config_parser):
session = mock.MagicMock()
options = mock.MagicMock()
@ -159,7 +159,7 @@ class TestRunrootConfig(unittest.TestCase):
paths = list([CONFIG2[k] for k in ('path0', 'path1', 'path2')])
self.assertEqual(task2.config['paths'], paths)
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def test_bad_path_sub(self, safe_config_parser):
session = mock.MagicMock()
options = mock.MagicMock()
@ -172,7 +172,7 @@ class TestRunrootConfig(unittest.TestCase):
class TestMounts(unittest.TestCase):
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def setUp(self, safe_config_parser):
safe_config_parser.return_value = FakeConfigParser()
self.session = mock.MagicMock()
@ -324,7 +324,7 @@ class TestMounts(unittest.TestCase):
os_unlink.assert_not_called()
class TestHandler(unittest.TestCase):
@mock.patch('ConfigParser.SafeConfigParser')
@mock.patch('six.moves.configparser.SafeConfigParser')
def setUp(self, safe_config_parser):
self.session = mock.MagicMock()
self.br = mock.MagicMock()