How to use is_virtualenv method in prospector

Best Python code snippet using prospector_python

virtualenv.py

Source:virtualenv.py Github

copy

Full Screen

...20 venv_dir = path.join(env.VIRTUALENV_PREFIX, venv_dir)21 else:22 user_home = run('USER_HOME=$(eval echo ~${SUDO_USER}) && echo ${USER_HOME}')23 venv_dir = path.join(user_home, 'w', venv_dir)24 if is_virtualenv(venv_dir):25 return26 if env.VIRTUALENV_BIN:27 virtualenv_bin = env.VIRTUALENV_BIN28 command = '%(virtualenv_bin)s "%(venv_dir)s"' % locals()29 else:30 if package.is_virtualenv_installed_in_system():31 virtualenv_bin = 'virtualenv'32 else:33 virtualenv_bin = '~/.local/bin/virtualenv'34 command = '%(virtualenv_bin)s --quiet "%(venv_dir)s"' % locals()35 run(command)36 if not sub_dirs:37 sub_dirs = ['logs', 'etc', 'tmp']38 if 'VIRTUALENV_SUB_DIRS' in env:39 sub_dirs = list(set(sub_dirs + env.VIRTUALENV_SUB_DIRS))40 for sub_dir in sub_dirs:41 fs.ensure_dir(path.join(venv_dir, sub_dir))42@contextmanager43def activate(venv_dir, local=False):44 """45 用来启用VirtualEnv的上下文管理器46 ::47 with virtualenv('/path/to/virtualenv'):48 run('python -V')49 .. _virtual environment: http://www.virtualenv.org/50 """51 if not venv_dir.startswith('/'):52 if 'VIRTUALENV_PREFIX' in env:53 venv_dir = path.join(env.VIRTUALENV_PREFIX, venv_dir)54 else:55 user_home = run('USER_HOME=$(eval echo ~${SUDO_USER}) && echo ${USER_HOME}')56 venv_dir = path.join(user_home, 'w', venv_dir)57 if not is_virtualenv(venv_dir):58 raise Exception('无效虚拟环境: %s' % venv_dir)59 join = path.join if local else posixpath.join60 with prefix('. "%s"' % join(venv_dir, 'bin', 'activate')):61 env.CURRENT_VIRTUAL_ENV_DIR = venv_dir62 yield63 # del env['CURRENT_VIRTUAL_ENV_DIR']64def is_virtualenv(venv_dir):65 """判断指定的虚拟环境是否正确"""66 return exists(path.join(venv_dir, 'bin', 'activate'))67def remove(venv_dir):68 """删除指定的虚拟环境"""69 answer = prompt(u"确定删除虚拟环境:%s (y/n)?" % venv_dir)70 if answer.lower() in ['y', 'yes']:71 if is_virtualenv(venv_dir):72 process.kill_by_name(path.join(venv_dir, 'bin'))...

Full Screen

Full Screen

test_python.py

Source:test_python.py Github

copy

Full Screen

1"""2Python interpreter and environment tests.3These need to be executed with the standard library unittest.4Third party test runners such as pytest cannot be used because5that would interfere with the tests.6"""7import platform8import sys9import unittest10import site11ENV = "@env@"12INTERPRETER = "@interpreter@"13PYTHON_VERSION = "@pythonVersion@"14IS_VIRTUALENV = @is_virtualenv@15IS_VENV = @is_venv@16IS_NIXENV = @is_nixenv@17IS_PYPY = platform.python_implementation() == "PyPy"18class TestCasePython(unittest.TestCase):19 @unittest.skipIf(IS_PYPY, "Executable is incorrect and needs to be fixed.")20 def test_interpreter(self):21 self.assertEqual(sys.executable, INTERPRETER)22 @unittest.skipIf(IS_PYPY, "Prefix is incorrect and needs to be fixed.")23 def test_prefix(self):24 self.assertEqual(sys.prefix, ENV)25 self.assertEqual(sys.prefix, sys.exec_prefix)26 def test_site_prefix(self):27 self.assertTrue(sys.prefix in site.PREFIXES)28 @unittest.skipIf(IS_PYPY or sys.version_info.major==2, "Python 2 does not have base_prefix")29 def test_base_prefix(self):30 if IS_VENV or IS_NIXENV or IS_VIRTUALENV:31 self.assertNotEqual(sys.prefix, sys.base_prefix)32 else:33 self.assertEqual(sys.prefix, sys.base_prefix)34 @unittest.skipIf(sys.version_info.major==3, "sys.real_prefix is only set by virtualenv in case of Python 2.")35 def test_real_prefix(self):36 self.assertTrue(hasattr(sys, "real_prefix") == IS_VIRTUALENV)37 def test_python_version(self):38 self.assertTrue(platform.python_version().startswith(PYTHON_VERSION))39if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful