How to use getcommandpath method in tox

Best Python code snippet using tox_python

test_venv.py

Source:test_venv.py Github

copy

Full Screen

...56 if sys.platform != "win32":57 # realpath is needed for stuff like the debian symlinks58 assert py.path.local(sys.executable).realpath() == py.path.local(args[0]).realpath()59 # assert Envconfig.toxworkdir in args60 assert venv.getcommandpath("easy_install", cwd=py.path.local())61 interp = venv._getliveconfig().python62 assert interp == venv.envconfig.python_info.executable63 assert venv.path_config.check(exists=False)64@pytest.mark.skipif("sys.platform == 'win32'")65def test_commandpath_venv_precendence(tmpdir, monkeypatch,66 mocksession, newconfig):67 config = newconfig([], """68 [testenv:py123]69 """)70 envconfig = config.envconfigs['py123']71 venv = VirtualEnv(envconfig, session=mocksession)72 tmpdir.ensure("easy_install")73 monkeypatch.setenv("PATH", str(tmpdir), prepend=os.pathsep)74 envconfig.envbindir.ensure("easy_install")75 p = venv.getcommandpath("easy_install")76 assert py.path.local(p).relto(envconfig.envbindir), p77def test_create_sitepackages(monkeypatch, mocksession, newconfig):78 config = newconfig([], """79 [testenv:site]80 sitepackages=True81 [testenv:nosite]82 sitepackages=False83 """)84 envconfig = config.envconfigs['site']85 venv = VirtualEnv(envconfig, session=mocksession)86 venv.create()87 l = mocksession._pcalls88 assert len(l) >= 189 args = l[0].args90 assert "--system-site-packages" in map(str, args)91 mocksession._clearmocks()92 envconfig = config.envconfigs['nosite']93 venv = VirtualEnv(envconfig, session=mocksession)94 venv.create()95 l = mocksession._pcalls96 assert len(l) >= 197 args = l[0].args98 assert "--system-site-packages" not in map(str, args)99 assert "--no-site-packages" not in map(str, args)100def test_install_deps_wildcard(newmocksession):101 mocksession = newmocksession([], """102 [tox]103 distshare = {toxworkdir}/distshare104 [testenv:py123]105 deps=106 {distshare}/dep1-*107 """)108 venv = mocksession.getenv("py123")109 venv.create()110 l = mocksession._pcalls111 assert len(l) == 1112 distshare = venv.session.config.distshare113 distshare.ensure("dep1-1.0.zip")114 distshare.ensure("dep1-1.1.zip")115 venv.install_deps()116 assert len(l) == 2117 args = l[-1].args118 assert l[-1].cwd == venv.envconfig.config.toxinidir119 assert "pip" in str(args[0])120 assert args[1] == "install"121 # arg = "--download-cache=" + str(venv.envconfig.downloadcache)122 # assert arg in args[2:]123 args = [arg for arg in args if str(arg).endswith("dep1-1.1.zip")]124 assert len(args) == 1125@pytest.mark.parametrize("envdc", [True, False])126def test_install_downloadcache(newmocksession, monkeypatch, tmpdir, envdc):127 if envdc:128 monkeypatch.setenv("PIP_DOWNLOAD_CACHE", tmpdir)129 else:130 monkeypatch.delenv("PIP_DOWNLOAD_CACHE", raising=False)131 mocksession = newmocksession([], """132 [testenv:py123]133 deps=134 dep1135 dep2136 """)137 venv = mocksession.getenv("py123")138 venv.create()139 l = mocksession._pcalls140 assert len(l) == 1141 venv.install_deps()142 assert len(l) == 2143 args = l[-1].args144 assert l[-1].cwd == venv.envconfig.config.toxinidir145 assert "pip" in str(args[0])146 assert args[1] == "install"147 assert "dep1" in args148 assert "dep2" in args149 deps = list(filter(None, [x[1] for x in venv._getliveconfig().deps]))150 assert deps == ['dep1', 'dep2']151def test_install_deps_indexserver(newmocksession):152 mocksession = newmocksession([], """153 [tox]154 indexserver =155 abc = ABC156 abc2 = ABC157 [testenv:py123]158 deps=159 dep1160 :abc:dep2161 :abc2:dep3162 """)163 venv = mocksession.getenv('py123')164 venv.create()165 l = mocksession._pcalls166 assert len(l) == 1167 l[:] = []168 venv.install_deps()169 # two different index servers, two calls170 assert len(l) == 3171 args = " ".join(l[0].args)172 assert "-i " not in args173 assert "dep1" in args174 args = " ".join(l[1].args)175 assert "-i ABC" in args176 assert "dep2" in args177 args = " ".join(l[2].args)178 assert "-i ABC" in args179 assert "dep3" in args180def test_install_deps_pre(newmocksession):181 mocksession = newmocksession([], """182 [testenv]183 pip_pre=true184 deps=185 dep1186 """)187 venv = mocksession.getenv('python')188 venv.create()189 l = mocksession._pcalls190 assert len(l) == 1191 l[:] = []192 venv.install_deps()193 assert len(l) == 1194 args = " ".join(l[0].args)195 assert "--pre " in args196 assert "dep1" in args197def test_installpkg_indexserver(newmocksession, tmpdir):198 mocksession = newmocksession([], """199 [tox]200 indexserver =201 default = ABC202 """)203 venv = mocksession.getenv('python')204 l = mocksession._pcalls205 p = tmpdir.ensure("distfile.tar.gz")206 mocksession.installpkg(venv, p)207 # two different index servers, two calls208 assert len(l) == 1209 args = " ".join(l[0].args)210 assert "-i ABC" in args211def test_install_recreate(newmocksession, tmpdir):212 pkg = tmpdir.ensure("package.tar.gz")213 mocksession = newmocksession(['--recreate'], """214 [testenv]215 deps=xyz216 """)217 venv = mocksession.getenv('python')218 venv.update()219 mocksession.installpkg(venv, pkg)220 mocksession.report.expect("verbosity0", "*create*")221 venv.update()222 mocksession.report.expect("verbosity0", "*recreate*")223def test_test_hashseed_is_in_output(newmocksession):224 original_make_hashseed = tox_plus.config.make_hashseed225 tox_plus.config.make_hashseed = lambda: '123456789'226 try:227 mocksession = newmocksession([], '''228 [testenv]229 ''')230 finally:231 tox_plus.config.make_hashseed = original_make_hashseed232 venv = mocksession.getenv('python')233 venv.update()234 venv.test()235 mocksession.report.expect("verbosity0", "python runtests: PYTHONHASHSEED='123456789'")236def test_test_runtests_action_command_is_in_output(newmocksession):237 mocksession = newmocksession([], '''238 [testenv]239 commands = echo foo bar240 ''')241 venv = mocksession.getenv('python')242 venv.update()243 venv.test()244 mocksession.report.expect("verbosity0", "*runtests*commands?0? | echo foo bar")245def test_install_error(newmocksession, monkeypatch):246 mocksession = newmocksession(['--recreate'], """247 [testenv]248 deps=xyz249 commands=250 qwelkqw251 """)252 venv = mocksession.getenv('python')253 venv.test()254 mocksession.report.expect("error", "*not find*qwelkqw*")255 assert venv.status == "commands failed"256def test_install_command_not_installed(newmocksession, monkeypatch):257 mocksession = newmocksession(['--recreate'], """258 [testenv]259 commands=260 py.test261 """)262 venv = mocksession.getenv('python')263 venv.test()264 mocksession.report.expect("warning", "*test command found but not*")265 assert venv.status == 0266def test_install_command_whitelisted(newmocksession, monkeypatch):267 mocksession = newmocksession(['--recreate'], """268 [testenv]269 whitelist_externals = py.test270 xy*271 commands=272 py.test273 xyz274 """)275 venv = mocksession.getenv('python')276 venv.test()277 mocksession.report.expect("warning", "*test command found but not*",278 invert=True)279 assert venv.status == "commands failed"280@pytest.mark.skipif("not sys.platform.startswith('linux')")281def test_install_command_not_installed_bash(newmocksession):282 mocksession = newmocksession(['--recreate'], """283 [testenv]284 commands=285 bash286 """)287 venv = mocksession.getenv('python')288 venv.test()289 mocksession.report.expect("warning", "*test command found but not*")290def test_install_python3(tmpdir, newmocksession):291 if not py.path.local.sysfind('python3.3'):292 pytest.skip("needs python3.3")293 mocksession = newmocksession([], """294 [testenv:py123]295 basepython=python3.3296 deps=297 dep1298 dep2299 """)300 venv = mocksession.getenv('py123')301 venv.create()302 l = mocksession._pcalls303 assert len(l) == 1304 args = l[0].args305 assert str(args[2]) == 'virtualenv'306 l[:] = []307 action = mocksession.newaction(venv, "hello")308 venv._install(["hello"], action=action)309 assert len(l) == 1310 args = l[0].args311 assert 'pip' in str(args[0])312 for x in args:313 assert "--download-cache" not in args, args314class TestCreationConfig:315 def test_basic(self, newconfig, mocksession, tmpdir):316 config = newconfig([], "")317 envconfig = config.envconfigs['python']318 venv = VirtualEnv(envconfig, session=mocksession)319 cconfig = venv._getliveconfig()320 assert cconfig.matches(cconfig)321 path = tmpdir.join("configdump")322 cconfig.writeconfig(path)323 newconfig = CreationConfig.readconfig(path)324 assert newconfig.matches(cconfig)325 assert cconfig.matches(newconfig)326 def test_matchingdependencies(self, newconfig, mocksession):327 config = newconfig([], """328 [testenv]329 deps=abc330 """)331 envconfig = config.envconfigs['python']332 venv = VirtualEnv(envconfig, session=mocksession)333 cconfig = venv._getliveconfig()334 config = newconfig([], """335 [testenv]336 deps=xyz337 """)338 envconfig = config.envconfigs['python']339 venv = VirtualEnv(envconfig, session=mocksession)340 otherconfig = venv._getliveconfig()341 assert not cconfig.matches(otherconfig)342 def test_matchingdependencies_file(self, newconfig, mocksession):343 config = newconfig([], """344 [tox]345 distshare={toxworkdir}/distshare346 [testenv]347 deps=abc348 {distshare}/xyz.zip349 """)350 xyz = config.distshare.join("xyz.zip")351 xyz.ensure()352 envconfig = config.envconfigs['python']353 venv = VirtualEnv(envconfig, session=mocksession)354 cconfig = venv._getliveconfig()355 assert cconfig.matches(cconfig)356 xyz.write("hello")357 newconfig = venv._getliveconfig()358 assert not cconfig.matches(newconfig)359 def test_matchingdependencies_latest(self, newconfig, mocksession):360 config = newconfig([], """361 [tox]362 distshare={toxworkdir}/distshare363 [testenv]364 deps={distshare}/xyz-*365 """)366 config.distshare.ensure("xyz-1.2.0.zip")367 xyz2 = config.distshare.ensure("xyz-1.2.1.zip")368 envconfig = config.envconfigs['python']369 venv = VirtualEnv(envconfig, session=mocksession)370 cconfig = venv._getliveconfig()371 md5, path = cconfig.deps[0]372 assert path == xyz2373 assert md5 == path.computehash()374 def test_python_recreation(self, tmpdir, newconfig, mocksession):375 pkg = tmpdir.ensure("package.tar.gz")376 config = newconfig([], "")377 envconfig = config.envconfigs['python']378 venv = VirtualEnv(envconfig, session=mocksession)379 cconfig = venv._getliveconfig()380 venv.update()381 assert not venv.path_config.check()382 mocksession.installpkg(venv, pkg)383 assert venv.path_config.check()384 assert mocksession._pcalls385 args1 = map(str, mocksession._pcalls[0].args)386 assert 'virtualenv' in " ".join(args1)387 mocksession.report.expect("*", "*create*")388 # modify config and check that recreation happens389 mocksession._clearmocks()390 venv.update()391 mocksession.report.expect("*", "*reusing*")392 mocksession._clearmocks()393 cconfig.python = py.path.local("balla")394 cconfig.writeconfig(venv.path_config)395 venv.update()396 mocksession.report.expect("verbosity0", "*recreate*")397 def test_dep_recreation(self, newconfig, mocksession):398 config = newconfig([], "")399 envconfig = config.envconfigs['python']400 venv = VirtualEnv(envconfig, session=mocksession)401 venv.update()402 cconfig = venv._getliveconfig()403 cconfig.deps[:] = [("1" * 32, "xyz.zip")]404 cconfig.writeconfig(venv.path_config)405 mocksession._clearmocks()406 venv.update()407 mocksession.report.expect("*", "*recreate*")408 def test_develop_recreation(self, newconfig, mocksession):409 config = newconfig([], "")410 envconfig = config.envconfigs['python']411 venv = VirtualEnv(envconfig, session=mocksession)412 venv.update()413 cconfig = venv._getliveconfig()414 cconfig.usedevelop = True415 cconfig.writeconfig(venv.path_config)416 mocksession._clearmocks()417 venv.update()418 mocksession.report.expect("verbosity0", "*recreate*")419class TestVenvTest:420 def test_envbinddir_path(self, newmocksession, monkeypatch):421 monkeypatch.setenv("PIP_RESPECT_VIRTUALENV", "1")422 mocksession = newmocksession([], """423 [testenv:python]424 commands=abc425 """)426 venv = mocksession.getenv("python")427 monkeypatch.setenv("PATH", "xyz")428 l = []429 monkeypatch.setattr("py.path.local.sysfind", classmethod(430 lambda *args, **kwargs: l.append(kwargs) or 0 / 0))431 py.test.raises(ZeroDivisionError, "venv._install(list('123'))")432 assert l.pop()["paths"] == [venv.envconfig.envbindir]433 py.test.raises(ZeroDivisionError, "venv.test()")434 assert l.pop()["paths"] == [venv.envconfig.envbindir]435 py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'])")436 assert l.pop()["paths"] == [venv.envconfig.envbindir]437 monkeypatch.setenv("PIP_RESPECT_VIRTUALENV", "1")438 monkeypatch.setenv("PIP_REQUIRE_VIRTUALENV", "1")439 monkeypatch.setenv("__PYVENV_LAUNCHER__", "1")440 py.test.raises(ZeroDivisionError, "venv.run_install_command(['qwe'])")441 assert 'PIP_RESPECT_VIRTUALENV' not in os.environ442 assert 'PIP_REQUIRE_VIRTUALENV' not in os.environ443 assert '__PYVENV_LAUNCHER__' not in os.environ444def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig, monkeypatch):445 pkg = tmpdir.ensure("package.tar.gz")446 monkeypatch.setenv("X123", "123")447 monkeypatch.setenv("YY", "456")448 config = newconfig([], """449 [testenv:python]450 commands=python -V451 passenv = x123452 setenv =453 ENV_VAR = value454 """)455 mocksession._clearmocks()456 venv = VirtualEnv(config.envconfigs['python'], session=mocksession)457 # import pdb; pdb.set_trace()458 mocksession.installpkg(venv, pkg)459 venv.test()460 l = mocksession._pcalls461 assert len(l) == 2462 for x in l:463 env = x.env464 assert env is not None465 assert 'ENV_VAR' in env466 assert env['ENV_VAR'] == 'value'467 assert env['VIRTUAL_ENV'] == str(venv.path)468 assert env['X123'] == "123"469 # all env variables are passed for installation470 assert l[0].env["YY"] == "456"471 assert "YY" not in l[1].env472 assert set(["ENV_VAR", "VIRTUAL_ENV", "PYTHONHASHSEED", "X123", "PATH"])\473 .issubset(l[1].env)474 # for e in os.environ:475 # assert e in env476def test_installpkg_no_upgrade(tmpdir, newmocksession):477 pkg = tmpdir.ensure("package.tar.gz")478 mocksession = newmocksession([], "")479 venv = mocksession.getenv('python')480 venv.just_created = True481 venv.envconfig.envdir.ensure(dir=1)482 mocksession.installpkg(venv, pkg)483 l = mocksession._pcalls484 assert len(l) == 1485 assert '-U' not in l[0].args486def test_installpkg_upgrade(newmocksession, tmpdir):487 pkg = tmpdir.ensure("package.tar.gz")488 mocksession = newmocksession([], "")489 venv = mocksession.getenv('python')490 assert not hasattr(venv, 'just_created')491 mocksession.installpkg(venv, pkg)492 l = mocksession._pcalls493 assert len(l) == 1494 index = l[0].args.index(str(pkg))495 assert index >= 0496 assert '-U' in l[0].args[:index]497 assert '--no-deps' in l[0].args[:index]498def test_run_install_command(newmocksession):499 mocksession = newmocksession([], "")500 venv = mocksession.getenv('python')501 venv.just_created = True502 venv.envconfig.envdir.ensure(dir=1)503 action = mocksession.newaction(venv, "hello")504 venv.run_install_command(packages=["whatever"], action=action)505 l = mocksession._pcalls506 assert len(l) == 1507 assert 'pip' in l[0].args[0]508 assert 'install' in l[0].args509 env = l[0].env510 assert env is not None511def test_run_custom_install_command(newmocksession):512 mocksession = newmocksession([], """513 [testenv]514 install_command=easy_install {opts} {packages}515 """)516 venv = mocksession.getenv('python')517 venv.just_created = True518 venv.envconfig.envdir.ensure(dir=1)519 action = mocksession.newaction(venv, "hello")520 venv.run_install_command(packages=["whatever"], action=action)521 l = mocksession._pcalls522 assert len(l) == 1523 assert 'easy_install' in l[0].args[0]524 assert l[0].args[1:] == ['whatever']525def test_command_relative_issue26(newmocksession, tmpdir, monkeypatch):526 mocksession = newmocksession([], """527 [testenv]528 """)529 x = tmpdir.ensure("x")530 venv = mocksession.getenv("python")531 x2 = venv.getcommandpath("./x", cwd=tmpdir)532 assert x == x2533 mocksession.report.not_expect("warning", "*test command found but not*")534 x3 = venv.getcommandpath("/bin/bash", cwd=tmpdir)535 assert x3 == "/bin/bash"536 mocksession.report.not_expect("warning", "*test command found but not*")537 monkeypatch.setenv("PATH", str(tmpdir))538 x4 = venv.getcommandpath("x", cwd=tmpdir)539 assert x4.endswith(os.sep + 'x')...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...26 version = "%s.%s" % m.groups()27 else:28 raise exception.UnsupporterInterpreter(29 'TOX-EDM cannot infer version from {!r}'.format(name))30 edm = venv.getcommandpath('edm', venv=False)31 action.venv.envconfig.whitelist_externals.append(32 os.path.dirname(edm))33 if action.activity == 'recreate':34 action.popen([35 edm, 'envs', 'create', action.venvname,36 '--force', '--version', version])37 elif not env_exists(edm, action.venvname):38 action.popen([39 edm, 'envs', 'create', action.venvname,40 '--version', version])41 prefix = action.popen(42 [edm, 'prefix', '-e', action.venvname],43 redirect=False, returnout=True)44 prefix = prefix.strip()45 # The envbindir will be used to find the environment python46 # So we have to make sure that it has the right value.47 action.venv.envconfig.envbindir = prefix48 action.venv.envconfig.whitelist_externals.append(prefix)49 return True50@hookimpl51def tox_testenv_install_deps(venv, action):52 deps = venv._getresolvedeps()53 name = action.venvname54 if len(deps) > 0:55 edm = venv.getcommandpath('edm', venv=False)56 depinfo = " ".join(map(str, deps))57 action.setactivity("installdeps", "%s" % depinfo)58 args = [edm, 'install', '-e', name, '-y'] + map(str, deps)59 action.popen(args)60 return True61@hookimpl62def tox_runenvreport(venv, action):63 edm = venv.getcommandpath('edm', venv=True)64 output = action.popen([65 edm, 'run', '-e', action.venvname, '--',66 'pip', 'freeze'])67 output = output.split("\n\n")[-1]68 return output.strip().splitlines()69@hookimpl70def tox_runtest_pre(venv):71 return True72@hookimpl73def tox_runtest_post(venv):74 return True75@hookimpl76def tox_runtest(venv, redirect):77 session = venv.session78 envconfig = venv.envconfig79 action = session.newaction(venv, "runtests")80 with action:81 venv.status = 082 session.make_emptydir(envconfig.envtmpdir)83 envconfig.envtmpdir.ensure(dir=1)84 env = venv._getenv(testcommand=True)85 cwd = envconfig.changedir86 edm = venv.getcommandpath('edm', venv=True)87 action.setactivity(88 "runtests", "PYTHONHASHSEED={!r}".format(89 env.get("PYTHONHASHSEED")))90 for i, argv in enumerate(envconfig.commands):91 message = "commands[%s] | %s" % (92 i, ' '.join([str(x) for x in argv]))93 action.setactivity("runtests", message)94 ignore_return = argv[0].startswith("-")95 if ignore_return:96 if argv[0] == "-":97 del argv[0]98 else:99 argv[0] = argv[0].lstrip("-")100 argv = [edm, 'run', '-e', action.venvname, '--'] + argv101 try:102 action.popen(103 argv, cwd=cwd, env=env, redirect=redirect,104 ignore_ret=ignore_return)105 except exception.InvocationError as error:106 if envconfig.ignore_outcome:107 session.report.warning(COMMAND_FAILED.format(error))108 venv.status = "ignored failed command"109 continue # keep processing commands110 session.report.error(str(error))111 venv.status = "commands failed"112 if not envconfig.ignore_errors:113 break # Don't process remaining commands114 except KeyboardInterrupt:115 venv.status = "keyboardinterrupt"116 session.report.error(venv.status)117 raise118 return True119@hookimpl120def tox_get_python_executable(envconfig):121 venv = VirtualEnv(envconfig=envconfig)122 edm = venv.getcommandpath('edm', venv=False)123 if env_exists(edm, envconfig.envname):124 executable = subprocess.check_output([125 str(edm), 'run', '-e', envconfig.envname, '--',126 'python', '-c',127 "import sys; sys.stdout.write(sys.executable)"])128 executable = executable.strip()129 if sys.platform.startswith('win'):130 # Make sure that we always have the right bin directory131 envconfig.envbindir = os.path.join(132 os.path.dirname(executable), 'Scripts')133 return os.path.abspath(executable)134 else:...

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 tox 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