mailr22780 - /trunk/devel_scripts/test_library_independence.py


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

Header


Content

Posted by edward on April 16, 2014 - 09:12:
Author: bugman
Date: Wed Apr 16 09:12:26 2014
New Revision: 22780

URL: http://svn.gna.org/viewcvs/relax?rev=22780&view=rev
Log:
Improvements to the test_library_independence.py development script.

This script for checking the independence of the relax library will now 
recursively import all
packages and modules in the library and report at the end a list of all 
failures.


Modified:
    trunk/devel_scripts/test_library_independence.py

Modified: trunk/devel_scripts/test_library_independence.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/devel_scripts/test_library_independence.py?rev=22780&r1=22779&r2=22780&view=diff
==============================================================================
--- trunk/devel_scripts/test_library_independence.py    (original)
+++ trunk/devel_scripts/test_library_independence.py    Wed Apr 16 09:12:26 
2014
@@ -1,7 +1,14 @@
 #! /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
@@ -21,13 +28,82 @@
     # Modify the system path.
     sys.path.append(tmpdir)
 
-    # Import the temporary library.
-    from lib import *
+    # 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("Testing in the temporary directory %s." % tmpdir)
+print("\nTesting in the temporary directory %s.\n" % tmpdir)
 
 # Failsafe execution of the testing.
 try:
@@ -35,5 +111,5 @@
 
 # Delete the temporary directory.
 finally:
-    print("Deleting the directory %s." % tmpdir)
+    print("\n\nDeleting the directory %s.\n" % tmpdir)
     rmtree(tmpdir)




Related Messages


Powered by MHonArc, Updated Wed Apr 16 10:00:04 2014