diff Tools/scripts/findnocoding.py @ 76106:62dde5dd475e 3.2

#14490, #14491: add 'sundry'-style import tests for Tools/scripts. This patch changes a few of the scripts to have __name__=='__main__' clauses so that they are importable without running. Also fixes the syntax errors revealed by the tests.
author R David Murray <rdmurray@bitdance.com>
date Wed, 04 Apr 2012 21:28:14 -0400
parents fcfe324663a6
children 696cb524322a
line wrap: on
line diff
--- a/Tools/scripts/findnocoding.py	Wed Apr 04 20:17:06 2012 +0200
+++ b/Tools/scripts/findnocoding.py	Wed Apr 04 21:28:14 2012 -0400
@@ -76,29 +76,31 @@
     -c: recognize Python source files trying to compile them
     -d: debug output""" % sys.argv[0]
 
-try:
-    opts, args = getopt.getopt(sys.argv[1:], 'cd')
-except getopt.error as msg:
-    print(msg, file=sys.stderr)
-    print(usage, file=sys.stderr)
-    sys.exit(1)
+if __name__ == '__main__':
 
-is_python = pysource.looks_like_python
-debug = False
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], 'cd')
+    except getopt.error as msg:
+        print(msg, file=sys.stderr)
+        print(usage, file=sys.stderr)
+        sys.exit(1)
+
+    is_python = pysource.looks_like_python
+    debug = False
 
-for o, a in opts:
-    if o == '-c':
-        is_python = pysource.can_be_compiled
-    elif o == '-d':
-        debug = True
+    for o, a in opts:
+        if o == '-c':
+            is_python = pysource.can_be_compiled
+        elif o == '-d':
+            debug = True
 
-if not args:
-    print(usage, file=sys.stderr)
-    sys.exit(1)
+    if not args:
+        print(usage, file=sys.stderr)
+        sys.exit(1)
 
-for fullpath in pysource.walk_python_files(args, is_python):
-    if debug:
-        print("Testing for coding: %s" % fullpath)
-    result = needs_declaration(fullpath)
-    if result:
-        print(fullpath)
+    for fullpath in pysource.walk_python_files(args, is_python):
+        if debug:
+            print("Testing for coding: %s" % fullpath)
+        result = needs_declaration(fullpath)
+        if result:
+            print(fullpath)