VOL-1448: Added unit test and unit-test-with-coverage support
Change-Id: Ia3c1c3b18b0871b9a796f6eb62e9f2bb14b33ab8
diff --git a/Makefile b/Makefile
index 72c396e..766e07d 100644
--- a/Makefile
+++ b/Makefile
@@ -63,7 +63,8 @@
@echo "dist : Build the protos and create the python package"
@echo "docker_base_img : Build a base docker image with a modern version of pip and requirements.txt installed"
@echo "docker_image : Build a docker image with pyvoltha installed"
- @echo "test : Run all unit test"
+ @echo "utest : Run all unit test"
+ @echo "utest-with-coverage : Run all unit test with coverage reporting"
@echo "clean : Remove files created by the build and tests"
@echo "distclean : Remove venv directory"
@echo "help : Print this help"
@@ -102,7 +103,7 @@
build: protos
protos:
- make -C pyvoltha/protos
+ @ . ${VENVDIR}/bin/activate && make -C pyvoltha/protos
dist: venv protos
@ echo "Creating PyPi artifacts"
@@ -124,23 +125,24 @@
test: venv protos
@ echo "Executing all unit tests"
- @ . ${VENVDIR}/bin/activate && tox
-# @ . ${VENVDIR}/bin/activate && make -C test utest
+ @ tox -- --with-xunit
-COVERAGE_OPTS=--with-xcoverage --with-xunit --cover-package=voltha,common,ofagent --cover-html\
- --cover-html-dir=tmp/cover
+COVERAGE_OPTS=--with-coverage --with-xunit --cover-branches --cover-html --cover-html-dir=tmp/cover \
+ --cover-package=pyvoltha.adapters,pyvoltha.common
utest-with-coverage: venv protos
@ echo "Executing all unit tests and producing coverage results"
- @ . ${VENVDIR}/bin/activate && nosetests $(COVERAGE_OPTS) pyvoltha/tests/utests
+ @ tox -- $(COVERAGE_OPTS)
clean:
find . -name '*.pyc' | xargs rm -f
find . -name 'coverage.xml' | xargs rm -f
find . -name 'nosetests.xml' | xargs rm -f
make -C pyvoltha/protos clean
- rm -rf PyVoltha.egg-info
+ rm -rf pyvoltha.egg-info
rm -rf dist
+ rm -rf .tox
+ rm -rf test/unit/tmp
distclean: clean
rm -rf ${VENVDIR}
diff --git a/__init__.py b/__init__.py
deleted file mode 100644
index cfcdc97..0000000
--- a/__init__.py
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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
-#
-# 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.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
\ No newline at end of file
diff --git a/env.sh b/env.sh
index 98f1d24..aeb4a1f 100644
--- a/env.sh
+++ b/env.sh
@@ -26,4 +26,4 @@
. ${VENVDIR}/bin/activate
# add top-level voltha dir to pythonpath
-export PYTHONPATH=${VOLTHA_BASE}/${VENVDIR}/lib/python2.7/site-packages:${PYTHONPATH}:${VOLTHA_BASE}:${VOLTHA_BASE}/protos/third_party
+export PYTHONPATH=${VOLTHA_BASE}/${VENVDIR}/lib/python2.7/site-packages:${VOLTHA_BASE}/pyvoltha:${VOLTHA_BASE}/pyvoltha/protos/third_party
diff --git a/pyvoltha/protos/Makefile b/pyvoltha/protos/Makefile
index 66115c5..e0cab35 100644
--- a/pyvoltha/protos/Makefile
+++ b/pyvoltha/protos/Makefile
@@ -44,7 +44,7 @@
google_api:
@echo "Building protocol buffer artifacts from third_party google api"
cd third_party ; \
- env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
+ env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc_tools.protoc \
-I. \
--python_out=. \
--grpc_python_out=. \
@@ -57,7 +57,7 @@
%_pb2.py: %.proto Makefile
@echo "Building protocol buffer artifacts from $<"
- env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc.tools.protoc \
+ env LD_LIBRARY_PATH=$(PROTOC_LIBDIR) python -m grpc_tools.protoc \
-I. \
-I./third_party \
--python_out=. \
@@ -82,7 +82,7 @@
install-protoc: $(PROTOC)
@echo "Downloading and installing protocol buffer support."
- @echo "Installation will require sodo priviledges"
+ @echo "Installation will require sudo privileges"
@echo "This will take a few minutes."
mkdir -p $(PROTOC_BUILD_TMP_DIR)
@echo "We ask for sudo credentials now so we can install at the end"; \
diff --git a/requirements.txt b/requirements.txt
index c666dea..205d524 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,8 +12,8 @@
fluent-logger==0.6.0
gevent==1.4.0
grpc==0.3.post19
-grpcio==1.3.5
-grpcio-tools==1.3.5
+grpcio==1.16.0
+grpcio-tools==1.16.0
hash_ring==1.3.1
hexdump==3.3
jinja2==2.8
@@ -28,7 +28,7 @@
pcapy==0.11.1
pep8==1.7.1
pep8-naming>=0.3.3
-protobuf==3.3.0
+protobuf==3.6.1
protobuf-to-dict==0.1.0
pyflakes==2.1.0
pylint==1.9.4
diff --git a/setup.py b/setup.py
index bd60cbc..293fd2e 100644
--- a/setup.py
+++ b/setup.py
@@ -57,7 +57,7 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
],
- packages=find_packages(exclude=['protos']),
+ packages=find_packages(exclude=['protos', 'test']),
install_requires=[required],
include_package_data=True,
dependency_links=["git+https://github.com/ciena/afkak.git#egg=afkak-3.0.0.dev20181106"]
diff --git a/test-requirements.txt b/test-requirements.txt
index aa45729..17efb24 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -6,4 +6,5 @@
sphinx>=1.8.1,<2.0.0
mock==2.0.0
nose-exclude==0.5.0
-nose-testconfig==0.10
\ No newline at end of file
+nose-testconfig==0.10
+coverage==4.5.2
\ No newline at end of file
diff --git a/test/unit/extensions/omci/mock/mock_adapter_agent.py b/test/unit/extensions/omci/mock/mock_adapter_agent.py
index 866eb67..ebe94e2 100644
--- a/test/unit/extensions/omci/mock/mock_adapter_agent.py
+++ b/test/unit/extensions/omci/mock/mock_adapter_agent.py
@@ -20,6 +20,7 @@
# from pyvoltha.protos.voltha_pb2 import VolthaInstance
# from pyvoltha.adapters.extensions.omci.omci_frame import OmciFrame
+
class MockProxyAddress(object):
def __init__(self, device_id, pon_id, onu_id):
self.device_id = device_id # Device ID of proxy (OLT)
@@ -44,6 +45,10 @@
class MockCore(object):
def __init__(self):
self.root = None # ConfigRoot(VolthaInstance())
+ if self.root is None:
+ from nose import SkipTest
+ msg = "TODO: Unit tests involving the kv-store are not yet supported by pyvoltha"
+ raise SkipTest(msg)
def get_proxy(self, path):
return self.root.get_proxy(path)
diff --git a/test/unit/extensions/omci/test_image_agent.py b/test/unit/extensions/omci/test_image_agent.py
index a801d0a..08f0f1e 100644
--- a/test/unit/extensions/omci/test_image_agent.py
+++ b/test/unit/extensions/omci/test_image_agent.py
@@ -29,7 +29,7 @@
from pyvoltha.protos.voltha_pb2 import ImageDownload
from pyvoltha.protos.device_pb2 import Device
-from tests.utests.voltha.extensions.omci.mock.mock_adapter_agent import MockAdapterAgent, MockCore
+from test.unit.extensions.omci.mock.mock_adapter_agent import MockAdapterAgent, MockCore
from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.internet.epollreactor import EPollReactor
diff --git a/test/unit/extensions/omci/test_omci_cc.py b/test/unit/extensions/omci/test_omci_cc.py
index 7c1491d..ced24b0 100644
--- a/test/unit/extensions/omci/test_omci_cc.py
+++ b/test/unit/extensions/omci/test_omci_cc.py
@@ -14,7 +14,7 @@
# limitations under the License.
#
import binascii
-from common.frameio.frameio import hexify
+from pyvoltha.adapters.common.frameio.frameio import hexify
from twisted.python.failure import Failure
from unittest import TestCase, main, skip
from mock.mock_adapter_agent import MockAdapterAgent
diff --git a/tox.ini b/tox.ini
index 97b442d..b32b8b6 100644
--- a/tox.ini
+++ b/tox.ini
@@ -44,7 +44,6 @@
[pylama:test/*]
ignore = C0111,R0201,R0903
-
[pytest]
passenv = {env:PYTEST_ARGS}
flags =-vvl {env:PYTEST_ARGS:}
@@ -53,7 +52,11 @@
test = py.test {[pytest]flags} {[pytest]unit_results}
with_metrics = {[pytest]test} {[cov]coverage}
+[nosetests]
+passenv =
+
[testenv]
+changedir = test/unit
basepython =
py27: python2.7
;py3: python3
@@ -62,7 +65,10 @@
;py3: {toxworkdir}/.py3
setenv =
COVERAGE_FILE = {envdir}/.coverage
+ PYTHONPATH = {toxinidir}:{toxinidir}/pyvoltha/protos/third_party
+
commands =
+ py27: nosetests {posargs}
; py3-test: {[pytest]with_metrics} test
; py3-no-coverage: {[pytest]test} test
; py3-unit: {[pytest]with_metrics} test/unit
@@ -72,12 +78,6 @@
; py3-analysis: black --check {[pylama]analysis_dirs}
; py3-black: black {[pylama]analysis_dirs}
; py3-docs: sphinx-build -b html docs docs_out
- py27-test: nosetests {posargs}
- py27-test: {[pytest]with_metrics} test
- py27-no-coverage: {[pytest]test} test
- py27-unit: {[pytest]with_metrics} test/unit
- py27-component: {[pytest]with_metrics} test/component
- py27-adhoc: {posargs: bash -c 'echo must provide posargs with "tox args -- posargs"'}
deps =
nose