[PATCH 7/8] Rearranged the automake tests.

David Shea dshea at redhat.com
Thu Sep 5 14:42:44 UTC 2013


Modified the tests so that they can be run from any directory and so
that they fit better with automake's parallel test harness.
---
 .gitignore                                   |  5 +++
 Makefile.am                                  |  8 +----
 configure.ac                                 |  1 +
 tests/Makefile.am                            | 47 ++++++++++++++++++++++++
 tests/accelerators/run_check_accelerators.sh |  6 ++--
 tests/nosetests.sh                           | 14 ++++++--
 tests/pylint/runpylint.sh                    | 54 +++++++++++++++++++---------
 7 files changed, 106 insertions(+), 29 deletions(-)
 create mode 100644 tests/Makefile.am

diff --git a/.gitignore b/.gitignore
index a4cb776..c076307 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,6 +70,11 @@ py-compile
 stamp-h1
 tags
 test-driver
+tests/*/*.log
+tests/*/*.trs
+tests/*.log
+tests/*.trs
+tests/test-suite.log
 updates.img
 utils/dd/dd_extract
 utils/dd/dd_list
diff --git a/Makefile.am b/Makefile.am
index e4b0e88..756131b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,13 +19,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = pyanaconda po data \
-	      utils scripts docs dracut widgets
-
-TESTS_ENVIRONMENT = PYTHONPATH=$(builddir)/pyanaconda/isys/.libs:$(builddir)/pyanaconda/isys:$(builddir)/pyanaconda ; export PYTHONPATH;
-TESTS = tests/pylint/runpylint.sh \
-		  tests/nosetests.sh \
-		  tests/accelerators/run_check_accelerators.sh
+SUBDIRS = data docs dracut po pyanaconda scripts tests widgets utils
 
 EXTRA_DIST = config.rpath COPYING
 
diff --git a/configure.ac b/configure.ac
index 28ea1ef..99952f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -260,6 +260,7 @@ AC_CONFIG_FILES([Makefile
                  pyanaconda/ui/tui/tools/Makefile
                  pyanaconda/ui/tui/Makefile
                  data/post-scripts/Makefile
+                 tests/Makefile
                  utils/Makefile
                  utils/dd/Makefile
                  utils/log_picker/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..0f63278
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,47 @@
+# Makefile.am for anaconda tests
+#
+# Copyright (C) 2013  Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Shea <dshea at redhat.com>
+
+# This Makefile is non-recursive so that all tests can easily be run with the
+# same python environment. $top_srcdir and $top_builddir are added to the
+# environment so that tests can get their bearings. Tests need to be aware that
+# they may be run from within an arbitrary working directory.
+# 
+# While automake claims that it doesn't support wildcards anywhere, they really
+# mean it with the parallel test harness. Rather than reverting back to the
+# serial harness, all of the nosetests-based checks will be run serially by
+# nosetests.sh. This script can be run in parallel with the other test scripts,
+# such as pylint.
+#
+# nosetests will be run for any python files found in a directory matching *_tests
+
+AM_TESTS_ENVIRONMENT = PYTHONPATH='$(abs_top_builddir)'/pyanaconda/isys/.libs:'$(abs_top_srcdir)'/pyanaconda/isys:'$(abs_top_srcdir)'/pyanaconda:'$(abs_top_srcdir)'; top_srcdir='$(abs_top_srcdir)'; top_builddir='$(abs_top_builddir)'; export PYTHONPATH; export top_srcdir; export top_builddir;
+TEST_EXTENSIONS = .sh
+
+dist_check_DATA = pylint/pylint-false-positives
+
+# Test scripts need to be listed both here and in TESTS
+dist_check_SCRIPTS = accelerators/check_accelerators.py \
+		     accelerators/run_check_accelerators.sh \
+		     nosetests.sh \
+		     pylint/runpylint.sh \
+		     $(srcdir)/*_tests/*.py
+
+TESTS = nosetests.sh \
+	pylint/runpylint.sh \
+	accelerators/run_check_accelerators.sh
diff --git a/tests/accelerators/run_check_accelerators.sh b/tests/accelerators/run_check_accelerators.sh
index 15ccab7..ac4969a 100755
--- a/tests/accelerators/run_check_accelerators.sh
+++ b/tests/accelerators/run_check_accelerators.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-scriptdir="$(dirname "$0")"
-gladedir="$scriptdir/../.."
+: "${top_srcdir:=$(dirname "$0")/../..}"
+: "${srcdir:=${top_srcdir}/tests/accelerators}"
 
-find "${gladedir}" -name '*.glade' -exec "${scriptdir}/check_accelerators.py" {} +
+find "${top_srcdir}" -name '*.glade' -exec "${srcdir}/check_accelerators.py" {} +
diff --git a/tests/nosetests.sh b/tests/nosetests.sh
index c031201..ee4b07c 100755
--- a/tests/nosetests.sh
+++ b/tests/nosetests.sh
@@ -1,6 +1,14 @@
-#!/bin/bash
+#!/bin/sh
 
 echo $PYTHONPATH
 
-# The path we pass to nosetests is relative to the top-level of the anaconda source dir.
-nosetests -v --exclude=logpicker -a \!acceptance,\!slow tests/*_tests
+# Use the directory above the one containing the script as the default for
+# $top_srcdir
+: "${top_srcdir:=$(dirname "$0")/..}"
+
+# If no tests were selected, select all of them
+if [ $# -eq 0 ]; then
+    set -- "${top_srcdir}"/tests/*_tests
+fi
+
+exec nosetests -v --exclude=logpicker -a \!acceptance,\!slow "$@"
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
index 60ecaaf..72283d9 100755
--- a/tests/pylint/runpylint.sh
+++ b/tests/pylint/runpylint.sh
@@ -8,7 +8,17 @@
 # to stdout and this script will exit with a status of 1, if no (non filtered)
 # warnings are found it exits with a status of 0
 
-FALSE_POSITIVES=tests/pylint/pylint-false-positives
+# If $top_srcdir is set, assume this is being run from automake and we don't
+# need to keep a separate log
+pylint_log=0
+if [ -z "$top_srcdir" ]; then
+    pylint_log=1
+fi
+
+: "${top_srcdir:=$(dirname "$0")/../..}"
+: "${srcdir:=${top_srcdir}/tests/pylint}"
+
+FALSE_POSITIVES="${srcdir}"/pylint-false-positives
 
 # W0212 - Access to a protected member %s of a client class
 NON_STRICT_OPTIONS="--disable=W0212"
@@ -54,15 +64,19 @@ if [ "`tail -c 1 $FALSE_POSITIVES`" == "`echo`" ]; then
   exit 1
 fi
 
+exit_status=0
+if [ "$pylint_log" -ne 0 ]; then
+    > pylint-log
+fi
+
 # run pylint one file / module at a time, otherwise it sometimes gets
 # confused
-> pylint-log
-for i in anaconda $(find pyanaconda -type f -name '*py' \! -executable); do
-  if [ "$i" == "pyanaconda/packaging/dnfpayload.py" ]; then
+for i in "${top_srcdir}"/anaconda $(find "${top_srcdir}/pyanaconda" -type f -name '*py' \! -executable); do
+  if [ -n "$(echo "$i" | grep 'pyanaconda/packaging/dnfpayload.py$')" ]; then
      continue
   fi
 
-  pylint \
+  pylint_output="$(pylint \
     --msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}' \
     -r n --disable=C,R --rcfile=/dev/null \
     --dummy-variables-rgx=_ \
@@ -71,19 +85,27 @@ for i in anaconda $(find pyanaconda -type f -name '*py' \! -executable); do
     $DISABLED_WARN_OPTIONS \
     $DISABLED_ERR_OPTIONS \
     $NON_STRICT_OPTIONS $i | \
-    egrep -v "`cat $FALSE_POSITIVES | tr '\n' '|'`" > pylint-tmp-log
-  if grep -q -v '************* Module ' pylint-tmp-log; then
-    cat pylint-tmp-log >> pylint-log
+    egrep -v "$(tr '\n' '|' < "$FALSE_POSITIVES") \
+    ")"
+  # I0011 is the informational "Locally disabling ...." message
+  if [ -n "$(echo "$pylint_output" | fgrep -v '************* Module ' |\
+          grep -v '^I0011:')" ]; then
+      if [ "$pylint_log" -ne 0 ]; then
+          echo "$pylint_output" >> pylint-log
+      else
+          echo "$pylint_output"
+      fi
+      exit_status=1
   fi
 done
-rm pylint-tmp-log
 
-if [ -s pylint-log ]; then
-  echo "pylint reports the following issues:"
-  cat pylint-log
-  exit 1
+if [ "$pylint_log" -ne 0 ]; then
+    if [ -s pylint-log ]; then
+        echo "pylint reports the following issues:"
+        cat pylint-log
+    else
+        rm pylint-log
+    fi
 fi
 
-rm pylint-log
-
-exit 0
+exit "$exit_status"
-- 
1.8.3.1



More information about the anaconda-patches mailing list