Exemple #1
0
    def __init__(self, environ=None):
        
        self.root_path = mkdtemp(prefix='pkgtest')

        # We will set up a virtual environment at root_path.  
        self.scratch_path = self.root_path / self.scratch

        self.venv_path = self.root_path / self.venv

        if not environ:
            environ = dict(((k, v) for k, v in os.environ.items()
                if not k.lower().startswith('pip_')))
            environ['PIP_DOWNLOAD_CACHE'] = str(download_cache)

        environ['PIP_NO_INPUT'] = '1'
        environ['PIP_LOG_FILE'] = str(self.root_path/'pip-log.txt')

        super(Environment,self).__init__(
            self.root_path, ignore_hidden=False, 
            environ=environ, split_cmd=False, start_clear=False,
            cwd=self.scratch_path, capture_temp=True, assert_no_temp=True
            )

        mktree(self.venv_path)
        mktree(self.scratch_path)

        use_distribute = os.environ.get('PKGTEST_USE_DISTRIBUTE', False)

        # Create a virtualenv and remember where it is putting things.
        virtualenv_paths = create_virtualenv(self.venv_path, distribute=use_distribute)

        assert self.venv_path == virtualenv_paths[0] # sanity check

        for id,path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths):
            setattr(self, id+'_path', Path(path))
            setattr(self, id, relpath(self.root_path,path))
            
        assert self.venv == Environment.venv # sanity check

        self.site_packages = self.lib/'site-packages'
        self.site_packages_path = self.lib_path/'site-packages'

        # put the virtualenv's bin dir first on the PATH; that's
        # essentially all that happens when you activate a virtualenv
        self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH']) )

        # test that test-scratch virtualenv creation produced sensible venv python
        pythonbin = self.run('python', '-c', 'import sys; print sys.executable').stdout.strip()
        if Path(pythonbin).noext != self.bin_path/'python':
            raise RuntimeError(
                "Oops! 'python' in our test environment runs %r" 
                " rather than expected %r" % (pythonbin, self.bin_path/'python'))

        # make sure we have current setuptools to avoid svn incompatibilities
        if not use_distribute:
            install_setuptools(self)
Exemple #2
0
def main(argv = []):
    global use_distribute

    # Grab this script's options
    global use_distribute
    use_distribute = ('--distribute' in argv)
    prepare_env = [x for x in argv if x.startswith('--prepare-env=')]
    argv = [x for x in argv if x != '--distribute' and not x.startswith('--prepare-env=')]

    here = Path(sys.path[0])
    script_name = Path(__file__).name

    if not (here/script_name).exists:
        here = Path(__file__).abspath.folder
        assert (here/script_name).exists, "Can't locate directory of this script"

    # Make sure all external tools are set up to be used.
    print >> sys.stderr, 'Checking for installed prerequisites in PATH:',
    for tool in ('git', 'cmake'):
        print >> sys.stderr, tool,'...',
        assert_in_path(tool)
    print >> sys.stderr, 'ok'

    ryppl_root = here.folder

    #
    # Delete everything that could lead to stale test results
    #
    clean( ryppl_root )
    
    save_dir = os.getcwd()

    if prepare_env:
        venv_dir = prepare_env[-1][len('--prepare-env='):]
        mktree(venv_dir)
    else:
        venv_dir = mkdtemp('-ryppl_self_test')

    try:
        os.chdir(venv_dir)

        #
        # Prepare a clean, writable workspace
        #
        print >> sys.stderr, 'Preparing test environment ...'
        venv, lib, include, bin = create_virtualenv(venv_dir, distribute=use_distribute)

        abs_bin = Path(bin).abspath

        # Make sure it's first in PATH
        os.environ['PATH'] = str(
            Path.pathsep.join(( abs_bin, os.environ['PATH'] ))
            )

        #
        # Install python module testing prerequisites
        #
        pip_exe = abs_bin/'pip'+EXE
        download_cache = '--download-cache=' \
            + Path(gettempdir())/'ryppl-test-download-cache'
        def pip_install(*pkg):
            print >> sys.stderr, '   pip install',' '.join(pkg), '...',
            run(pip_exe, 'install', '-q', download_cache, *pkg)
            print >> sys.stderr, 'ok'
        pip_install('virtualenv')
        pip_install('--no-index', '-f', 'http://pypi.python.org/packages/source/n/nose/', 'nose')
        pip_install('scripttest>=1.0.4')
        print >> sys.stderr, 'ok'
        nosetests = abs_bin/'nosetests'+EXE
        #
        # ericniebler, 2010-06-03:
        # --exe is to force nose to look for tests in py files the os
        # reports as executable. This is only an issue on cygwin.
        # TODO: investigate nose/config.py, which uses the following
        # global to control this behavior. It seems to have the logic
        # reversed [site-packages/nose/config.py(24)]:
        #
        # # plaforms on which the exe check defaults to off
        # # Windows and IronPython
        # exe_allowed_platforms = ('win32', 'cli')
        #
        test_cmd = [nosetests, '--exe', '-w', ryppl_root/'test'] + argv
        if prepare_env:
            print 'Testing command:'
            print ' '.join(test_cmd)
        else:
            run( *test_cmd )

    finally:
        os.chdir(save_dir)
        # Keep VCSes from seeing spurious new/changed files
        clean(ryppl_root)
Exemple #3
0
def main(argv=[]):
    global use_distribute

    # Grab this script's options
    global use_distribute
    use_distribute = ('--distribute' in argv)
    prepare_env = [x for x in argv if x.startswith('--prepare-env=')]
    argv = [
        x for x in argv
        if x != '--distribute' and not x.startswith('--prepare-env=')
    ]

    here = Path(sys.path[0])
    script_name = Path(__file__).name

    if not (here / script_name).exists:
        here = Path(__file__).abspath.folder
        assert (here /
                script_name).exists, "Can't locate directory of this script"

    # Make sure all external tools are set up to be used.
    print >> sys.stderr, 'Checking for installed prerequisites in PATH:',
    for tool in ('git', 'cmake'):
        print >> sys.stderr, tool, '...',
        assert_in_path(tool)
    print >> sys.stderr, 'ok'

    ryppl_root = here.folder

    #
    # Delete everything that could lead to stale test results
    #
    clean(ryppl_root)

    save_dir = os.getcwd()

    if prepare_env:
        venv_dir = prepare_env[-1][len('--prepare-env='):]
        mktree(venv_dir)
    else:
        venv_dir = mkdtemp('-ryppl_self_test')

    try:
        os.chdir(venv_dir)

        #
        # Prepare a clean, writable workspace
        #
        print >> sys.stderr, 'Preparing test environment ...'
        venv, lib, include, bin = create_virtualenv(venv_dir,
                                                    distribute=use_distribute)

        abs_bin = Path(bin).abspath

        # Make sure it's first in PATH
        os.environ['PATH'] = str(
            Path.pathsep.join((abs_bin, os.environ['PATH'])))

        #
        # Install python module testing prerequisites
        #
        pip_exe = abs_bin / 'pip' + EXE
        download_cache = '--download-cache=' \
            + Path(gettempdir())/'ryppl-test-download-cache'

        def pip_install(*pkg):
            print >> sys.stderr, '   pip install', ' '.join(pkg), '...',
            run(pip_exe, 'install', '-q', download_cache, *pkg)
            print >> sys.stderr, 'ok'

        pip_install('virtualenv')
        pip_install('--no-index', '-f',
                    'http://pypi.python.org/packages/source/n/nose/', 'nose')
        pip_install('scripttest>=1.0.4')
        print >> sys.stderr, 'ok'
        nosetests = abs_bin / 'nosetests' + EXE
        #
        # ericniebler, 2010-06-03:
        # --exe is to force nose to look for tests in py files the os
        # reports as executable. This is only an issue on cygwin.
        # TODO: investigate nose/config.py, which uses the following
        # global to control this behavior. It seems to have the logic
        # reversed [site-packages/nose/config.py(24)]:
        #
        # # plaforms on which the exe check defaults to off
        # # Windows and IronPython
        # exe_allowed_platforms = ('win32', 'cli')
        #
        test_cmd = [nosetests, '--exe', '-w', ryppl_root / 'test'] + argv
        if prepare_env:
            print 'Testing command:'
            print ' '.join(test_cmd)
        else:
            run(*test_cmd)

    finally:
        os.chdir(save_dir)
        # Keep VCSes from seeing spurious new/changed files
        clean(ryppl_root)