aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstark, steven <steven.stark@att.com>2020-09-18 10:10:50 -0700
committerstark, steven <steven.stark@att.com>2020-09-18 10:45:37 -0700
commitb5b81c492ab382fc1014f92e7daad6fdb97377af (patch)
tree29ed20e8a9f59a729b5f537023a099320f7a532b
parent35375724d9657de99adb8e530e1be21305555a40 (diff)
[VVP] fixing utility cli
Issue-ID: VVP-469 Signed-off-by: stark, steven <steven.stark@att.com> Change-Id: I4f6d77ca0ac8165b1020bd15b9c9e2cff7f7150b
-rw-r--r--.gitignore2
-rw-r--r--onap-client/onap_client/util.py41
-rw-r--r--onap-client/setup.py2
-rw-r--r--onap-client/tox.ini3
4 files changed, 37 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 8452818..5b124b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@
*pytest_cache*
.coverage
coverage.xml
+*junit*
+*htmlcov*
build
dist
*egg-info*
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