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):
|
||||
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):
|
||||
koji.MultiCallHack(self.ksession)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ class TestGenMockConfig(unittest.TestCase):
|
|||
if not fn.endswith('.data'):
|
||||
continue
|
||||
path = os.path.join(datadir, fn)
|
||||
with open(path, 'rt', encoding='utf-8') as fo:
|
||||
with open(path, 'rt') as fo:
|
||||
s = fo.read()
|
||||
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()
|
||||
output = koji.genMockConfig(**params)
|
||||
self.assertMultiLineEqual(output, expected)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import sys
|
|||
import unittest
|
||||
|
||||
try:
|
||||
import importlib
|
||||
imp = None
|
||||
except ImportError:
|
||||
import imp
|
||||
importlib = None
|
||||
except ImportError:
|
||||
import importlib
|
||||
imp = None
|
||||
|
||||
import koji
|
||||
import koji.util
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import shutil
|
|||
import tempfile
|
||||
import unittest
|
||||
|
||||
import six
|
||||
|
||||
import koji
|
||||
|
||||
|
||||
|
|
@ -31,6 +33,7 @@ class TestCheckSigMD5(unittest.TestCase):
|
|||
self.assertEqual(contents_signed, contents_spliced)
|
||||
self.assertNotEqual(contents_signed, contents_orig)
|
||||
|
||||
@unittest.skipIf(six.PY2, "Python 2 not supported")
|
||||
def test_splice_rpm_sighdr(self):
|
||||
contents_signed = open(self.signed, 'rb').read()
|
||||
sighdr = koji.rip_rpm_sighdr(self.signed)
|
||||
|
|
|
|||
|
|
@ -320,9 +320,8 @@ class TasksTestCase(unittest.TestCase):
|
|||
|
||||
@patch('time.time')
|
||||
@patch('time.sleep')
|
||||
@patch('signal.sigtimedwait')
|
||||
@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"""
|
||||
temp_path = self.get_tmp_dir_path('TaskTest')
|
||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||
|
|
@ -330,11 +329,18 @@ class TasksTestCase(unittest.TestCase):
|
|||
obj.session = MagicMock()
|
||||
obj.session.host.taskWait.return_value = [[], [99, 100, 101]]
|
||||
time.side_effect = list(range(0, 4000, 60))
|
||||
if six.PY3:
|
||||
sigtimedwait = patch('signal.sigtimedwait').start()
|
||||
|
||||
try:
|
||||
obj.wait([99, 100, 101], timeout=3600)
|
||||
raise Exception('A GenericError was not raised.')
|
||||
except koji.GenericError as e:
|
||||
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.cancelTaskChildren.assert_called_once_with(95)
|
||||
obj.session.getTaskResult.assert_not_called()
|
||||
|
|
@ -342,9 +348,8 @@ class TasksTestCase(unittest.TestCase):
|
|||
|
||||
@patch('time.time')
|
||||
@patch('time.sleep')
|
||||
@patch('signal.sigtimedwait')
|
||||
@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"""
|
||||
temp_path = self.get_tmp_dir_path('TaskTest')
|
||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||
|
|
@ -359,8 +364,15 @@ class TasksTestCase(unittest.TestCase):
|
|||
# and then report all done
|
||||
taskWait_returns.append([[99, 100, 101], []])
|
||||
obj.session.host.taskWait.side_effect = taskWait_returns
|
||||
|
||||
if six.PY3:
|
||||
sigtimedwait = patch('signal.sigtimedwait').start()
|
||||
|
||||
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.cancelTaskChildren.assert_not_called()
|
||||
pause.assert_not_called()
|
||||
|
|
|
|||
|
|
@ -758,7 +758,7 @@ class MavenUtilTestCase(unittest.TestCase):
|
|||
|
||||
def _read_conf(self, cfile):
|
||||
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:
|
||||
config = six.moves.configparser.SafeConfigParser()
|
||||
config.readfp(conf_file)
|
||||
|
|
@ -1513,7 +1513,10 @@ class TestRmtree(unittest.TestCase):
|
|||
rmtree_nofork.assert_called_once()
|
||||
self.assertEqual(rmtree_nofork.call_args[0][0], path)
|
||||
_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('koji.util._rmtree_nofork')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
# coding=utf-8
|
||||
from __future__ import absolute_import
|
||||
from six.moves import range
|
||||
import unittest
|
||||
|
||||
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 koji import xmlrpcplus
|
||||
|
||||
|
||||
|
|
@ -98,6 +104,9 @@ class TestDump(unittest.TestCase):
|
|||
'RegexNameInternal.compiled': re.compile('^[A-Za-z0-9/_.+-]+$')}
|
||||
dist_data_output = ({'MaxNameLengthInternal': 15,
|
||||
'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,)
|
||||
enc = xmlrpcplus.dumps(dict_data, methodresponse=1)
|
||||
params, method = xmlrpc_client.loads(enc)
|
||||
|
|
|
|||
2
tox.ini
2
tox.ini
|
|
@ -57,7 +57,7 @@ commands_pre =
|
|||
{envbindir}/coverage2 erase
|
||||
commands =
|
||||
{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_save_failed_tree_builder.py \
|
||||
tests/test_plugins/test_runroot_cli.py \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue