Update get_arg_list_as_str to skip func params
This patch updates inspect_utils.get_arg_list_as_str so that it skips handling parameters that can't be JSON serialized. One example of this would be a function parameter (func=time.sleep). Some of the OpenStack clients have functions that would be useful to expose by simply relying on the default settings for these parameters. Change-Id: Id1cc8e79db3001ffec5066b2e81ec2e5119e875a Closes-bug: #1584366
This commit is contained in:
parent
b9dafd1e1a
commit
7712cc3138
@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import time
|
||||
|
||||
from mistral.actions import std_actions
|
||||
from mistral.tests.unit import base
|
||||
from mistral.utils import inspect_utils as i_u
|
||||
@ -37,3 +39,11 @@ class InspectUtilsTest(base.BaseTest):
|
||||
parameters_str = i_u.get_arg_list_as_str(clazz.__init__)
|
||||
|
||||
self.assertEqual("wf_ex, task_spec, ctx", parameters_str)
|
||||
|
||||
def test_get_parameters_str_with_function_parameter(self):
|
||||
|
||||
def test_func(foo, bar=None, test_func=time.sleep):
|
||||
pass
|
||||
|
||||
parameters_str = i_u.get_arg_list_as_str(test_func)
|
||||
self.assertEqual("foo, bar=null", parameters_str)
|
||||
|
@ -66,12 +66,15 @@ def get_arg_list_as_str(func):
|
||||
|
||||
for index, default in enumerate(args):
|
||||
if index >= diff_args_defs:
|
||||
arg_str_list.append(
|
||||
"%s=%s" % (
|
||||
args[index],
|
||||
json.dumps(defs[index - diff_args_defs])
|
||||
try:
|
||||
arg_str_list.append(
|
||||
"%s=%s" % (
|
||||
args[index],
|
||||
json.dumps(defs[index - diff_args_defs])
|
||||
)
|
||||
)
|
||||
)
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
arg_str_list.append("%s" % args[index])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user