visit_Node = VisitorTransform.recurse_to_children
-def unpack_source_tree(tree_file):
- dir = tempfile.mkdtemp()
+def unpack_source_tree(tree_file, dir=None):
+ if dir is None:
+ dir = tempfile.mkdtemp()
+ header = []
cur_file = None
for line in open(tree_file).readlines():
if line[:5] == '#####':
- filename = line.strip().strip('#').strip()
+ filename = line.strip().strip('#').strip().replace('/', os.path.sep)
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
+ else:
+ header.append(line)
+ return dir, ''.join(header)
from distutils.command.build_ext import build_ext as _build_ext
distutils_distro = Distribution()
-TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr']
+TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr', 'build']
TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr']
# Lists external modules, and a matcher matching tests
filenames = os.listdir(path)
filenames.sort()
for filename in filenames:
+ if context == "build" and filename.endswith(".srctree"):
+ suite.addTest(EndToEndTest(filename, workdir, self.cleanup_workdir))
+ continue
if not (filename.endswith(".pyx") or filename.endswith(".py")):
continue
if filename.startswith('.'): continue # certain emacs backup files
except ValueError: # no tests
pass
+
+class EndToEndTest(unittest.TestCase):
+ """
+ This is a test of build/*.srctree files, where srctree defines a full
+ directory structure and its header gives a list of commands to run.
+ """
+ def __init__(self, treefile, workdir, cleanup_workdir=True):
+ self.treefile = treefile
+ self.workdir = os.path.join(workdir, os.path.splitext(treefile)[0])
+ self.cleanup_workdir = cleanup_workdir
+ unittest.TestCase.__init__(self)
+
+ def shortDescription(self):
+ return "End-to-end %s" % self.treefile
+
+ def setUp(self):
+ from Cython.TestUtils import unpack_source_tree
+ _, self.commands = unpack_source_tree(os.path.join('tests', 'build', self.treefile), self.workdir)
+ self.old_dir = os.getcwd()
+ if not os.path.exists(self.workdir):
+ os.makedirs(self.workdir)
+ os.chdir(self.workdir)
+ if self.workdir not in sys.path:
+ sys.path.insert(0, self.workdir)
+
+ def tearDown(self):
+ try:
+ sys.path.remove(self.workdir)
+ except ValueError:
+ pass
+ if self.cleanup_workdir:
+ shutil.rmtree(self.workdir)
+ os.chdir(self.old_dir)
+
+ def runTest(self):
+ commands = (self.commands
+ .replace("CYTHON", "PYTHON %s" % os.path.join(self.old_dir, 'cython.py'))
+ .replace("PYTHON", sys.executable))
+ self.assertEqual(0, os.system(commands))
+
+
# TODO: Support cython_freeze needed here as well.
# TODO: Windows support.