def test_setenv_added_to_pcall(mocksession, newconfig): config = newconfig([], """ [testenv:python] commands=python -V setenv = ENV_VAR = value """) mocksession._clearmocks() venv = VirtualEnv(config.envconfigs['python'], session=mocksession) # import pdb; pdb.set_trace() mocksession.installsdist(venv, "xyz") venv.test() l = mocksession._pcalls assert len(l) == 2 for x in l: args = x.args env = x.env assert env is not None assert 'ENV_VAR' in env assert env['ENV_VAR'] == 'value' for e in os.environ: assert e in env
def test_basic(self, newconfig, mocksession, tmpdir): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() assert cconfig.matches(cconfig) path = tmpdir.join("configdump") cconfig.writeconfig(path) newconfig = CreationConfig.readconfig(path) assert newconfig.matches(cconfig) assert cconfig.matches(newconfig)
def test_create_sitepackages(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:site] sitepackages=True [testenv:nosite] sitepackages=False """) envconfig = config.envconfigs['site'] venv = VirtualEnv(envconfig, session=mocksession) venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--system-site-packages" in map(str, args) mocksession._clearmocks() envconfig = config.envconfigs['nosite'] venv = VirtualEnv(envconfig, session=mocksession) venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--system-site-packages" not in map(str, args) assert "--no-site-packages" not in map(str, args)
def test_create_distribute(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:py123] distribute=False """) envconfig = config.envconfigs['py123'] venv = VirtualEnv(envconfig, session=mocksession) assert venv.path == envconfig.envdir assert not venv.path.check() venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--distribute" not in " ".join(args)
def test_create_distribute(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:py123] distribute=False """) envconfig = config.envconfigs['py123'] venv = VirtualEnv(envconfig, session=mocksession) assert venv.path == envconfig.envdir assert not venv.path.check() venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--distribute" not in map(str, args)
def test_matchingdependencies_latest(self, newconfig, mocksession): config = newconfig([], """ [tox] distshare={toxworkdir}/distshare [testenv] deps={distshare}/xyz-* """) xyz = config.distshare.ensure("xyz-1.2.0.zip") xyz2 = config.distshare.ensure("xyz-1.2.1.zip") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() md5, path = cconfig.deps[0] assert path == xyz2 assert md5 == path.computehash()
def test_matchingdependencies(self, newconfig, mocksession): config = newconfig([], """ [testenv] deps=abc """) envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() config = newconfig([], """ [testenv] deps=xyz """) envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) otherconfig = venv._getliveconfig() assert not cconfig.matches(otherconfig)
def test_getsupportedinterpreter(monkeypatch, newconfig, mocksession): config = newconfig([], """ [testenv:python] basepython=%s """ % sys.executable) venv = VirtualEnv(config.envconfigs['python'], session=mocksession) interp = venv.getsupportedinterpreter() # realpath needed for debian symlinks assert interp == py.path.local(sys.executable).realpath() monkeypatch.setattr(sys, 'platform', "win32") monkeypatch.setattr(venv.envconfig, 'basepython', 'jython') py.test.raises(tox.exception.UnsupportedInterpreter, venv.getsupportedinterpreter) monkeypatch.undo() monkeypatch.setattr(venv.envconfig, 'basepython', 'notexistingpython') py.test.raises(tox.exception.InterpreterNotFound, venv.getsupportedinterpreter)
def test_matchingdependencies_file(self, newconfig, mocksession): config = newconfig([], """ [tox] distshare={toxworkdir}/distshare [testenv] deps=abc {distshare}/xyz.zip """) xyz = config.distshare.join("xyz.zip") xyz.ensure() envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() assert cconfig.matches(cconfig) xyz.write("hello") newconfig = venv._getliveconfig() assert not cconfig.matches(newconfig)
def _makevenv(self, name): envconfig = self.config.envconfigs.get(name, None) if envconfig is None: self.report.error("unknown environment %r" % name) raise LookupError(name) venv = VirtualEnv(envconfig=envconfig, session=self) self._name2venv[name] = venv return venv
def test_dep_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) venv.update() cconfig = venv._getliveconfig() cconfig.deps[:] = [("1"*32, "xyz.zip")] cconfig.writeconfig(venv.path_config) mocksession._clearmocks() venv.update() mocksession.report.expect("*", "*recreate*")
def test_distribute_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) venv.update() cconfig = venv._getliveconfig() cconfig.distribute = False cconfig.writeconfig(venv.path_config) mocksession._clearmocks() venv.update() mocksession.report.expect("verbosity0", "*recreate*")
def test_python_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() venv.update() assert not venv.path_config.check() venv.install_sdist([]) assert venv.path_config.check() assert mocksession._pcalls args1 = map(str, mocksession._pcalls[0].args) assert 'virtualenv' in " ".join(args1) mocksession.report.expect("action", "creating virtualenv*") # modify config and check that recreation happens mocksession._clearmocks() venv.update() mocksession.report.expect("action", "reusing existing*") mocksession._clearmocks() cconfig.python = py.path.local("balla") cconfig.writeconfig(venv.path_config) venv.update() mocksession.report.expect("action", "recreating virtualenv*")
def test_setenv_added_to_pcall(mocksession, newconfig): config = newconfig([], """ [testenv:python] commands=%s -V setenv = ENV_VAR = value """ % sys.executable) mocksession._clearmocks() venv = VirtualEnv(config.envconfigs['python'], session=mocksession) # import pdb; pdb.set_trace() venv.test() l = mocksession._pcalls assert len(l) == 1 args = l[0].args env = l[0].env assert env is not None assert 'ENV_VAR' in env assert env['ENV_VAR'] == 'value' for e in os.environ: assert e in env
def test_distribute_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) venv.update() cconfig = venv._getliveconfig() cconfig.distribute = False cconfig.writeconfig(venv.path_config) mocksession._clearmocks() venv.update() mocksession.report.expect("action", "recreating virtualenv*")
def test_dep_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) venv.update() cconfig = venv._getliveconfig() cconfig.deps[:] = [("1"*32, "xyz.zip")] cconfig.writeconfig(venv.path_config) mocksession._clearmocks() venv.update() mocksession.report.expect("action", "recreating virtualenv*")
def test_python_recreation(self, newconfig, mocksession): config = newconfig([], "") envconfig = config.envconfigs['python'] venv = VirtualEnv(envconfig, session=mocksession) cconfig = venv._getliveconfig() venv.update() assert not venv.path_config.check() mocksession.installsdist(venv, "sdist.zip") assert venv.path_config.check() assert mocksession._pcalls args1 = map(str, mocksession._pcalls[0].args) assert 'virtualenv' in " ".join(args1) mocksession.report.expect("*", "*create*") # modify config and check that recreation happens mocksession._clearmocks() venv.update() mocksession.report.expect("*", "*reusing*") mocksession._clearmocks() cconfig.python = py.path.local("balla") cconfig.writeconfig(venv.path_config) venv.update() mocksession.report.expect("verbosity0", "*recreate*")
def test_create(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:py123] """) envconfig = config.envconfigs['py123'] venv = VirtualEnv(envconfig, session=mocksession) assert venv.path == envconfig.envdir assert not venv.path.check() venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert str(args[1]).endswith("virtualenv.py") if sys.platform != "win32": # realpath is needed for stuff like the debian symlinks assert py.path.local(sys.executable).realpath() == args[0] #assert Envconfig.toxworkdir in args assert venv.getcommandpath("easy_install", cwd=py.path.local()) interp = venv._getliveconfig().python assert interp == venv.getconfigexecutable() assert venv.path_config.check(exists=False)
def test_create(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:py123] """) envconfig = config.envconfigs['py123'] venv = VirtualEnv(envconfig, session=mocksession) assert venv.path == envconfig.envdir assert not venv.path.check() venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert str(args[1]).endswith("virtualenv.py") if sys.platform != "win32": # realpath is needed for stuff like the debian symlinks assert py.path.local(sys.executable).realpath() == args[0] #assert Envconfig.toxworkdir in args assert venv.getcommandpath("easy_install") interp = venv._getliveconfig().python assert interp == venv.getconfigexecutable() assert venv.path_config.check(exists=False)
def test_create_sitepackages(monkeypatch, mocksession, newconfig): config = newconfig([], """ [testenv:site] sitepackages=True [testenv:nosite] sitepackages=False """) envconfig = config.envconfigs['site'] venv = VirtualEnv(envconfig, session=mocksession) venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--no-site-packages" not in " ".join(args) mocksession._clearmocks() envconfig = config.envconfigs['nosite'] venv = VirtualEnv(envconfig, session=mocksession) venv.create() l = mocksession._pcalls assert len(l) >= 1 args = l[0].args assert "--no-site-packages" in " ".join(args)
def getenv(self, name): return VirtualEnv(self.config.envconfigs[name], session=self)