cleanup, more testing
This commit is contained in:
parent
1bdf7a0f09
commit
9e48e440e8
2 changed files with 56 additions and 4 deletions
|
|
@ -101,7 +101,6 @@ def apply_argspec(argspec, args, kwargs=None):
|
|||
if kwargs is None:
|
||||
kwargs = {}
|
||||
f_args, f_varargs, f_varkw, f_defaults = argspec
|
||||
print argspec, args, kwargs
|
||||
data = dict(zip(f_args, args))
|
||||
if len(args) > len(f_args):
|
||||
if not f_varargs:
|
||||
|
|
@ -152,7 +151,9 @@ def parse_task_params(method, params):
|
|||
# check for new style
|
||||
if (len(params) == 1 and isinstance(params[0], dict)
|
||||
and '__method__' in params[0]):
|
||||
return params[0]
|
||||
ret = params[0].copy()
|
||||
del ret['__method__']
|
||||
return ret
|
||||
|
||||
# otherwise sort out the legacy signatures
|
||||
args, kwargs = koji.decode_args(*params)
|
||||
|
|
@ -279,6 +280,9 @@ LEGACY_SIGNATURES = {
|
|||
'restartHosts' : [
|
||||
[[], None, None, None],
|
||||
],
|
||||
'runroot' : [
|
||||
[['root', 'arch', 'command', 'keep', 'packages', 'mounts', 'repo_id', 'skip_setarch', 'weight', 'upload_logs', 'new_chroot'], None, None, (False, [], [], None, False, None, None, False)],
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,25 @@
|
|||
|
||||
"""Test argspec functions"""
|
||||
|
||||
import koji.tasks
|
||||
import inspect
|
||||
import os.path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import koji.tasks
|
||||
|
||||
|
||||
# jump through hoops to import kojid
|
||||
KOJID_FILENAME = os.path.dirname(__file__) + "/../builder/kojid"
|
||||
if sys.version_info[0] >= 3:
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location("kojid", KOJID_FILENAME)
|
||||
kojid = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(kojid)
|
||||
else:
|
||||
import imp
|
||||
kojid = imp.load_source('koji_kojid', KOJID_FILENAME)
|
||||
|
||||
|
||||
class ParseTaskParamsCase(unittest.TestCase):
|
||||
"""Main test case container"""
|
||||
|
|
@ -12,12 +28,44 @@ class ParseTaskParamsCase(unittest.TestCase):
|
|||
def test_parse_task_params(self):
|
||||
"""Test parse_task_params"""
|
||||
|
||||
# Start simple
|
||||
# simple case
|
||||
ret = koji.tasks.parse_task_params('sleep', [4])
|
||||
self.assertEqual(ret, {'n':4})
|
||||
|
||||
# bad args
|
||||
with self.assertRaises(koji.ParameterError):
|
||||
koji.tasks.parse_task_params('sleep', [4, 5])
|
||||
|
||||
# bad method
|
||||
with self.assertRaises(TypeError):
|
||||
koji.tasks.parse_task_params('MISSINGMETHOD', [1,2,3])
|
||||
|
||||
# new style
|
||||
params = {'__method__': 'hello', 'n': 1}
|
||||
ret = koji.tasks.parse_task_params('hello', [params])
|
||||
del params['__method__']
|
||||
self.assertEqual(ret, params)
|
||||
self.assertIsNot(ret, params)
|
||||
# ^data should be copied
|
||||
|
||||
|
||||
def test_legacy_data(self):
|
||||
for method in koji.tasks.LEGACY_SIGNATURES:
|
||||
for mod in kojid, koji.tasks:
|
||||
h_class = getattr(mod, method, None)
|
||||
if h_class:
|
||||
break
|
||||
else:
|
||||
continue
|
||||
|
||||
spec = inspect.getargspec(h_class.handler)
|
||||
# unbound method, so strip "self"
|
||||
spec.args.pop(0)
|
||||
|
||||
# for the methods we have, at least one of the signatures should
|
||||
# match
|
||||
self.assertIn(argspec, koji.tasks.LEGACY_SIGNATURES[method])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue