From e11be5dc15e6800ed6111b7773b9e44571343207 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Thu, 21 Sep 2017 12:19:32 -0400 Subject: Fix tox to give more accurate coverage reports * Also attempted to get sonar working * Fixed minor things along the way Change-Id: I434c0d791140e75cd5997be0cc3fefce7ccc292f Issue-Id: DCAEGEN2-60 Signed-off-by: Michael Hwang --- python-discovery-client/.coveragerc | 21 +++++++++++++++++++++ .../discovery_client/discovery.py | 4 +--- python-discovery-client/pom.xml | 16 +++++----------- python-discovery-client/tests/test_discovery.py | 6 +++--- python-discovery-client/tox.ini | 3 +-- python-dockering/.coveragerc | 21 +++++++++++++++++++++ python-dockering/dockering/core.py | 2 +- python-dockering/pom.xml | 18 ++++++------------ python-dockering/tox.ini | 3 +-- 9 files changed, 60 insertions(+), 34 deletions(-) create mode 100644 python-discovery-client/.coveragerc create mode 100644 python-dockering/.coveragerc diff --git a/python-discovery-client/.coveragerc b/python-discovery-client/.coveragerc new file mode 100644 index 0000000..088c2da --- /dev/null +++ b/python-discovery-client/.coveragerc @@ -0,0 +1,21 @@ +# .coveragerc to control coverage.py +[run] +branch = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/python-discovery-client/discovery_client/discovery.py b/python-discovery-client/discovery_client/discovery.py index 180e933..51b5897 100644 --- a/python-discovery-client/discovery_client/discovery.py +++ b/python-discovery-client/discovery_client/discovery.py @@ -222,9 +222,7 @@ def _resolve_name(lookup_func, service_name): # TODO: Need a better way to identify CDAP apps. Really need to make this # better. - if "platform-" in service_name: - return "{0}:{1}".format(ip, port) - elif "cdap" in service_name: + if "cdap" in service_name: redirectish_url = "http://{0}:{1}/application/{2}".format(ip, port, service_name) diff --git a/python-discovery-client/pom.xml b/python-discovery-client/pom.xml index 39b5da5..d6a87f8 100644 --- a/python-discovery-client/pom.xml +++ b/python-discovery-client/pom.xml @@ -26,27 +26,21 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. 1.0.0-SNAPSHOT org.onap.dcaegen2.utils - onap-dcae-discovery-client + python-discovery-client dcaegen2-utils-python-discovery-client 1.0.0-SNAPSHOT http://maven.apache.org UTF-8 + . - - - - + xunit-results.xml + coverage.xml py Python **/*.py - - + tests/* ${project.artifactId}-${project.version} diff --git a/python-discovery-client/tests/test_discovery.py b/python-discovery-client/tests/test_discovery.py index 00f1b5e..36817af 100644 --- a/python-discovery-client/tests/test_discovery.py +++ b/python-discovery-client/tests/test_discovery.py @@ -17,7 +17,7 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -import json, logging +import six, json, logging # http://stackoverflow.com/questions/9623114/check-if-two-unordered-lists-are-equal from collections import Counter from functools import partial @@ -65,8 +65,8 @@ def test_get_connection_types(): assert Counter(expected) == Counter(actual) # Force strings to be unicode, test for Python2 compatibility - config = { "x": "say something".decode("utf-8"), "y": 123, - "z": "{{some-analytics}}".decode("utf-8") } + config = { "x": six.u("say something"), "y": 123, + "z": six.u("{{some-analytics}}") } expected = [(("z", ), "some-analytics"), ] actual = dis._get_connection_types(config) assert Counter(expected) == Counter(actual) diff --git a/python-discovery-client/tox.ini b/python-discovery-client/tox.ini index 987b009..5b492c9 100644 --- a/python-discovery-client/tox.ini +++ b/python-discovery-client/tox.ini @@ -4,8 +4,7 @@ envlist = py27,py35 [testenv] deps= - -rrequirements.txt pytest coverage pytest-cov -commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir} --cov-report=xml +commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir}/discovery_client --cov-report=xml diff --git a/python-dockering/.coveragerc b/python-dockering/.coveragerc new file mode 100644 index 0000000..088c2da --- /dev/null +++ b/python-dockering/.coveragerc @@ -0,0 +1,21 @@ +# .coveragerc to control coverage.py +[run] +branch = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/python-dockering/dockering/core.py b/python-dockering/dockering/core.py index 9ef1ae3..d82e346 100644 --- a/python-dockering/dockering/core.py +++ b/python-dockering/dockering/core.py @@ -104,7 +104,7 @@ def start_container(client, container): # TODO: Have logic to inspect response and through NonRecoverableError # when start fails. Docker-py docs don't quickly tell me what the # response looks like. - response = client.start(container=container["Id"]) + client.start(container=container["Id"]) utils.logger.info("Container started: {0}".format(container["Id"])) # TODO: Maybe check stats? diff --git a/python-dockering/pom.xml b/python-dockering/pom.xml index afc39a8..0933bcb 100644 --- a/python-dockering/pom.xml +++ b/python-dockering/pom.xml @@ -26,27 +26,21 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. 1.0.0-SNAPSHOT org.onap.dcaegen2.utils - onap-dcae-dockering + python-dockering dcaegen2-utils-python-dockering 1.0.0-SNAPSHOT http://maven.apache.org UTF-8 - true - - - - + + . + xunit-results.xml + coverage.xml py Python **/*.py - - + tests/* ${project.artifactId}-${project.version} diff --git a/python-dockering/tox.ini b/python-dockering/tox.ini index 987b009..280cf78 100644 --- a/python-dockering/tox.ini +++ b/python-dockering/tox.ini @@ -4,8 +4,7 @@ envlist = py27,py35 [testenv] deps= - -rrequirements.txt pytest coverage pytest-cov -commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir} --cov-report=xml +commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir}/dockering --cov-report=xml -- cgit 1.2.3-korg