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
1diff --git a/Makefile b/Makefile
2index c76f2bf..523b0ac 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -63,21 +63,15 @@ flake8: clean
6
7 check-syntax: pylint flake8
8
9-.PHONY: check-names.list
10-check-names.list:
11- (python3 collect-check-names-from-tests 2>&1 \
12- | grep 'CHECK|' | cut -d '|' -f 2- | egrep -v '(skeleton|some-check)' | LC_ALL=C sort \
13- | awk -F '|' '(l && $$1 != l1) {print l} {l1=$$1; l=$$0} END {print l}') > check-names.list
14-
15-check-names: check-names.list
16- # make sure check-names.list is up to date
17- cp -f check-names.list check-names.list.orig
18- $(MAKE) check-names.list
19- diff -Naur check-names.list.orig check-names.list || exit 1
20- rm -f check-names.list.orig
21-
22+TMP_DIR := $(shell mktemp -d)
23 unittest:
24- python3 -m unittest discover -v -s ./reviewtools/tests -p 'test_*'
25+ CHECK_NAMES_LIST=$(TMP_DIR)/check-names.raw python3 -m unittest discover -v -s ./reviewtools/tests -p 'test_*'
26+
27+ (cat $(TMP_DIR)/check-names.raw 2>&1 | egrep -v '(skeleton|some-check)' | LC_ALL=C sort \
28+ | awk -F '|' '(l && $$1 != l1) {print l} {l1=$$1; l=$$0} END {print l}') > $(TMP_DIR)/check-names.list
29+
30+ diff -Naur check-names.list $(TMP_DIR)/check-names.list || exit 1
31+ rm -rf $(TMP_DIR)
32
33 coverage:
34 python3 -m coverage run -m unittest discover -s ./reviewtools/tests -p 'test_*'
35@@ -100,7 +94,7 @@ functest-updates:
36 functest-dump-tool:
37 ./tests/test-dump-tool.sh
38
39-check: check-deps check-style check-syntax check-names unittest functest-updates functest-dump-tool functest
40+check: check-deps check-style check-syntax unittest functest-updates functest-dump-tool functest
41
42 clean:
43 rm -rf ./reviewtools/__pycache__ ./reviewtools/tests/__pycache__
44diff --git a/collect-check-names-from-tests b/collect-check-names-from-tests
45deleted file mode 100755
46index f8da1fa..0000000
47--- a/collect-check-names-from-tests
48+++ /dev/null
49@@ -1,28 +0,0 @@
50-#!/usr/bin/python3
51-'''collect-check-names-from-tests: print list of check names discovered from tests'''
52-#
53-# Copyright (C) 2015 Canonical Ltd.
54-#
55-# This program is free software: you can redistribute it and/or modify
56-# it under the terms of the GNU General Public License as published by
57-# the Free Software Foundation; version 3 of the License.
58-#
59-# This program is distributed in the hope that it will be useful,
60-# but WITHOUT ANY WARRANTY; without even the implied warranty of
61-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62-# GNU General Public License for more details.
63-#
64-# You should have received a copy of the GNU General Public License
65-# along with this program. If not, see <http://www.gnu.org/licenses/>.
66-
67-# NOTE: changes to this file may also need to be made to 'run-tests'
68-
69-import logging
70-import unittest
71-
72-test_directory = 'reviewtools/tests/'
73-
74-logging.basicConfig(level=logging.DEBUG)
75-
76-suite = unittest.TestLoader().discover(test_directory)
77-unittest.TextTestRunner(verbosity=0).run(suite)
78diff --git a/reviewtools/common.py b/reviewtools/common.py
79index a42f919..eaaadee 100644
80--- a/reviewtools/common.py
81+++ b/reviewtools/common.py
82@@ -20,7 +20,6 @@ import copy
83 from enum import Enum
84 import inspect
85 import json
86-import logging
87 import os
88 from pkg_resources import resource_filename
89 import re
90@@ -196,20 +195,19 @@ class ReviewBase(object):
91 manual_review=False,
92 ):
93 """Add result to report"""
94+ if review_name not in self.review_report.results[self.section][result_type]:
95+ # save info about checks that has been run to be later
96+ # compared against check-names.list
97+ if os.getenv("CHECK_NAMES_LIST") is not None:
98+ name = ":".join(review_name.split(":")[:2])
99+ link_text = link if link is not None else ""
100+ with open(os.getenv("CHECK_NAMES_LIST"), "a") as fd:
101+ fd.write("{}|{}\n".format(name, link_text))
102+
103 self.review_report.add_result(
104 self.section, result_type, review_name, result, link, manual_review
105 )
106
107- if review_name not in self.review_report.results[self.section][result_type]:
108- # log info about check so it can be collected into the
109- # check-names.list file
110- # format should be
111- # CHECK|<review_type:check_name>|<link>
112- msg = "CHECK|{}|{}"
113- name = ":".join(review_name.split(":")[:2])
114- link_text = link if link is not None else ""
115- logging.debug(msg.format(name, link_text))
116-
117 def do_checks(self):
118 """Run all methods that start with check_"""
119 methodList = [

Subscribers

People subscribed via source and target branches