Merge ~jslarraz/review-tools:remove-redundant-tests into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Merged
Merged at revision: 995ce42ef81708f7807b4fb7e7c478a75ee9c093
Proposed branch: ~jslarraz/review-tools:remove-redundant-tests
Merge into: review-tools:master
Diff against target: 119 lines (+18/-54)
3 files modified
Makefile (+9/-15)
dev/null (+0/-28)
reviewtools/common.py (+9/-11)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466731@code.launchpad.net

Commit message

So make check were running unittest test once under unittest target and again under check-names just to collect check names. This change merges unittest and check-names targets so we run check-names essentially for free.

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

LGTM - nice cleanup!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/Makefile b/Makefile
index c76f2bf..523b0ac 100644
--- a/Makefile
+++ b/Makefile
@@ -63,21 +63,15 @@ flake8: clean
6363
64check-syntax: pylint flake864check-syntax: pylint flake8
6565
66.PHONY: check-names.list66TMP_DIR := $(shell mktemp -d)
67check-names.list:
68 (python3 collect-check-names-from-tests 2>&1 \
69 | grep 'CHECK|' | cut -d '|' -f 2- | egrep -v '(skeleton|some-check)' | LC_ALL=C sort \
70 | awk -F '|' '(l && $$1 != l1) {print l} {l1=$$1; l=$$0} END {print l}') > check-names.list
71
72check-names: check-names.list
73 # make sure check-names.list is up to date
74 cp -f check-names.list check-names.list.orig
75 $(MAKE) check-names.list
76 diff -Naur check-names.list.orig check-names.list || exit 1
77 rm -f check-names.list.orig
78
79unittest:67unittest:
80 python3 -m unittest discover -v -s ./reviewtools/tests -p 'test_*'68 CHECK_NAMES_LIST=$(TMP_DIR)/check-names.raw python3 -m unittest discover -v -s ./reviewtools/tests -p 'test_*'
69
70 (cat $(TMP_DIR)/check-names.raw 2>&1 | egrep -v '(skeleton|some-check)' | LC_ALL=C sort \
71 | awk -F '|' '(l && $$1 != l1) {print l} {l1=$$1; l=$$0} END {print l}') > $(TMP_DIR)/check-names.list
72
73 diff -Naur check-names.list $(TMP_DIR)/check-names.list || exit 1
74 rm -rf $(TMP_DIR)
8175
82coverage:76coverage:
83 python3 -m coverage run -m unittest discover -s ./reviewtools/tests -p 'test_*'77 python3 -m coverage run -m unittest discover -s ./reviewtools/tests -p 'test_*'
@@ -100,7 +94,7 @@ functest-updates:
100functest-dump-tool:94functest-dump-tool:
101 ./tests/test-dump-tool.sh95 ./tests/test-dump-tool.sh
10296
103check: check-deps check-style check-syntax check-names unittest functest-updates functest-dump-tool functest97check: check-deps check-style check-syntax unittest functest-updates functest-dump-tool functest
10498
105clean:99clean:
106 rm -rf ./reviewtools/__pycache__ ./reviewtools/tests/__pycache__100 rm -rf ./reviewtools/__pycache__ ./reviewtools/tests/__pycache__
diff --git a/collect-check-names-from-tests b/collect-check-names-from-tests
107deleted file mode 100755101deleted file mode 100755
index f8da1fa..0000000
--- a/collect-check-names-from-tests
+++ /dev/null
@@ -1,28 +0,0 @@
1#!/usr/bin/python3
2'''collect-check-names-from-tests: print list of check names discovered from tests'''
3#
4# Copyright (C) 2015 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; version 3 of the License.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18# NOTE: changes to this file may also need to be made to 'run-tests'
19
20import logging
21import unittest
22
23test_directory = 'reviewtools/tests/'
24
25logging.basicConfig(level=logging.DEBUG)
26
27suite = unittest.TestLoader().discover(test_directory)
28unittest.TextTestRunner(verbosity=0).run(suite)
diff --git a/reviewtools/common.py b/reviewtools/common.py
index a42f919..eaaadee 100644
--- a/reviewtools/common.py
+++ b/reviewtools/common.py
@@ -20,7 +20,6 @@ import copy
20from enum import Enum20from enum import Enum
21import inspect21import inspect
22import json22import json
23import logging
24import os23import os
25from pkg_resources import resource_filename24from pkg_resources import resource_filename
26import re25import re
@@ -196,20 +195,19 @@ class ReviewBase(object):
196 manual_review=False,195 manual_review=False,
197 ):196 ):
198 """Add result to report"""197 """Add result to report"""
198 if review_name not in self.review_report.results[self.section][result_type]:
199 # save info about checks that has been run to be later
200 # compared against check-names.list
201 if os.getenv("CHECK_NAMES_LIST") is not None:
202 name = ":".join(review_name.split(":")[:2])
203 link_text = link if link is not None else ""
204 with open(os.getenv("CHECK_NAMES_LIST"), "a") as fd:
205 fd.write("{}|{}\n".format(name, link_text))
206
199 self.review_report.add_result(207 self.review_report.add_result(
200 self.section, result_type, review_name, result, link, manual_review208 self.section, result_type, review_name, result, link, manual_review
201 )209 )
202210
203 if review_name not in self.review_report.results[self.section][result_type]:
204 # log info about check so it can be collected into the
205 # check-names.list file
206 # format should be
207 # CHECK|<review_type:check_name>|<link>
208 msg = "CHECK|{}|{}"
209 name = ":".join(review_name.split(":")[:2])
210 link_text = link if link is not None else ""
211 logging.debug(msg.format(name, link_text))
212
213 def do_checks(self):211 def do_checks(self):
214 """Run all methods that start with check_"""212 """Run all methods that start with check_"""
215 methodList = [213 methodList = [

Subscribers

People subscribed via source and target branches