Back to index

python3.2  3.2.2
Functions | Variables
lib2to3.tests.pytree_idempotency Namespace Reference

Functions

def main
def diff

Variables

string __author__ = "Guido van Rossum <guido@python.org>"

Function Documentation

def lib2to3.tests.pytree_idempotency.diff (   fn,
  tree 
)

Definition at line 80 of file pytree_idempotency.py.

00080 
00081 def diff(fn, tree):
00082     f = open("@", "w")
00083     try:
00084         f.write(str(tree))
00085     finally:
00086         f.close()
00087     try:
00088         return os.system("diff -u %s @" % fn)
00089     finally:
00090         os.remove("@")

Here is the call graph for this function:

Definition at line 24 of file pytree_idempotency.py.

00024 
00025 def main():
00026     gr = driver.load_grammar("Grammar.txt")
00027     dr = driver.Driver(gr, convert=pytree.convert)
00028 
00029     fn = "example.py"
00030     tree = dr.parse_file(fn, debug=True)
00031     if not diff(fn, tree):
00032         print("No diffs.")
00033     if not sys.argv[1:]:
00034         return # Pass a dummy argument to run the complete test suite below
00035 
00036     problems = []
00037 
00038     # Process every imported module
00039     for name in sys.modules:
00040         mod = sys.modules[name]
00041         if mod is None or not hasattr(mod, "__file__"):
00042             continue
00043         fn = mod.__file__
00044         if fn.endswith(".pyc"):
00045             fn = fn[:-1]
00046         if not fn.endswith(".py"):
00047             continue
00048         print("Parsing", fn, file=sys.stderr)
00049         tree = dr.parse_file(fn, debug=True)
00050         if diff(fn, tree):
00051             problems.append(fn)
00052 
00053     # Process every single module on sys.path (but not in packages)
00054     for dir in sys.path:
00055         try:
00056             names = os.listdir(dir)
00057         except os.error:
00058             continue
00059         print("Scanning", dir, "...", file=sys.stderr)
00060         for name in names:
00061             if not name.endswith(".py"):
00062                 continue
00063             print("Parsing", name, file=sys.stderr)
00064             fn = os.path.join(dir, name)
00065             try:
00066                 tree = dr.parse_file(fn, debug=True)
00067             except pgen2.parse.ParseError as err:
00068                 print("ParseError:", err)
00069             else:
00070                 if diff(fn, tree):
00071                     problems.append(fn)
00072 
00073     # Show summary of problem files
00074     if not problems:
00075         print("No problems.  Congratulations!")
00076     else:
00077         print("Problems in following files:")
00078         for fn in problems:
00079             print("***", fn)

Here is the caller graph for this function:


Variable Documentation

string lib2to3.tests.pytree_idempotency.__author__ = "Guido van Rossum <guido@python.org>"

Definition at line 7 of file pytree_idempotency.py.