Commit bfe3c0a8 authored by Robert Bradshaw's avatar Robert Bradshaw

Tests of an entire source tree build invocation.

parent 2cde741b
...@@ -168,18 +168,20 @@ class TreeAssertVisitor(VisitorTransform): ...@@ -168,18 +168,20 @@ class TreeAssertVisitor(VisitorTransform):
visit_Node = VisitorTransform.recurse_to_children visit_Node = VisitorTransform.recurse_to_children
def unpack_source_tree(tree_file): def unpack_source_tree(tree_file, dir=None):
dir = tempfile.mkdtemp() if dir is None:
dir = tempfile.mkdtemp()
header = []
cur_file = None cur_file = None
for line in open(tree_file).readlines(): for line in open(tree_file).readlines():
if line[:5] == '#####': if line[:5] == '#####':
filename = line.strip().strip('#').strip() filename = line.strip().strip('#').strip().replace('/', os.path.sep)
path = os.path.join(dir, filename) path = os.path.join(dir, filename)
print os.path.dirname(path)
if not os.path.exists(os.path.dirname(path)): if not os.path.exists(os.path.dirname(path)):
print " ...creating"
os.makedirs(os.path.dirname(path)) os.makedirs(os.path.dirname(path))
cur_file = open(path, 'w') cur_file = open(path, 'w')
elif cur_file is not None: elif cur_file is not None:
cur_file.write(line) cur_file.write(line)
return dir else:
header.append(line)
return dir, ''.join(header)
...@@ -28,7 +28,7 @@ from distutils.core import Extension ...@@ -28,7 +28,7 @@ from distutils.core import Extension
from distutils.command.build_ext import build_ext as _build_ext from distutils.command.build_ext import build_ext as _build_ext
distutils_distro = Distribution() distutils_distro = Distribution()
TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr'] TEST_DIRS = ['compile', 'errors', 'run', 'wrappers', 'pyregr', 'build']
TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr'] TEST_RUN_DIRS = ['run', 'wrappers', 'pyregr']
# Lists external modules, and a matcher matching tests # Lists external modules, and a matcher matching tests
...@@ -162,6 +162,9 @@ class TestBuilder(object): ...@@ -162,6 +162,9 @@ class TestBuilder(object):
filenames = os.listdir(path) filenames = os.listdir(path)
filenames.sort() filenames.sort()
for filename in filenames: 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")): if not (filename.endswith(".pyx") or filename.endswith(".py")):
continue continue
if filename.startswith('.'): continue # certain emacs backup files if filename.startswith('.'): continue # certain emacs backup files
...@@ -623,6 +626,47 @@ def collect_doctests(path, module_prefix, suite, selectors): ...@@ -623,6 +626,47 @@ def collect_doctests(path, module_prefix, suite, selectors):
except ValueError: # no tests except ValueError: # no tests
pass 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: Support cython_freeze needed here as well.
# TODO: Windows support. # TODO: Windows support.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment