[PATCH 1/6] Fix problems with the test scripts

David Shea dshea at redhat.com
Sun Sep 8 16:33:18 UTC 2013


- Remove the executable bit from the regex_tests, which was causing
  nosetests to skip them
- Override the $srcdir set by automake in runpylint.sh and
  run_check_accelerators.sh.
- Add more useful output to the regex tests
- Fix the name of the PROXY_URL_REGEX in proxy_test
- Add PYTHONPATH when running tests outside automake
---
 tests/Makefile.am                            |  3 ++-
 tests/accelerators/run_check_accelerators.sh |  2 +-
 tests/nosetests.sh                           |  7 +++++--
 tests/pylint/runpylint.sh                    |  7 ++++++-
 tests/regex_tests/groupparse_test.py         |  2 +-
 tests/regex_tests/proxy_test.py              |  6 +++---
 tests/regex_tests/username_test.py           |  4 ++--
 tests/testenv.sh                             | 14 ++++++++++++++
 8 files changed, 34 insertions(+), 11 deletions(-)
 mode change 100755 => 100644 tests/regex_tests/groupparse_test.py
 mode change 100755 => 100644 tests/regex_tests/proxy_test.py
 mode change 100755 => 100644 tests/regex_tests/username_test.py
 create mode 100644 tests/testenv.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0f63278..eb2b98b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,7 +30,7 @@
 #
 # 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;
+AM_TESTS_ENVIRONMENT = top_srcdir="$(top_srcdir)" top_builddir="$(top_builddir)" ; . $(srcdir)/testenv.sh ;
 TEST_EXTENSIONS = .sh
 
 dist_check_DATA = pylint/pylint-false-positives
@@ -40,6 +40,7 @@ dist_check_SCRIPTS = accelerators/check_accelerators.py \
 		     accelerators/run_check_accelerators.sh \
 		     nosetests.sh \
 		     pylint/runpylint.sh \
+		     testenv.sh \
 		     $(srcdir)/*_tests/*.py
 
 TESTS = nosetests.sh \
diff --git a/tests/accelerators/run_check_accelerators.sh b/tests/accelerators/run_check_accelerators.sh
index ac4969a..a49cda1 100755
--- a/tests/accelerators/run_check_accelerators.sh
+++ b/tests/accelerators/run_check_accelerators.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 : "${top_srcdir:=$(dirname "$0")/../..}"
-: "${srcdir:=${top_srcdir}/tests/accelerators}"
+srcdir="${top_srcdir}/tests/accelerators"
 
 find "${top_srcdir}" -name '*.glade' -exec "${srcdir}/check_accelerators.py" {} +
diff --git a/tests/nosetests.sh b/tests/nosetests.sh
index ee4b07c..1ad86c0 100755
--- a/tests/nosetests.sh
+++ b/tests/nosetests.sh
@@ -1,11 +1,14 @@
 #!/bin/sh
 
-echo $PYTHONPATH
-
 # Use the directory above the one containing the script as the default for
 # $top_srcdir
 : "${top_srcdir:=$(dirname "$0")/..}"
 
+# If no PYTHONPATH is set, import the test environment
+if [ -z "$PYTHONPATH" ]; then
+    . ${top_srcdir}/tests/testenv.sh
+fi
+
 # If no tests were selected, select all of them
 if [ $# -eq 0 ]; then
     set -- "${top_srcdir}"/tests/*_tests
diff --git a/tests/pylint/runpylint.sh b/tests/pylint/runpylint.sh
index 72283d9..2cf5797 100755
--- a/tests/pylint/runpylint.sh
+++ b/tests/pylint/runpylint.sh
@@ -16,7 +16,12 @@ if [ -z "$top_srcdir" ]; then
 fi
 
 : "${top_srcdir:=$(dirname "$0")/../..}"
-: "${srcdir:=${top_srcdir}/tests/pylint}"
+srcdir="${top_srcdir}/tests/pylint"
+
+# If no PYTHONPATH is set, import the test environment
+if [ -z "$PYTHONPATH" ]; then
+    . ${top_srcdir}/tests/testenv.sh
+fi
 
 FALSE_POSITIVES="${srcdir}"/pylint-false-positives
 
diff --git a/tests/regex_tests/groupparse_test.py b/tests/regex_tests/groupparse_test.py
old mode 100755
new mode 100644
index 96fd9d7..2802cad
--- a/tests/regex_tests/groupparse_test.py
+++ b/tests/regex_tests/groupparse_test.py
@@ -55,7 +55,7 @@ class GroupParseTestCase(unittest.TestCase):
                 self.assertEqual(GROUPLIST_FANCY_PARSE.match(group).groups(), result)
             except AssertionError as error:
                 got_error = True
-                print(error)
+                print("Group parse error: `%s' did not not parse as `%s'" % (group, result))
 
         if got_error:
             self.fail()
diff --git a/tests/regex_tests/proxy_test.py b/tests/regex_tests/proxy_test.py
old mode 100755
new mode 100644
index 1b0e561..0e551f1
--- a/tests/regex_tests/proxy_test.py
+++ b/tests/regex_tests/proxy_test.py
@@ -20,7 +20,7 @@
 
 import unittest
 
-from pyanaconda.regexes import PROXY_URL
+from pyanaconda.regexes import PROXY_URL_PARSE
 
 class ProxyRegexTestCase(unittest.TestCase):
     def proxy_regex_test(self):
@@ -110,10 +110,10 @@ class ProxyRegexTestCase(unittest.TestCase):
         got_error = False
         for proxy, result in tests:
             try:
-                self.assertEqual(PROXY_URL.match(proxy).groups(), result)
+                self.assertEqual(PROXY_URL_PARSE.match(proxy).groups(), result)
             except AssertionError as error:
                 got_error = True
-                print error
+                print("Proxy parse error: `%s' did not parse as `%s'" % (proxy, result))
 
         if got_error:
             self.fail()
diff --git a/tests/regex_tests/username_test.py b/tests/regex_tests/username_test.py
old mode 100755
new mode 100644
index 9f2ac2e..9877410
--- a/tests/regex_tests/username_test.py
+++ b/tests/regex_tests/username_test.py
@@ -31,14 +31,14 @@ class UsernameRegexTestCase(unittest.TestCase):
                 self.assertIsNotNone(expression.match(good))
             except AssertionError as error:
                 got_error = True
-                print(error)
+                print("Good string %s did not match expression" % good)
 
         for bad in badlist:
             try:
                 self.assertIsNone(expression.match(bad))
             except AssertionError as error:
                 got_error = True
-                print(error)
+                print("Bad string %s matched expression" % bad)
 
         if got_error:
             self.fail()
diff --git a/tests/testenv.sh b/tests/testenv.sh
new file mode 100644
index 0000000..b4749b4
--- /dev/null
+++ b/tests/testenv.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+if [ -z "$top_srcdir" ]; then
+    echo "*** top_srcdir must be set"
+    exit 1
+fi
+
+# If not top_builddir is set, use top_srcdir
+: "${top_builddir:=$top_srcdir}"
+
+PYTHONPATH="${top_builddir}/pyanaconda/isys/.libs:${top_srcdir}/pyanaconda:${top_srcdir}"
+export PYTHONPATH
+export top_srcdir
+export top_builddir
-- 
1.8.3.1



More information about the anaconda-patches mailing list