aboutsummaryrefslogtreecommitdiffstats
path: root/onap-client
diff options
context:
space:
mode:
Diffstat (limited to 'onap-client')
-rw-r--r--onap-client/onap_client/util.py41
-rw-r--r--onap-client/setup.py2
-rw-r--r--onap-client/tox.ini3
3 files changed, 35 insertions, 11 deletions
diff --git a/onap-client/onap_client/util.py b/onap-client/onap_client/util.py
index 4c8043a..2a9e3e7 100644
--- a/onap-client/onap_client/util.py
+++ b/onap-client/onap_client/util.py
@@ -34,8 +34,8 @@
# limitations under the License.
#
# ============LICENSE_END============================================
-
import json
+import inspect
from prettytable import PrettyTable
@@ -59,10 +59,11 @@ def utility_cli(onap_client, cli_arguments):
return
if callable(functions):
- if functions.__code__.co_argcount != len(cli_arguments):
+ cf = CallableFunction(functions)
+ if cf.required_arg_count != len(cli_arguments):
print(
"Function requires {} arguments, but {} were passed. Try --help.".format(
- functions.__code__.co_argcount, len(cli_arguments)
+ cf.required_arg_count, len(cli_arguments)
)
)
return
@@ -99,14 +100,16 @@ def get_actions(functions):
actions["--help"] = ("", "")
if isinstance(functions, dict):
for k, v in functions.items():
+ cf = CallableFunction(v)
actions[convert_to_dash(k)] = (
- v.__doc__,
- list(v.__code__.co_varnames[: v.__code__.co_argcount]),
+ cf.doc_string,
+ cf.required_arguments,
)
elif callable(functions):
- actions[convert_to_dash(functions.__name__)] = (
- functions.__doc__,
- list(functions.__code__.co_varnames[: functions.__code__.co_argcount]),
+ cf = CallableFunction(functions)
+ actions[convert_to_dash(cf.name)] = (
+ cf.doc_string,
+ cf.required_arguments,
)
return actions
@@ -138,3 +141,25 @@ def help_table(actions):
def utility(func):
func.utility_function = True
return func
+
+
+class CallableFunction:
+ def __init__(self, function):
+ self.function = function
+ self.required_arguments = []
+
+ for param in inspect.signature(self.function).parameters.values():
+ if param.default == param.empty:
+ self.required_arguments.append(param.name)
+
+ @property
+ def required_arg_count(self):
+ return len(self.required_arguments)
+
+ @property
+ def doc_string(self):
+ return self.function.__doc__
+
+ @property
+ def name(self):
+ return self.function.__name__
diff --git a/onap-client/setup.py b/onap-client/setup.py
index 6c25765..2f0a0fe 100644
--- a/onap-client/setup.py
+++ b/onap-client/setup.py
@@ -47,7 +47,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="onap-client",
- version="1.0.0",
+ version="1.0.1",
author="Steven Stark",
author_email="steven.stark@att.com",
description="Python API wrapper for ONAP applications",
diff --git a/onap-client/tox.ini b/onap-client/tox.ini
index 621da2c..f9f3292 100644
--- a/onap-client/tox.ini
+++ b/onap-client/tox.ini
@@ -55,8 +55,7 @@ commands =
pip install . --upgrade
flake8 onap_client
bandit -c bandit.yaml -r onap_client -x ./.tox/**,./venv-tox/**
- pytest --cov=onap_client -s
- coverage xml
+ pytest --cov=onap_client --junitxml=junit/test-results.xml --cov-report=xml --cov-report=html -s
[flake8]
ignore = W391, W503, E501