Exemple #1
0
def test_all():
    parsers = ['gccxml', 'clang']
    cases = [{'parser': p} for p in parsers]

    cwd = os.getcwd()
    base = os.path.dirname(cwd)
    path = base
    if 'PYTHONPATH' in os.environ:
        path = path+':'+os.environ['PYTHONPATH']
    pyexec = sys.executable
    xdexec = os.path.join(base, 'scripts', 'xdress')
    defaults = {'cwd': cwd, 'base': base, 'pyexec': pyexec, 'xdexec': xdexec,
                'instdir': INSTDIR, 'rootdir': ROOTDIR, 'path': path,
                'builddir': os.path.join(PROJDIR, 'build')}

    commands = (
        'PYTHONPATH="{path}" {pyexec} {xdexec} --debug -p={parser} --builddir="{builddir}"\n'
        '{pyexec} setup.py install --prefix="{instdir}" --root="{rootdir}" -- --\n'
        )

    for case in cases:
        parser = case['parser']
        instdir = case['instdir'] = defaults['instdir'] + '-' + parser
        builddir = case['builddir'] = defaults['builddir'] + '-' + parser
        if not PARSERS_AVAILABLE[parser]:
            yield skip_then_continue, parser + " unavailable"
            continue
        cleanfs(GENERATED_PATHS)
        rtn = 1
        holdsrtn = [rtn]  # needed because nose does not send() to test generator
        fill = dict(defaults)
        fill.update(case)
        cmds = commands.format(**fill).strip().splitlines()
        for cmd in cmds:
            yield check_cmd, cmd, PROJDIR, holdsrtn
            rtn = holdsrtn[0]
            if rtn != 0:
                break  # don't execute further commands
        if rtn != 0:
            break  # don't try further cases

        # we have now run xdress and build the project
        # What follow are project unit tests, no need to break on these
        instsite = os.path.join(instdir, 'lib', 'python*', 'site-packages')
        instsite = glob.glob(instsite)[0]
        instproj = os.path.join(instsite, PROJNAME)

        for testfile in dirtests(TESTDIR):
            with clean_import(testfile, [TESTDIR, instproj, instsite]) as testmod:
                for test in modtests(testmod):
                    print(test)
                    yield test
    else:
        cleanfs(GENERATED_PATHS)