def test_virtualenv(): from metrique.utils import virtualenv_activate, virtualenv_deactivate from metrique.utils import active_virtualenv av = active_virtualenv orig_venv = av() if not orig_venv: # this test will only work if we START in a virtenv # otherwise, we don't know of a virtenv we can test against return assert av() == os.environ['VIRTUAL_ENV'] assert virtualenv_deactivate() is True assert virtualenv_deactivate() is None assert av() == '' assert '' == os.environ['VIRTUAL_ENV'] virtualenv_activate(orig_venv) assert av() == os.environ['VIRTUAL_ENV'] assert av() == orig_venv assert virtualenv_activate() is None assert virtualenv_activate(orig_venv) is None try: virtualenv_activate('virtenv_that_doesnt_exist') except OSError: pass else: assert False, "Activated non-existing virtenv"
def _deploy_virtenv_init(args): _virtenv = utils.active_virtualenv() virtenv = getattr(args, 'virtenv') or _virtenv # skip if we're already in the targeted virtenv... if virtenv and virtenv != _virtenv: # we can't alrady be in a virtenv when running virtualenv.main() utils.virtualenv_deactivate() # scratch the existing virtenv directory, if requested if args.trash: utils.remove_file(virtenv, force=True) if args.trash_home: trash() # virtualenv.main; pass in only the virtenv path sys.argv = sys.argv[0:1] + [virtenv] # run the virtualenv script to install the virtenv virtualenv.main() # activate the newly installed virtenv utils.virtualenv_activate(args.virtenv) return virtenv