[feat] adding-tox-testing

- tox commands
- docs update

Change-Id: Ie6caa498d6017822e095ee5b001124074e2755aa
This commit is contained in:
Alexis Rivera De La Torre 2017-08-10 01:22:21 +00:00
parent 978ab7481b
commit d17485f8b9
6 changed files with 65 additions and 34 deletions

View File

@ -109,7 +109,7 @@ class ChartBuilder(object):
try: try:
chart_yaml = dotify( chart_yaml = dotify(
yaml.load( yaml.safe_load(
open(os.path.join(self.source_directory, 'Chart.yaml')) open(os.path.join(self.source_directory, 'Chart.yaml'))
.read())) .read()))
except Exception: except Exception:

View File

@ -1,10 +1,25 @@
# Copyright 2017 The Armada 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.
from os import path
import os import os
import requests import requests
import shutil
import tarfile import tarfile
import tempfile import tempfile
import shutil
from git import Repo from git import Repo
from os import path
from ..exceptions import source_exceptions from ..exceptions import source_exceptions
@ -20,7 +35,7 @@ def git_clone(repo_url, branch='master'):
raise source_exceptions.GitLocationException(repo_url) raise source_exceptions.GitLocationException(repo_url)
os.environ['GIT_TERMINAL_PROMPT'] = '0' os.environ['GIT_TERMINAL_PROMPT'] = '0'
_tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp') _tmp_dir = tempfile.mkdtemp(prefix='armada')
try: try:
Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch}) Repo.clone_from(repo_url, _tmp_dir, **{'branch': branch})
@ -38,7 +53,7 @@ def download_tarball(tarball_url):
Downloads a tarball to /tmp and returns the path Downloads a tarball to /tmp and returns the path
''' '''
try: try:
tarball_filename = tempfile.mkstemp(prefix='armada', dir='/tmp')[1] tarball_filename = tempfile.mkstemp(prefix='armada')[1]
response = requests.get(tarball_url) response = requests.get(tarball_url)
with open(tarball_filename, 'wb') as f: with open(tarball_filename, 'wb') as f:
f.write(response.content) f.write(response.content)
@ -53,7 +68,7 @@ def extract_tarball(tarball_path):
if not path.exists(tarball_path): if not path.exists(tarball_path):
raise source_exceptions.InvalidPathException(tarball_path) raise source_exceptions.InvalidPathException(tarball_path)
_tmp_dir = tempfile.mkdtemp(prefix='armada', dir='/tmp') _tmp_dir = tempfile.mkdtemp(prefix='armada')
try: try:
file = tarfile.open(tarball_path) file = tarfile.open(tarball_path)

View File

@ -36,7 +36,17 @@ From the directory of the forked repository:
pip install -r requirements.txt pip install -r requirements.txt
pip install -r test-requirements.txt pip install -r test-requirements.txt
pip install -e .
pip install .
# Testing your armada code
# The tox command will execute lint, bandit, cover
tox
# For targeted test
tox -e pep8
tox -e bandit
tox -e cover
.. note:: .. note::

View File

@ -1,22 +1,5 @@
from setuptools.command.test import test as TestCommand
import sys
import setuptools import setuptools
class Tox(TestCommand):
"""Runs Tox comands"""
def finalize_options(self):
"""preps test suite"""
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
"""runs test suite"""
import tox
errcode = tox.cmdline(self.test_args)
sys.exit(errcode)
try: try:
import multiprocessing # noqa import multiprocessing # noqa
except ImportError: except ImportError:

View File

@ -10,3 +10,5 @@ nose==1.3.7
testtools==2.3.0 testtools==2.3.0
codecov codecov
mock mock
bandit
pytest==3.2.1

41
tox.ini
View File

@ -1,26 +1,47 @@
[tox] [tox]
envlist = py27 skipsdist = True
envlist = py27, pep8, coverage, bandit
[testenv] [testenv]
deps= deps=
-r{toxinidir}/requirements.txt -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt -r{toxinidir}/test-requirements.txt
setenv= setenv=
PYTHONWARNINGS=all VIRTUAL_ENV={envdir}
usedevelop = True
commands =
find . -type f -name "*.pyc" -delete
python -V
py.test -vvv -s --ignore=hapi
[testenv:docs] [testenv:docs]
commands = python setup.py build_sphinx commands =
python setup.py build_sphinx
[testenv:genconfig] [testenv:genconfig]
commands = oslo-config-generator --config-file=etc/armada/config-generator.conf commands =
oslo-config-generator --config-file=etc/armada/config-generator.conf
[testenv:lint] [testenv:pep8]
commands = flake8 . deps=
{[testenv]deps}
commands =
flake8 {posargs}
[testenv:testing] [testenv:bandit]
commands = nosetest -w armada deps = .[bandit]
commands =
bandit -r armada -x armada/tests -n 5
[flake8] #TODO: Remove E402 [testenv:coverage]
ignore=E302,H306,E402,W503 deps=
{[testenv]deps}
commands =
nosetests -w armada/tests/unit --cover-package=armada --with-coverage --cover-tests --exclude=.tox
[flake8]
filename= *.py
ignore = W503,E302
exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi exclude= .git, .idea, .tox, *.egg-info, *.eggs, bin, dist, hapi