diff options
author | Robert Bradshaw <robertwb@math.washington.edu> | 2010-09-12 01:36:38 -0700 |
---|---|---|
committer | Robert Bradshaw <robertwb@math.washington.edu> | 2010-09-12 01:36:38 -0700 |
commit | 2cde741b316064f613fe540da030177c72e240ef (patch) | |
tree | efe5a3d07f1e72e8a02a1241137ab6eb6dc22f52 /Cython/TestUtils.py | |
parent | ff954f31c5c935169e278c0a53eba8f5a52f279c (diff) | |
download | cython-2cde741b316064f613fe540da030177c72e240ef.tar.gz |
Utility methods for unpacking a source tree from a single file.
Diffstat (limited to 'Cython/TestUtils.py')
-rw-r--r-- | Cython/TestUtils.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Cython/TestUtils.py b/Cython/TestUtils.py index 6d62114c9..094bc1a23 100644 --- a/Cython/TestUtils.py +++ b/Cython/TestUtils.py @@ -7,7 +7,8 @@ from Cython.Compiler.Visitor import TreeVisitor, VisitorTransform from Cython.Compiler import TreePath import unittest -import sys +import os, sys +import tempfile class NodeTypeWriter(TreeVisitor): def __init__(self): @@ -166,3 +167,19 @@ class TreeAssertVisitor(VisitorTransform): return node visit_Node = VisitorTransform.recurse_to_children + +def unpack_source_tree(tree_file): + dir = tempfile.mkdtemp() + cur_file = None + for line in open(tree_file).readlines(): + if line[:5] == '#####': + filename = line.strip().strip('#').strip() + path = os.path.join(dir, filename) + print os.path.dirname(path) + if not os.path.exists(os.path.dirname(path)): + print " ...creating" + os.makedirs(os.path.dirname(path)) + cur_file = open(path, 'w') + elif cur_file is not None: + cur_file.write(line) + return dir |