From d4af56d4c2f67a1285da783764f20a0c1c546592 Mon Sep 17 00:00:00 2001 From: umry8364 Date: Wed, 28 Aug 2019 12:06:30 +0200 Subject: Add tox it would create virtualenv to - run tests in python2.7 and 3 - perform linting operations (flake8, pylint) Issue-ID: INT-1228 Change-Id: I451e1108285f6ebffc650bf3de4f175594ec796d Signed-off-by: umry8364 Signed-off-by: DR695H --- robotframework-onap/.gitignore | 1 + robotframework-onap/ONAPLibrary/BaseAAIKeywords.py | 4 +- .../ONAPLibrary/CloudConfigSOKeywords.py | 2 +- robotframework-onap/ONAPLibrary/KafkaKeywords.py | 1 - robotframework-onap/README.TXT | 17 +++++- robotframework-onap/requirements.txt | 19 ++++++ robotframework-onap/setup.cfg | 26 ++++++-- robotframework-onap/setup.py | 69 +++++----------------- robotframework-onap/test-requirements.txt | 14 +++++ .../tests/vcpeutils/SoUtils_test.py | 9 ++- robotframework-onap/tox.ini | 46 ++++++++++++--- 11 files changed, 133 insertions(+), 75 deletions(-) create mode 100644 robotframework-onap/requirements.txt create mode 100644 robotframework-onap/test-requirements.txt (limited to 'robotframework-onap') diff --git a/robotframework-onap/.gitignore b/robotframework-onap/.gitignore index 3f4c0a8..d754a0e 100644 --- a/robotframework-onap/.gitignore +++ b/robotframework-onap/.gitignore @@ -262,6 +262,7 @@ coverage.xml *.cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo diff --git a/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py b/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py index 0b312df..762a2ee 100644 --- a/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py +++ b/robotframework-onap/ONAPLibrary/BaseAAIKeywords.py @@ -80,7 +80,7 @@ class BaseAAIKeywords(object): def find_node(self, search_node_type, key, node_uuid, auth=None, client_certs=None): data_path = '/aai/v11/search/nodes-query?search-node-type={0}&filter={1}:EQUALS:{2}'.format( search_node_type, key, node_uuid) - resp = self.reqs.get_request("aai", self.aai_endpoint, data_path, accept="application/json", auth=auth, - client_certs=client_certs) + resp = self.reqs.get_request(alias="aai", endpoint=self.aai_endpoint, data_path=data_path, + accept="application/json", auth=auth, client_certs=client_certs) response = resp.json() return 'result-data' in response diff --git a/robotframework-onap/ONAPLibrary/CloudConfigSOKeywords.py b/robotframework-onap/ONAPLibrary/CloudConfigSOKeywords.py index fb8808d..fe487a2 100644 --- a/robotframework-onap/ONAPLibrary/CloudConfigSOKeywords.py +++ b/robotframework-onap/ONAPLibrary/CloudConfigSOKeywords.py @@ -31,7 +31,7 @@ class CloudConfigSOKeywords(object): @keyword def get_cloud_configuration(self, endpoint, data_path, site_name, auth=None): """Gets cloud configuration in SO""" - return self.reqs.get_request("so", endpoint, data_path + "/" + site_name, auth=auth) + return self.reqs.get_request(alias="so", endpoint=endpoint, data_path=data_path + "/" + site_name, auth=auth) @keyword def create_cloud_configuration(self, endpoint, data_path, templates_folder, template, arguments, auth=None): diff --git a/robotframework-onap/ONAPLibrary/KafkaKeywords.py b/robotframework-onap/ONAPLibrary/KafkaKeywords.py index 44ffb49..329729b 100644 --- a/robotframework-onap/ONAPLibrary/KafkaKeywords.py +++ b/robotframework-onap/ONAPLibrary/KafkaKeywords.py @@ -105,5 +105,4 @@ class KafkaKeywords(object): else: for tp in partitions: consumer.seek(tp, offset - 1) - return consumer diff --git a/robotframework-onap/README.TXT b/robotframework-onap/README.TXT index 9989546..f5b20c9 100644 --- a/robotframework-onap/README.TXT +++ b/robotframework-onap/README.TXT @@ -1,6 +1,19 @@ Robotframework-ONAP ======================= -Robot framework plugin to work with onap +Robot framework plugin to work with ONAP. +It provides 3 packages: -to install locally, checkout this repo and then run 'pip install -e .' in the root \ No newline at end of file +* ONAPLibrary +* vcpeutils + +A tox file has been created with the following targets: + +* py3: run unit tests using python3 + provide unit test coverage information +* py27: run unit tests using python2.7 +* pep8: python linting with flake8 (python3) +* pylint: python linting with pylint (python3), pylint provide a rate estimation + +You can run all the target one after the other by typing `tox` from +robotframework-onap directory. Or if you want to specify a single target type +`tox -epep8` diff --git a/robotframework-onap/requirements.txt b/robotframework-onap/requirements.txt new file mode 100644 index 0000000..d82ec25 --- /dev/null +++ b/robotframework-onap/requirements.txt @@ -0,0 +1,19 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +pbr!=2.1.0 # Apache-2.0 +deepdiff +dnspython +future +jinja2 +jsonpath-rw +kafka-python +paramiko +protobuf +pyyaml +requests +robotframework +robotframework-requests +robotlibcore-temp +six +urllib3 diff --git a/robotframework-onap/setup.cfg b/robotframework-onap/setup.cfg index c34b498..46d7b48 100644 --- a/robotframework-onap/setup.cfg +++ b/robotframework-onap/setup.cfg @@ -1,5 +1,21 @@ -[bdist_wheel] -# This flag says that the code is written to work on both Python 2 and Python -# 3. If at all possible, it is good practice to do this. If you cannot, you -# will need to generate wheels for each Python version that you support. -universal=1 \ No newline at end of file +[metadata] +name = robotframework-onap +version = 0.5 +home-page = https://github.com/onap/testsuite-python-testing-utils +classifier = + Development Status :: 4 - Beta + Environment :: Plugins + Framework :: Robot Framework + Framework :: Robot Framework :: Library + Intended Audience :: Developers + Intended Audience :: Information Technology + License :: OSI Approved :: Apache Software License + Operating System :: OS Independent + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3.7 + +[files] +packages = vcpeutils,ONAPLibrary + +[wheel] +universal = 1 diff --git a/robotframework-onap/setup.py b/robotframework-onap/setup.py index f5973df..566d844 100644 --- a/robotframework-onap/setup.py +++ b/robotframework-onap/setup.py @@ -1,66 +1,29 @@ -# Copyright 2019 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2013 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. # See the License for the specific language governing permissions and # limitations under the License. +# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT +import setuptools -from setuptools import setup +# In python < 2.7.4, a lazy loading of package `pbr` will break +# setuptools if some other modules registered functions in `atexit`. +# solution from: http://bugs.python.org/issue15881#msg170215 +try: + import multiprocessing # noqa +except ImportError: + pass -setup( - name='robotframework-onap', # This is the name of your PyPI-package. - keywords=["utils", "robotframework", "testing", "onap"], - version='0.5', # Update the version number for new releases - license="Apache 2.0", - description='Scripts written to be used during robot framework testing', # Info about script - long_description="python-package that provides convenience methods to make certain tasks in robot framework easier." - "since this uses robot framework internal libraries or may in the future, it is not meant as a" - "general purpose library", - url="https://github.com/onap/testsuite-python-testing-utils", - platforms=['all'], - install_requires=[ - 'deepdiff', - 'dnspython', - 'future', - 'jinja2', - 'jsonpath-rw', - 'kafka-python', - 'paramiko', - 'protobuf', - 'pyyaml', - 'requests', - 'robotframework', - 'robotframework-requests', - 'robotlibcore-temp', - 'six', - 'urllib3' - ], # what we need to run library - packages=['vcpeutils', 'ONAPLibrary'], # The name of your scripts package - package_dir={ - 'vcpeutils': 'vcpeutils', - 'ONAPLibrary': 'ONAPLibrary' - }, # The location of your scipts package - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.7', - 'Environment :: Plugins', - 'Framework :: Robot Framework', - 'Framework :: Robot Framework :: Library', - 'License :: OSI Approved :: Apache Software License' - ], - test_suite="tests.runner", - tests_require=[ - 'mock', - 'requests-mock' - ] -) +setuptools.setup( + setup_requires=['pbr>=2.0.0'], + pbr=True) diff --git a/robotframework-onap/test-requirements.txt b/robotframework-onap/test-requirements.txt new file mode 100644 index 0000000..be413e1 --- /dev/null +++ b/robotframework-onap/test-requirements.txt @@ -0,0 +1,14 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. +coverage!=4.4,>=4.0 # Apache-2.0 +mock>=2.0 # BSD +nose # LGPL +flake8 # MIT +pylint # GPLv2 +requests +requests-mock +pytest +pytest-cov +pytest-mock +pytest-runner diff --git a/robotframework-onap/tests/vcpeutils/SoUtils_test.py b/robotframework-onap/tests/vcpeutils/SoUtils_test.py index 22afed6..cce3936 100644 --- a/robotframework-onap/tests/vcpeutils/SoUtils_test.py +++ b/robotframework-onap/tests/vcpeutils/SoUtils_test.py @@ -1,14 +1,17 @@ from unittest import TestCase -from vcpeutils.SoUtils import * +from vcpeutils.SoUtils import SoUtils class SoUtilsTest(TestCase): - def test(self): input_dict = dict() SoUtils.add_related_instance(input_dict, "test", "test2") results = dict() results['relatedInstanceList'] = [{"relatedInstance": {"instanceId": "test", "modelInfo": "test2"}}] - self.assertDictContainsSubset(results, input_dict) + self.assertEqual(results, self.extract_dict_a_from_b(results,input_dict)) + + @staticmethod + def extract_dict_a_from_b(a, b): + return dict([(k, b[k]) for k in a.keys() if k in b.keys()]) diff --git a/robotframework-onap/tox.ini b/robotframework-onap/tox.ini index bd1bff5..92f6317 100644 --- a/robotframework-onap/tox.ini +++ b/robotframework-onap/tox.ini @@ -1,11 +1,41 @@ -# Tox (https://tox.readthedocs.io/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - [tox] -envlist = py27, py3 +envlist = py3,pep8,pylint,py27 +modules = + ONAPLibrary + vcpeutils [testenv] -commands = {envpython} setup.py test -deps = \ No newline at end of file +usedevelop = True +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +install_command = pip install {opts} {packages} + +[testenv:pep8] +basepython = python3 +changedir = {toxinidir} +commands = + flake8 --max-line-length 120 {[tox]modules} + +[testenv:pylint] +basepython = python3 +deps = + pyflakes + pylint +commands = + pylint -f parseable --ignore-imports=y --disable=locally-disabled --max-line-length 120 --exit-zero -ry {[tox]modules} + +[testenv:py3] +basepython = python3 +commands = nosetests --with-xunit \ + --all-modules \ + --with-coverage \ + --cover-tests \ + --cover-package=. \ + --cover-xml \ + --cover-html \ + tests + +[testenv:py27] +basepython = python2.7 +commands = nosetests --all-modules tests -- cgit 1.2.3-korg