unittest: enabling tests/test_lib for py2
This commit is contained in:
parent
51d8535eee
commit
c8a27e525a
8 changed files with 45 additions and 14 deletions
|
|
@ -237,6 +237,10 @@ class TestMultiCall(unittest.TestCase):
|
||||||
|
|
||||||
def test_MultiCallHack_weakref_validation(self):
|
def test_MultiCallHack_weakref_validation(self):
|
||||||
expected_exc = 'The session parameter must be a weak reference'
|
expected_exc = 'The session parameter must be a weak reference'
|
||||||
|
if six.PY2:
|
||||||
|
with self.assertRaisesRegexp(TypeError, expected_exc):
|
||||||
|
koji.MultiCallHack(self.ksession)
|
||||||
|
return
|
||||||
with self.assertRaisesRegex(TypeError, expected_exc):
|
with self.assertRaisesRegex(TypeError, expected_exc):
|
||||||
koji.MultiCallHack(self.ksession)
|
koji.MultiCallHack(self.ksession)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ class TestGenMockConfig(unittest.TestCase):
|
||||||
if not fn.endswith('.data'):
|
if not fn.endswith('.data'):
|
||||||
continue
|
continue
|
||||||
path = os.path.join(datadir, fn)
|
path = os.path.join(datadir, fn)
|
||||||
with open(path, 'rt', encoding='utf-8') as fo:
|
with open(path, 'rt') as fo:
|
||||||
s = fo.read()
|
s = fo.read()
|
||||||
params = ast.literal_eval(s)
|
params = ast.literal_eval(s)
|
||||||
with open(path[:-5] + '.out', 'rt', encoding='utf-8') as fo:
|
with open(path[:-5] + '.out', 'rt') as fo:
|
||||||
expected = fo.read()
|
expected = fo.read()
|
||||||
output = koji.genMockConfig(**params)
|
output = koji.genMockConfig(**params)
|
||||||
self.assertMultiLineEqual(output, expected)
|
self.assertMultiLineEqual(output, expected)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import importlib
|
|
||||||
imp = None
|
|
||||||
except ImportError:
|
|
||||||
import imp
|
import imp
|
||||||
importlib = None
|
importlib = None
|
||||||
|
except ImportError:
|
||||||
|
import importlib
|
||||||
|
imp = None
|
||||||
|
|
||||||
import koji
|
import koji
|
||||||
import koji.util
|
import koji.util
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
import koji
|
import koji
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,6 +33,7 @@ class TestCheckSigMD5(unittest.TestCase):
|
||||||
self.assertEqual(contents_signed, contents_spliced)
|
self.assertEqual(contents_signed, contents_spliced)
|
||||||
self.assertNotEqual(contents_signed, contents_orig)
|
self.assertNotEqual(contents_signed, contents_orig)
|
||||||
|
|
||||||
|
@unittest.skipIf(six.PY2, "Python 2 not supported")
|
||||||
def test_splice_rpm_sighdr(self):
|
def test_splice_rpm_sighdr(self):
|
||||||
contents_signed = open(self.signed, 'rb').read()
|
contents_signed = open(self.signed, 'rb').read()
|
||||||
sighdr = koji.rip_rpm_sighdr(self.signed)
|
sighdr = koji.rip_rpm_sighdr(self.signed)
|
||||||
|
|
|
||||||
|
|
@ -320,9 +320,8 @@ class TasksTestCase(unittest.TestCase):
|
||||||
|
|
||||||
@patch('time.time')
|
@patch('time.time')
|
||||||
@patch('time.sleep')
|
@patch('time.sleep')
|
||||||
@patch('signal.sigtimedwait')
|
|
||||||
@patch('signal.pause')
|
@patch('signal.pause')
|
||||||
def test_BaseTaskHandler_wait_timeout(self, pause, sigtimedwait, sleep, time):
|
def test_BaseTaskHandler_wait_timeout(self, pause, sleep, time):
|
||||||
"""Tests timeout behavior in the wait function"""
|
"""Tests timeout behavior in the wait function"""
|
||||||
temp_path = self.get_tmp_dir_path('TaskTest')
|
temp_path = self.get_tmp_dir_path('TaskTest')
|
||||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||||
|
|
@ -330,11 +329,18 @@ class TasksTestCase(unittest.TestCase):
|
||||||
obj.session = MagicMock()
|
obj.session = MagicMock()
|
||||||
obj.session.host.taskWait.return_value = [[], [99, 100, 101]]
|
obj.session.host.taskWait.return_value = [[], [99, 100, 101]]
|
||||||
time.side_effect = list(range(0, 4000, 60))
|
time.side_effect = list(range(0, 4000, 60))
|
||||||
|
if six.PY3:
|
||||||
|
sigtimedwait = patch('signal.sigtimedwait').start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
obj.wait([99, 100, 101], timeout=3600)
|
obj.wait([99, 100, 101], timeout=3600)
|
||||||
raise Exception('A GenericError was not raised.')
|
raise Exception('A GenericError was not raised.')
|
||||||
except koji.GenericError as e:
|
except koji.GenericError as e:
|
||||||
self.assertEqual(e.args[0][:24], 'Subtasks timed out after')
|
self.assertEqual(e.args[0][:24], 'Subtasks timed out after')
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
sigtimedwait.stop()
|
||||||
|
|
||||||
obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])
|
obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])
|
||||||
obj.session.cancelTaskChildren.assert_called_once_with(95)
|
obj.session.cancelTaskChildren.assert_called_once_with(95)
|
||||||
obj.session.getTaskResult.assert_not_called()
|
obj.session.getTaskResult.assert_not_called()
|
||||||
|
|
@ -342,9 +348,8 @@ class TasksTestCase(unittest.TestCase):
|
||||||
|
|
||||||
@patch('time.time')
|
@patch('time.time')
|
||||||
@patch('time.sleep')
|
@patch('time.sleep')
|
||||||
@patch('signal.sigtimedwait')
|
|
||||||
@patch('signal.pause')
|
@patch('signal.pause')
|
||||||
def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sigtimedwait, sleep, time):
|
def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sleep, time):
|
||||||
"""Tests that timeout does not happen if tasks finish in time"""
|
"""Tests that timeout does not happen if tasks finish in time"""
|
||||||
temp_path = self.get_tmp_dir_path('TaskTest')
|
temp_path = self.get_tmp_dir_path('TaskTest')
|
||||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||||
|
|
@ -359,8 +364,15 @@ class TasksTestCase(unittest.TestCase):
|
||||||
# and then report all done
|
# and then report all done
|
||||||
taskWait_returns.append([[99, 100, 101], []])
|
taskWait_returns.append([[99, 100, 101], []])
|
||||||
obj.session.host.taskWait.side_effect = taskWait_returns
|
obj.session.host.taskWait.side_effect = taskWait_returns
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
sigtimedwait = patch('signal.sigtimedwait').start()
|
||||||
|
|
||||||
obj.wait([99, 100, 101], timeout=3600)
|
obj.wait([99, 100, 101], timeout=3600)
|
||||||
|
|
||||||
|
if six.PY3:
|
||||||
|
sigtimedwait.stop()
|
||||||
|
|
||||||
obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])
|
obj.session.host.taskSetWait.assert_called_once_with(95, [99, 100, 101])
|
||||||
obj.session.cancelTaskChildren.assert_not_called()
|
obj.session.cancelTaskChildren.assert_not_called()
|
||||||
pause.assert_not_called()
|
pause.assert_not_called()
|
||||||
|
|
|
||||||
|
|
@ -758,7 +758,7 @@ class MavenUtilTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def _read_conf(self, cfile):
|
def _read_conf(self, cfile):
|
||||||
path = os.path.dirname(__file__)
|
path = os.path.dirname(__file__)
|
||||||
with open(path + cfile, 'rt', encoding='utf-8') as conf_file:
|
with open(path + cfile, 'rt') as conf_file:
|
||||||
if six.PY2:
|
if six.PY2:
|
||||||
config = six.moves.configparser.SafeConfigParser()
|
config = six.moves.configparser.SafeConfigParser()
|
||||||
config.readfp(conf_file)
|
config.readfp(conf_file)
|
||||||
|
|
@ -1513,7 +1513,10 @@ class TestRmtree(unittest.TestCase):
|
||||||
rmtree_nofork.assert_called_once()
|
rmtree_nofork.assert_called_once()
|
||||||
self.assertEqual(rmtree_nofork.call_args[0][0], path)
|
self.assertEqual(rmtree_nofork.call_args[0][0], path)
|
||||||
_exit.assert_called_once()
|
_exit.assert_called_once()
|
||||||
logger = rmtree_nofork.call_args.kwargs['logger']
|
if mock.__package__ == 'unittest':
|
||||||
|
logger = rmtree_nofork.call_args.kwargs['logger']
|
||||||
|
else:
|
||||||
|
logger = rmtree_nofork.call_args[1]['logger']
|
||||||
|
|
||||||
@mock.patch('tempfile.mkstemp') # avoid stray temp file
|
@mock.patch('tempfile.mkstemp') # avoid stray temp file
|
||||||
@mock.patch('koji.util._rmtree_nofork')
|
@mock.patch('koji.util._rmtree_nofork')
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from six.moves import range
|
|
||||||
import unittest
|
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
try:
|
||||||
|
from unittest.mock import ANY
|
||||||
|
except ImportError:
|
||||||
|
from mock import ANY
|
||||||
|
|
||||||
from six.moves import xmlrpc_client
|
from six.moves import xmlrpc_client
|
||||||
|
|
||||||
from koji import xmlrpcplus
|
from koji import xmlrpcplus
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,6 +104,9 @@ class TestDump(unittest.TestCase):
|
||||||
'RegexNameInternal.compiled': re.compile('^[A-Za-z0-9/_.+-]+$')}
|
'RegexNameInternal.compiled': re.compile('^[A-Za-z0-9/_.+-]+$')}
|
||||||
dist_data_output = ({'MaxNameLengthInternal': 15,
|
dist_data_output = ({'MaxNameLengthInternal': 15,
|
||||||
'RegexNameInternal.compiled': "re.compile('^[A-Za-z0-9/_.+-]+$')"},)
|
'RegexNameInternal.compiled': "re.compile('^[A-Za-z0-9/_.+-]+$')"},)
|
||||||
|
if sys.version_info < (3, 7):
|
||||||
|
dist_data_output[0]['RegexNameInternal.compiled'] = ANY
|
||||||
|
|
||||||
dict_data = (dict_data,)
|
dict_data = (dict_data,)
|
||||||
enc = xmlrpcplus.dumps(dict_data, methodresponse=1)
|
enc = xmlrpcplus.dumps(dict_data, methodresponse=1)
|
||||||
params, method = xmlrpc_client.loads(enc)
|
params, method = xmlrpc_client.loads(enc)
|
||||||
|
|
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -57,7 +57,7 @@ commands_pre =
|
||||||
{envbindir}/coverage2 erase
|
{envbindir}/coverage2 erase
|
||||||
commands =
|
commands =
|
||||||
{envbindir}/coverage2 run --source . -m pytest {posargs:\
|
{envbindir}/coverage2 run --source . -m pytest {posargs:\
|
||||||
tests/test_builder tests/test_cli \
|
tests/test_builder tests/test_cli tests/test_lib \
|
||||||
tests/test_plugins/test_runroot_builder.py \
|
tests/test_plugins/test_runroot_builder.py \
|
||||||
tests/test_plugins/test_save_failed_tree_builder.py \
|
tests/test_plugins/test_save_failed_tree_builder.py \
|
||||||
tests/test_plugins/test_runroot_cli.py \
|
tests/test_plugins/test_runroot_cli.py \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue