Removing create_autospec and having salt.utils.args.argspec_report run against the _test_spec function directly. Depending on the python version, create_autospec gives different results and cause the test to fail. The test is now more accurate at testing the arguments for the function.

This commit is contained in:
Gareth J. Greenaway 2019-05-06 18:30:16 -07:00
parent cc7a0d1326
commit 8fdc48c0bd
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
2 changed files with 8 additions and 4 deletions

View file

@ -8,6 +8,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import copy
import fnmatch
import inspect
import logging
import re
import shlex
@ -20,6 +21,8 @@ import salt.utils.jid
import salt.utils.versions
import salt.utils.yaml
log = logging.getLogger(__name__)
if six.PY3:
KWARG_REGEX = re.compile(r'^([^\d\W][\w.-]*)=(?!=)(.*)$', re.UNICODE)

View file

@ -13,7 +13,6 @@ import salt.utils.args
# Import Salt Testing Libs
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
create_autospec,
DEFAULT,
NO_MOCK,
NO_MOCK_REASON,
@ -126,11 +125,13 @@ class ArgsTestCase(TestCase):
def _test_spec(arg1, arg2, kwarg1=None):
pass
sys_mock = create_autospec(_test_spec)
test_functions = {'test_module.test_spec': sys_mock}
test_functions = {'test_module.test_spec': _test_spec}
ret = salt.utils.args.argspec_report(test_functions, 'test_module.test_spec')
self.assertDictEqual(ret, {'test_module.test_spec':
{'kwargs': True, 'args': None, 'defaults': None, 'varargs': True}})
{'kwargs': None,
'args': ['arg1', 'arg2', 'kwarg1'],
'defaults': (None, ),
'varargs': None}})
def test_test_mode(self):
self.assertTrue(salt.utils.args.test_mode(test=True))