mailr22794 - in /trunk: devel_scripts/ test_suite/verification_tests/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on April 16, 2014 - 18:19:
Author: bugman
Date: Wed Apr 16 18:19:34 2014
New Revision: 22794

URL: http://svn.gna.org/viewcvs/relax?rev=22794&view=rev
Log:
Shifted the relax library independence developer script into the software 
verification tests.

The functionality of the devel_scripts/test_library_independence.py script is 
now within the
Library.test_library_independence software verification test.  Therefore the 
script has been
deleted.


Added:
    trunk/test_suite/verification_tests/library.py
Removed:
    trunk/devel_scripts/test_library_independence.py
Modified:
    trunk/test_suite/verification_tests/__init__.py

Removed: trunk/devel_scripts/test_library_independence.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/devel_scripts/test_library_independence.py?rev=22793&view=auto
==============================================================================
--- trunk/devel_scripts/test_library_independence.py    (original)
+++ trunk/devel_scripts/test_library_independence.py    (removed)
@@ -1,115 +0,0 @@
-#! /usr/bin/env python
-
-"""This script will throughly check the independence of the relax library.
-
-It will do this by copying just that package into a temporary directory, 
modifying the Python system path to include the directory, and then to 
recursively import all packages and modules.  All import failures will be 
reported at the end.
-"""
-
-# Python module imports.
-import importlib
-from os import sep
-import pkgutil
-from shutil import copytree, rmtree
-import sys
-from tempfile import mkdtemp
-
-
-def test_library(tmpdir=None):
-    """Test the independence of the relax library by importing it from a 
non-relax directory.
-
-    @keyword tmpdir:    The name of the temporary directory to perform the 
testing in.
-    @type tmpdir:       str
-    """
-
-    # Copy the entire library to the temporary directory.
-    tmplib = tmpdir+sep+'lib'
-    copytree('lib', tmplib)
-
-    # Modify the system path.
-    sys.path.append(tmpdir)
-
-    # Initialise a structure for later reporting of failed imports.
-    failed = []
-
-    # Import each part of the library.
-    import lib
-    for importer, name, is_pkg in pkgutil.iter_modules(lib.__path__):
-        # The full name.
-        full_name = 'lib.%s' % name
-
-        # Printout.
-        if is_pkg:
-            print("Package '%s'." % full_name)
-        else:
-            print("Module '%s'." % full_name)
-
-        # Import it.
-        try:
-            module = importlib.import_module(full_name)
-        except:
-            message = sys.exc_info()[1]
-            failed.append([full_name, message])
-
-        # Nothing more to do.
-        if not is_pkg:
-            continue
-
-        # First recursion.
-        for importer2, name2, is_pkg2 in 
pkgutil.iter_modules(module.__path__):
-            # The full name.
-            full_name2 = 'lib.%s.%s' % (name, name2)
-
-            # Printout.
-            if is_pkg2:
-                print("  Package '%s'." % full_name2)
-            else:
-                print("  Module '%s'." % full_name2)
-
-            # Import it.
-            try:
-                module2 = importlib.import_module(full_name2)
-            except:
-                message = sys.exc_info()[1]
-                failed.append([full_name2, message])
-
-            # Nothing more to do.
-            if not is_pkg2:
-                continue
-
-            # 2nd recursion (the last for now).
-            for importer3, name3, is_pkg3 in 
pkgutil.iter_modules(module2.__path__):
-                # The full name.
-                full_name3 = 'lib.%s.%s.%s' % (name, name2, name3)
-
-                # Printout.
-                if is_pkg3:
-                    print("    Package '%s'." % full_name3)
-                    raise NameError("Recursion limit exceeded.")
-                else:
-                    print("    Module '%s'." % full_name3)
-
-                # Import it.
-                try:
-                    module3 = importlib.import_module(full_name3)
-                except:
-                    message = sys.exc_info()[1]
-                    failed.append([full_name3, message])
-
-    # Printout of all import failures.
-    print('\n\nImport failures:')
-    for name, message in failed:
-        print("  %s:  %s" % (name, message))
-
-
-# Initialise a temporary directory.
-tmpdir = mkdtemp()
-print("\nTesting in the temporary directory %s.\n" % tmpdir)
-
-# Failsafe execution of the testing.
-try:
-    test_library(tmpdir)
-
-# Delete the temporary directory.
-finally:
-    print("\n\nDeleting the directory %s.\n" % tmpdir)
-    rmtree(tmpdir)

Modified: trunk/test_suite/verification_tests/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/verification_tests/__init__.py?rev=22794&r1=22793&r2=22794&view=diff
==============================================================================
--- trunk/test_suite/verification_tests/__init__.py     (original)
+++ trunk/test_suite/verification_tests/__init__.py     Wed Apr 16 18:19:34 
2014
@@ -34,6 +34,7 @@
 
 # relax software verification test module imports.
 from test_suite.relax_test_loader import RelaxTestLoader as TestLoader
+from test_suite.verification_tests.library import Library
 
 
 __all__ = [
@@ -90,7 +91,7 @@
 
         # All tests.
         if not tests:
-            pass
+            suite_array.append(TestLoader().loadTestsFromTestCase(Library))
 
         # Group all tests together.
         full_suite = TestSuite(suite_array)

Added: trunk/test_suite/verification_tests/library.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/test_suite/verification_tests/library.py?rev=22794&view=auto
==============================================================================
--- trunk/test_suite/verification_tests/library.py      (added)
+++ trunk/test_suite/verification_tests/library.py      Wed Apr 16 18:19:34 
2014
@@ -0,0 +1,183 @@
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2014 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 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 General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Module docstring.
+"""Verification tests for the relax library."""
+
+# Python module imports.
+from os import sep
+from shutil import copytree, rmtree
+from subprocess import PIPE, Popen
+import sys
+from tempfile import mkdtemp
+from unittest import TestCase
+
+
+class Library(TestCase):
+    """Test the relax library."""
+
+    def setUp(self):
+        """Set up for all of the library tests."""
+
+        # Initialise a temporary directory.
+        self.tmpdir = mkdtemp()
+
+
+    def tearDown(self):
+        """Clean up after the library tests."""
+
+        # Remove the temporary directory and all its contents.
+        rmtree(self.tmpdir)
+
+
+    def test_library_independence(self):
+        """Throughly check the independence of the relax library by 
importing it from a non-relax directory.
+
+        It will do this by copying just that package into a temporary 
directory, modifying the Python system path to include the directory, and 
then to recursively import all packages and modules.  All import failures 
will be reported at the end.
+        """
+
+        # Copy the entire library to the temporary directory.
+        tmplib = self.tmpdir + sep + 'lib'
+        copytree('lib', tmplib)
+
+        # Create a Python script for testing the import independently of 
relax.
+        script_name = self.tmpdir + sep + 'test.py'
+        script = open(script_name, 'w')
+
+        # Script contents.
+        lines = [
+            "",
+            "# Python module imports.",
+            "import importlib",
+            "import pkgutil",
+            "import sys",
+            "",
+            "# Initialise a structure for later reporting of failed 
imports.",
+            "failed = []",
+            "",
+            "# Import each part of the library.",
+            "import lib",
+            "for importer, name, is_pkg in 
pkgutil.iter_modules(lib.__path__):",
+            "    # The full name.",
+            "    full_name = 'lib.%s' % name",
+            "",
+            "    # Printout.",
+            "    if is_pkg:",
+            "        print(\"Package '%s'.\" % full_name)",
+            "    else:",
+            "        print(\"Module '%s'.\" % full_name)",
+            "",
+            "    # Import it.",
+            "    module = None",
+            "    try:",
+            "        module = importlib.import_module(full_name)",
+            "    except:",
+            "        message = sys.exc_info()[1]",
+            "        failed.append([full_name, message])",
+            "",
+            "    # Nothing more to do.",
+            "    if not is_pkg or module is None:",
+            "        continue",
+            "",
+            "    # First recursion.",
+            "    for importer2, name2, is_pkg2 in 
pkgutil.iter_modules(module.__path__):",
+            "        # The full name.",
+            "        full_name2 = 'lib.%s.%s' % (name, name2)",
+            "",
+            "        # Printout.",
+            "        if is_pkg2:",
+            "            print(\"  Package '%s'.\" % full_name2)",
+            "        else:",
+            "            print(\"  Module '%s'.\" % full_name2)",
+            "",
+            "        # Import it.",
+            "        module2 = None",
+            "        try:",
+            "            module2 = importlib.import_module(full_name2)",
+            "        except:",
+            "            message = sys.exc_info()[1]",
+            "            failed.append([full_name2, message])",
+            "",
+            "        # Nothing more to do.",
+            "        if not is_pkg2 or module2 is None:",
+            "            continue",
+            "",
+            "        # 2nd recursion (the last for now).",
+            "        for importer3, name3, is_pkg3 in 
pkgutil.iter_modules(module2.__path__):",
+            "            # The full name.",
+            "            full_name3 = 'lib.%s.%s.%s' % (name, name2, name3)",
+            "",
+            "            # Printout.",
+            "            if is_pkg3:",
+            "                print(\"    Package '%s'.\" % full_name3)",
+            "                raise NameError(\"Recursion limit exceeded.\")",
+            "            else:",
+            "                print(\"    Module '%s'.\" % full_name3)",
+            "",
+            "            # Import it.",
+            "            try:",
+            "                module3 = importlib.import_module(full_name3)",
+            "            except:",
+            "                message = sys.exc_info()[1]",
+            "                failed.append([full_name3, message])",
+            "",
+            "# Printout of all import failures.",
+            "if len(failed):",
+            "    sys.stderr.write('\\n\\nImport failures:\\n')",
+            "    for name, message in failed:",
+            "        sys.stderr.write(\"  %s:  %s\\n\" % (name, message))",
+            "    sys.stderr.write('\\n')",
+        ]
+        for line in lines:
+            script.write(line + '\n')
+
+        # Close the script.
+        script.close()
+
+        # Execute the script using the same Python executable as relax.
+        cmd = "%s %s" % (sys.executable, script_name)
+        pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, 
close_fds=False)
+
+        # Close the pipe.
+        pipe.stdin.close()
+
+        # Write to stdout.
+        for line in pipe.stdout.readlines():
+            # Decode Python 3 byte arrays.
+            if hasattr(line, 'decode'):
+                line = line.decode()
+
+            # Write.
+            sys.stdout.write(line)
+
+        # Write to stderr.
+        err_lines = pipe.stderr.readlines()
+        for line in err_lines:
+            # Decode Python 3 byte arrays.
+            if hasattr(line, 'decode'):
+                line = line.decode()
+
+            # Write.
+            sys.stderr.write(line)
+
+        # An import failure occurred.
+        if len(err_lines):
+            self.fail()




Related Messages


Powered by MHonArc, Updated Wed Apr 16 19:40:02 2014