From caaa9ea88d163dc089c422d511c48ca93e9261f1 Mon Sep 17 00:00:00 2001 From: zhurong Date: Sat, 6 Oct 2018 11:46:39 +0800 Subject: [PATCH] murano-dashbord python3 fix and use standard cover tox env Change-Id: I1d68ca7cbe325425cd1c05ff3101f19d3cb50b0a --- lower-constraints.txt | 1 + muranodashboard/tests/functional/base.py | 2 +- .../tests/functional/sanity_check.py | 8 +- muranodashboard/tests/functional/utils.py | 2 +- requirements.txt | 1 + tools/cover.sh | 90 ------------------- tox.ini | 7 +- 7 files changed, 14 insertions(+), 97 deletions(-) delete mode 100755 tools/cover.sh diff --git a/lower-constraints.txt b/lower-constraints.txt index dd52c9d28..86fb9363e 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -20,6 +20,7 @@ Django==1.11 django-appconf==1.0.2 django-babel==0.6.2 django-compressor==2.0 +django-floppyforms==1.7.0 django-formtools==2.0 django-nose==1.4.4 django-pyscss==2.0.2 diff --git a/muranodashboard/tests/functional/base.py b/muranodashboard/tests/functional/base.py index 635f6af33..4de77a838 100644 --- a/muranodashboard/tests/functional/base.py +++ b/muranodashboard/tests/functional/base.py @@ -35,7 +35,7 @@ import selenium.webdriver.common.by as by from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import ui -import config.config as cfg +from muranodashboard.tests.functional.config import config as cfg from muranodashboard.tests.functional import consts from muranodashboard.tests.functional import utils diff --git a/muranodashboard/tests/functional/sanity_check.py b/muranodashboard/tests/functional/sanity_check.py index fd814c154..10a963850 100644 --- a/muranodashboard/tests/functional/sanity_check.py +++ b/muranodashboard/tests/functional/sanity_check.py @@ -10,12 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. +from http.server import BaseHTTPRequestHandler import multiprocessing import os import re import shutil -import SimpleHTTPServer -import SocketServer +import socketserver import tempfile import time import unittest @@ -2765,10 +2765,10 @@ class TestSuiteRepository(base.PackageTestCase): self.serve_dir = tempfile.mkdtemp(suffix="repo") def serve_function(): - class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler): + class Handler(BaseHTTPRequestHandler): pass os.chdir(self.serve_dir) - httpd = SocketServer.TCPServer( + httpd = socketserver.TCPServer( ("0.0.0.0", 8099), Handler, bind_and_activate=False) httpd.allow_reuse_address = True diff --git a/muranodashboard/tests/functional/utils.py b/muranodashboard/tests/functional/utils.py index c61c51e9d..2d9c8ce9a 100644 --- a/muranodashboard/tests/functional/utils.py +++ b/muranodashboard/tests/functional/utils.py @@ -19,7 +19,7 @@ import zipfile from oslo_log import log from selenium.webdriver.support import wait -import config.config as cfg +from muranodashboard.tests.functional.config import config as cfg from muranodashboard.tests.functional import consts log = log.getLogger(__name__).logger diff --git a/requirements.txt b/requirements.txt index bd2510896..c6fc33b32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ pytz>=2013.6 # MIT PyYAML>=3.12 # MIT yaql>=1.1.3 # Apache 2.0 License castellan>=0.18.0 # Apache-2.0 +django-floppyforms>=1.7.0,<2 # BSD oslo.log>=3.36.0 # Apache-2.0 semantic-version>=2.3.1 # BSD diff --git a/tools/cover.sh b/tools/cover.sh deleted file mode 100755 index efcdc2cb4..000000000 --- a/tools/cover.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash -# -# Copyright 2016: Mirantis Inc. -# All Rights Reserved. -# -# 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. - -set -x - -ALLOWED_EXTRA_MISSING=4 - -show_diff () { - head -1 $1 - diff -U 0 $1 $2 | sed 1,2d -} - -# Stash uncommitted changes, checkout master and save coverage report -uncommitted=$(git status --porcelain | grep -v "^??") -[[ -n $uncommitted ]] && git stash > /dev/null -git checkout HEAD^ - -baseline_report=$(mktemp -t murano_dashboard_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete -echo $(which manage.py) -python manage.py test muranodashboard \ ---settings=muranodashboard.tests.settings \ ---cover-erase --with-coverage --cover-html --cover-inclusive -coverage report > $baseline_report -baseline_missing=$(awk 'END { print $3 }' $baseline_report) - -# Checkout back and unstash uncommitted changes (if any) -git checkout - -[[ -n $uncommitted ]] && git stash pop > /dev/null - -# Generate and save coverage report -current_report=$(mktemp -t murano_dashboard_coverageXXXXXXX) -find . -type f -name "*.pyc" -delete -echo $(which manage.py) -python manage.py test muranodashboard \ ---settings=muranodashboard.tests.settings \ ---cover-erase --with-coverage --cover-html --cover-inclusive -coverage report > $current_report -current_missing=$(awk 'END { print $3 }' $current_report) - -baseline_percentage=$(awk 'END { print $4 }' $baseline_report) -current_percentage=$(awk 'END { print $4 }' $current_report) -# Show coverage details -allowed_missing=$((baseline_missing+ALLOWED_EXTRA_MISSING)) - -echo "Baseline report:" -echo "$(cat ${baseline_report})" -echo "Proposed change report:" -echo "$(cat ${current_report})" -echo "" -echo "" -echo "Allowed to introduce missing lines : ${ALLOWED_EXTRA_MISSING}" -echo "Missing lines in master : ${baseline_missing}" -echo "Missing lines in proposed change : ${current_missing}" -echo "Current percentage : ${baseline_percentage}" -echo "Proposed change percentage : ${current_percentage}" - -if [ $allowed_missing -gt $current_missing ]; -then - if [ $baseline_missing -lt $current_missing ]; - then - show_diff $baseline_report $current_report - echo "I believe you can cover all your code with 100% coverage!" - else - echo "Thank you! You are awesome! Keep writing unit tests! :)" - fi - exit_code=0 -else - show_diff $baseline_report $current_report - echo "Please write more unit tests, we should keep our test coverage :( " - exit_code=1 -fi - -rm $baseline_report $current_report -set +x -exit $exit_code diff --git a/tox.ini b/tox.ini index bb0c1acb2..42908d05b 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,12 @@ commands = {posargs} [testenv:cover] basepython = python3 -commands = {toxinidir}/tools/cover.sh {posargs} +commands = + coverage erase + coverage run -a {toxinidir}/manage.py test muranodashboard --settings=muranodashboard.tests.settings + coverage html -d cover + coverage xml -o cover/coverage.xml + coverage report [testenv:pyflakes] deps = flake8