[svn] commit: r2898 - /branches/trac322/src/lib/python/isc/bind10/tests/rename.py

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Sep 9 18:18:23 UTC 2010


Author: vorner
Date: Thu Sep  9 18:18:23 2010
New Revision: 2898

Log:
Check that scripts use renaming

Modified:
    branches/trac322/src/lib/python/isc/bind10/tests/rename.py

Modified: branches/trac322/src/lib/python/isc/bind10/tests/rename.py
==============================================================================
--- branches/trac322/src/lib/python/isc/bind10/tests/rename.py (original)
+++ branches/trac322/src/lib/python/isc/bind10/tests/rename.py Thu Sep  9 18:18:23 2010
@@ -1,32 +1,46 @@
 import unittest
 import os
+import os.path
 import setproctitle
 import isc.bind10.rename
 import re
 
 class TestRename(unittest.TestCase):
-    def get_self_name(self):
+    def __get_self_name(self):
         return setproctitle.getproctitle()
 
     # This tests if the renaming works
     def test_rename(self):
         isc.bind10.rename.rename("rename-test")
-        self.assertEqual("rename-test", self.get_self_name())
+        self.assertEqual("rename-test", self.__get_self_name())
         isc.bind10.rename.rename()
-        self.assertEqual("rename.py", self.get_self_name())
+        self.assertEqual("rename.py", self.__get_self_name())
+
+    # Scan one script if it contains call to the renaming function
+    def __scan(self, directory, script, fun, repl):
+        filename = os.path.join(directory, script)
+        data = ''.join(open(filename).readlines())
+        prettyname = 'src' + filename[filename.rfind('../') + 2:]
+        self.assert_(fun.search(data),
+            "Didn't find a call to isc.bind10.rename.rename in " + prettyname)
 
     # This finds all python scripts and tries to find if they call the function
     def test_calls(self):
-        scripts = re.compile('^\\w+_SCRIPTS\\s*=\\s*((.|\\\\\\n)*)$',
+        # I miss perl here little bit...
+        lines = re.compile('^\\w+_SCRIPTS\\s*=\\s*((.|\\\\\\n)*)$',
             re.MULTILINE)
+        scripts = re.compile('((\w|[-.0-9])+)')
+        fun = re.compile('^\s*isc\.bind10\.rename\.rename\s*\(.*\)\s*(|#.*)$',
+            re.MULTILINE)
+        repl = re.compile('(../)*')
+        # Find all Makefile.am and extract names of scripts
         for (d, _, fs) in os.walk('../../../../../', followlinks = True):
             if 'Makefile.am' in fs:
-                print("Found Makefile.am in " + d)
                 makefile = ''.join(open(os.path.join(d,
                     "Makefile.am")).readlines())
-                # XXX Continue here, parse out the file names and check them
-                print(str(scripts.findall(makefile)))
-        self.assert_(False)
+                for (var, _) in lines.findall(makefile):
+                    for (script, _) in scripts.findall(var):
+                        self.__scan(d, script, fun, repl)
 
 if __name__ == "__main__":
     unittest.main()




More information about the bind10-changes mailing list