示例#1
0
def test_ignore_environ(workon_home, env1, env2):
    with temp_environ():
        del os.environ['VIRTUAL_ENV']
        with TemporaryDirectory() as tmpdir:
            res = invoke('workon', 'env1', inp='pew setproject env2 ' + tmpdir)
            assert not (workon_home / 'env1' / '.project').exists()
            assert check_project_dir(workon_home, 'env2', tmpdir)
示例#2
0
def inve(env, command, *args, exec_=False, **kwargs):
    """Run a command in the given virtual environment.

    If not execcing (replacing the python process with the specified process),
    pass additional keyword arguments to ``subprocess.check_call()``."""
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        os.environ['VIRTUAL_ENV'] = str(workon_home / env)
        os.environ['PATH'] = compute_path(env)

        unsetenv('PYTHONHOME')
        unsetenv('__PYVENV_LAUNCHER__')

        parser = InveParser()
        parser.read(os.path.join(os.environ['VIRTUAL_ENV'], '.inve.ini'))
        os.environ.update(parser.section_items('env', os.environ))

        if exec_:
            if 'cwd' in kwargs:
                os.chdir(kwargs['cwd'])
            os.execvp(command, [command] + list(args))
        else:
            try:
                return check_call([command] + list(args), shell=windows,
                    **kwargs)
                # need to have shell=True on windows, otherwise the PYTHONPATH
                # won't inherit the PATH
            except OSError as e:
                if e.errno == 2:
                    err('Unable to find', command)
                else:
                    raise
示例#3
0
def test_setproject(workon_home, env1):
    with temp_environ():
        del os.environ['VIRTUAL_ENV']
        with TemporaryDirectory() as tmpdir:
            res = invoke('setproject', 'env1', tmpdir)
            assert not res.err
            assert check_project_dir(workon_home, 'env1', tmpdir)
示例#4
0
文件: pew.py 项目: jck/pew
def inve(env, *args, **kwargs):
    assert args
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        envdir = workon_home / env
        os.environ['VIRTUAL_ENV'] = str(envdir)
        os.environ['PATH'] = os.pathsep.join([
            str(envdir / env_bin_dir),
            os.environ['PATH'],
        ])

        unsetenv('PYTHONHOME')
        unsetenv('__PYVENV_LAUNCHER__')

        try:
            return check_call(args, shell=windows, **kwargs)
            # need to have shell=True on windows, otherwise the PYTHONPATH
            # won't inherit the PATH
        except OSError as e:
            if e.errno == 2:
                print(kwargs)
                sys.stderr.write("Unable to find %s\n" % args[0])
            else:
                raise
示例#5
0
def test_setproject(workon_home, env1):
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            res = invoke('setproject', 'env1', tmpdir)
            assert not res.err
            assert check_project_dir(workon_home, 'env1', tmpdir)
示例#6
0
文件: pew.py 项目: zofuthan/pew
def inve(env, *args, **kwargs):
    assert args
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        envdir = workon_home / env
        os.environ['VIRTUAL_ENV'] = str(envdir)
        os.environ['PATH'] = os.pathsep.join([
            str(envdir / env_bin_dir),
            os.environ['PATH'],
        ])

        unsetenv('PYTHONHOME')
        unsetenv('__PYVENV_LAUNCHER__')

        try:
            return check_call(args, shell=windows, **kwargs)
            # need to have shell=True on windows, otherwise the PYTHONPATH
            # won't inherit the PATH
        except OSError as e:
            if e.errno == 2:
                print(kwargs)
                sys.stderr.write("Unable to find %s\n" % args[0])
            else:
                raise
示例#7
0
def test_ignore_environ(workon_home, env1, env2):
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            res = invoke('workon', 'env1', inp='pew setproject env2 ' + tmpdir)
            assert not (workon_home / 'env1' / '.project').exists()
            assert check_project_dir(workon_home, 'env2', tmpdir)
示例#8
0
def test_implicit_project(workon_home, env1):
    "use the cwd as project directory"
    with temp_environ():
        del os.environ['VIRTUAL_ENV']
        with TemporaryDirectory() as tmpdir:
            res = invoke('setproject', 'env1', cwd=tmpdir)
            assert not res.err
            assert check_project_dir(workon_home, 'env1', tmpdir)
示例#9
0
def test_implicit_project(workon_home, env1):
    "use the cwd as project directory"
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            res = invoke('setproject', 'env1', cwd=tmpdir)
            assert not res.err
            assert check_project_dir(workon_home, 'env1', tmpdir)
示例#10
0
def test_same_workon_and_project_home(workon_home, project_home):
    with temp_environ():
        os.environ['PROJECT_HOME'] = str(workon_home)
        envname = 'whatever'
        with pytest.raises(CalledProcessError):
            check_call('pew mkproject {0} -d'.format(envname).split())
        assert (workon_home / envname).exists()
        assert not (project_home / envname).exists()
示例#11
0
def test_same_workon_and_project_home(workon_home, project_home):
    with temp_environ():
        os.environ['PROJECT_HOME'] = str(workon_home)
        envname = 'whatever'
        with pytest.raises(CalledProcessError):
            check_call('pew mkproject {0} -d'.format(envname).split())
        assert (workon_home / envname).exists()
        assert not (project_home / envname).exists()
示例#12
0
def test_getproject(env1):
    """Check that ``getproject`` prints an environment's project directory."""
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            invoke('setproject', 'env1', tmpdir)
            res = invoke('getproject', 'env1')
            assert not res.err
            assert res.out == tmpdir
示例#13
0
def test_getproject(env1):
    """Check that ``getproject`` prints an environment's project directory."""
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            invoke('setproject', 'env1', tmpdir)
            res = invoke('getproject', 'env1')
            assert not res.err
            assert res.out == tmpdir
示例#14
0
def test_detect_shell():
    with temp_environ():
        try:
            del os.environ['SHELL']
        except KeyError:
            pass
        if sys.platform == 'win32':
            assert _detect_shell() in ['python.exe']
        else:
            assert _detect_shell() == 'sh'
        os.environ['SHELL'] = 'foo'
        assert _detect_shell() == 'foo'
示例#15
0
def test_project_directory_not_set(env1):
    """Check the error message if no project directory was set.

    If no project directory has been configured for an environment,
    ``getproject`` should quit with an error message.
    """
    name = 'env1'
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            res = invoke('getproject', name)
            assert not res.out
            assert res.err == (
                "ERROR: no project directory set for Environment '{0}'".format(
                    name))
示例#16
0
def test_project_directory_not_set(env1):
    """Check the error message if no project directory was set.

    If no project directory has been configured for an environment,
    ``getproject`` should quit with an error message.
    """
    name = 'env1'
    with temp_environ():
        os.environ.pop('VIRTUAL_ENV', None)
        with TemporaryDirectory() as tmpdir:
            res = invoke('getproject', name)
            assert not res.out
            assert res.err == (
                "ERROR: no project directory set for Environment '{0}'"
                .format(name)
            )
示例#17
0
def test_detect_shell():
    with temp_environ():
        try:
            del os.environ['SHELL']
        except KeyError:
            pass
        if sys.platform == 'win32':
            # NOTE: This assumes your current shell is CMD, and would fail if
            # you run the test in e.g. Powershell. You can safely ignore the
            # error as long as the _detect_shell() makes sense to you.
            # Hint: Disable this test like this: pytest -m 'not shell'
            # https://github.com/berdario/pew/pull/204#discussion_r273835108
            assert _detect_shell() == 'cmd.exe'
        else:
            assert _detect_shell() == 'sh'
        os.environ['SHELL'] = 'foo'
        assert _detect_shell() == 'foo'
示例#18
0
文件: test_workon.py 项目: tjanez/pew
def test_detect_shell():
    with temp_environ():
        try:
            del os.environ['SHELL']
        except KeyError:
            pass
        if sys.platform == 'win32':
            # NOTE: This assumes your current shell is CMD, and would fail if
            # you run the test in e.g. Powershell. You can safely ignore the
            # error as long as the _detect_shell() makes sense to you.
            # Hint: Disable this test like this: pytest -m 'not shell'
            # https://github.com/berdario/pew/pull/204#discussion_r273835108
            assert _detect_shell() == 'cmd.exe'
        else:
            assert _detect_shell() == 'sh'
        os.environ['SHELL'] = 'foo'
        assert _detect_shell() == 'foo'
示例#19
0
文件: pew.py 项目: alimuldal/pew
def inve(env, command, *args, **kwargs):
    """Run a command in the given virtual environment.

    Pass additional keyword arguments to ``subprocess.check_call()``."""
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        os.environ['VIRTUAL_ENV'] = str(workon_home / env)
        os.environ['PATH'] = compute_path(env)

        unsetenv('PYTHONHOME')
        unsetenv('__PYVENV_LAUNCHER__')

        try:
            return check_call([command] + list(args), shell=windows, **kwargs)
            # need to have shell=True on windows, otherwise the PYTHONPATH
            # won't inherit the PATH
        except OSError as e:
            if e.errno == 2:
                sys.stderr.write("Unable to find %s\n" % command)
            else:
                raise
示例#20
0
文件: pew.py 项目: berdario/pew
def inve(env, command, *args, **kwargs):
    """Run a command in the given virtual environment.

    Pass additional keyword arguments to ``subprocess.check_call()``."""
    # we don't strictly need to restore the environment, since pew runs in
    # its own process, but it feels like the right thing to do
    with temp_environ():
        os.environ["VIRTUAL_ENV"] = str(workon_home / env)
        os.environ["PATH"] = compute_path(env)

        unsetenv("PYTHONHOME")
        unsetenv("__PYVENV_LAUNCHER__")

        try:
            return check_call([command] + list(args), shell=windows, **kwargs)
            # need to have shell=True on windows, otherwise the PYTHONPATH
            # won't inherit the PATH
        except OSError as e:
            if e.errno == 2:
                err("Unable to find", command)
            else:
                raise
示例#21
0
def test_invalid_pew_workon_env_name(workon_home):
    with temp_environ():
        assert 'Invalid environment' in invoke('workon', '/home/toto').err
示例#22
0
def test_no_pew_workon_home(workon_home):
    with temp_environ():
        os.environ['WORKON_HOME'] += '/not_there'
        assert 'does not exist' in invoke('workon', 'doesnt_exist').err
示例#23
0
def test_invalid_pew_workon_env_name(workon_home):
    with temp_environ():
        assert 'Invalid environment' in invoke('workon', '/home/toto').err
示例#24
0
def test_no_project_home(project_home):
    with temp_environ():
        os.environ['PROJECT_HOME'] += '/not_there'
        with pytest.raises(CalledProcessError):
            check_call('pew mkproject whatever -d'.split())
示例#25
0
def test_no_project_home(project_home):
    with temp_environ():
        os.environ['PROJECT_HOME'] += '/not_there'
        with pytest.raises(CalledProcessError):
            check_call('pew mkproject whatever -d'.split())
示例#26
0
文件: test_workon.py 项目: arthru/pew
def test_no_pew_workon_home(workon_home):
    with temp_environ():
        os.environ['WORKON_HOME'] += '/not_there'
        assert 'does not exist' in invoke('in', 'doesnt_exist').err