[Pytest-commit] commit/tox: hpk42: make tox_get_python_executable hook receive "envconfig" instead of just basepython setting

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sun May 10 16:13:05 CEST 2015


1 new commit in tox:

https://bitbucket.org/hpk42/tox/commits/5bf717febabd/
Changeset:   5bf717febabd
Branch:      pluggy
User:        hpk42
Date:        2015-05-10 14:12:52+00:00
Summary:     make tox_get_python_executable hook receive "envconfig" instead of just basepython setting
Affected #:  5 files

diff -r 581c658b9b3978c753213450cce5b8222100d232 -r 5bf717febabda1de4f8db338e983832d54c25e59 tests/test_interpreters.py
--- a/tests/test_interpreters.py
+++ b/tests/test_interpreters.py
@@ -31,7 +31,10 @@
 
 
 def test_tox_get_python_executable():
-    p = tox_get_python_executable(sys.executable)
+    class envconfig:
+        basepython = sys.executable
+        envname = "pyxx"
+    p = tox_get_python_executable(envconfig)
     assert p == py.path.local(sys.executable)
     for ver in [""] + "2.4 2.5 2.6 2.7 3.0 3.1 3.2 3.3".split():
         name = "python%s" % ver
@@ -44,7 +47,8 @@
         else:
             if not py.path.local.sysfind(name):
                 continue
-        p = tox_get_python_executable(name)
+        envconfig.basepython = name
+        p = tox_get_python_executable(envconfig)
         assert p
         popen = py.std.subprocess.Popen([str(p), '-V'],
                                         stderr=py.std.subprocess.PIPE)
@@ -57,7 +61,12 @@
     def sysfind(x):
         return "hello"
     monkeypatch.setattr(py.path.local, "sysfind", sysfind)
-    t = tox_get_python_executable("qweqwe")
+
+    class envconfig:
+        basepython = "1lk23j"
+        envname = "pyxx"
+
+    t = tox_get_python_executable(envconfig)
     assert t == "hello"
 
 
@@ -71,31 +80,33 @@
 
 class TestInterpreters:
 
-    def test_get_info_self_exceptions(self, interpreters):
-        pytest.raises(ValueError, lambda:
-                      interpreters.get_info())
-        pytest.raises(ValueError, lambda:
-                      interpreters.get_info(name="12", executable="123"))
+    def test_get_executable(self, interpreters):
+        class envconfig:
+            basepython = sys.executable
+            envname = "pyxx"
 
-    def test_get_executable(self, interpreters):
-        x = interpreters.get_executable(sys.executable)
+        x = interpreters.get_executable(envconfig)
         assert x == sys.executable
-        assert not interpreters.get_executable("12l3k1j23")
-
-    def test_get_info__name(self, interpreters):
-        info = interpreters.get_info(executable=sys.executable)
+        info = interpreters.get_info(envconfig)
         assert info.version_info == tuple(sys.version_info)
         assert info.executable == sys.executable
         assert info.runnable
 
-    def test_get_info__name_not_exists(self, interpreters):
-        info = interpreters.get_info("qlwkejqwe")
+    def test_get_executable_no_exist(self, interpreters):
+        class envconfig:
+            basepython = "1lkj23"
+            envname = "pyxx"
+        assert not interpreters.get_executable(envconfig)
+        info = interpreters.get_info(envconfig)
         assert not info.version_info
-        assert info.name == "qlwkejqwe"
+        assert info.name == "1lkj23"
         assert not info.executable
         assert not info.runnable
 
     def test_get_sitepackagesdir_error(self, interpreters):
-        info = interpreters.get_info(sys.executable)
+        class envconfig:
+            basepython = sys.executable
+            envname = "123"
+        info = interpreters.get_info(envconfig)
         s = interpreters.get_sitepackagesdir(info, "")
         assert s

diff -r 581c658b9b3978c753213450cce5b8222100d232 -r 5bf717febabda1de4f8db338e983832d54c25e59 tests/test_venv.py
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -35,6 +35,7 @@
     py.test.raises(tox.exception.UnsupportedInterpreter,
                    venv.getsupportedinterpreter)
     monkeypatch.undo()
+    monkeypatch.setattr(venv.envconfig, "envname", "py1")
     monkeypatch.setattr(venv.envconfig, 'basepython', 'notexistingpython')
     py.test.raises(tox.exception.InterpreterNotFound,
                    venv.getsupportedinterpreter)
@@ -42,7 +43,7 @@
     # check that we properly report when no version_info is present
     info = NoInterpreterInfo(name=venv.name)
     info.executable = "something"
-    monkeypatch.setattr(config.interpreters, "get_info", lambda *args: info)
+    monkeypatch.setattr(config.interpreters, "get_info", lambda *args, **kw: info)
     pytest.raises(tox.exception.InvocationError, venv.getsupportedinterpreter)
 
 

diff -r 581c658b9b3978c753213450cce5b8222100d232 -r 5bf717febabda1de4f8db338e983832d54c25e59 tox/_config.py
--- a/tox/_config.py
+++ b/tox/_config.py
@@ -226,14 +226,14 @@
 
     @property
     def python_info(self):
-        return self.config.interpreters.get_info(self.basepython)
+        return self.config.interpreters.get_info(envconfig=self)
 
     def getsupportedinterpreter(self):
         if sys.platform == "win32" and self.basepython and \
                 "jython" in self.basepython:
             raise tox.exception.UnsupportedInterpreter(
                 "Jython/Windows does not support installing scripts")
-        info = self.config.interpreters.get_info(self.basepython)
+        info = self.config.interpreters.get_info(envconfig=self)
         if not info.executable:
             raise tox.exception.InterpreterNotFound(self.basepython)
         if not info.version_info:

diff -r 581c658b9b3978c753213450cce5b8222100d232 -r 5bf717febabda1de4f8db338e983832d54c25e59 tox/hookspecs.py
--- a/tox/hookspecs.py
+++ b/tox/hookspecs.py
@@ -22,7 +22,11 @@
 
 
 @hookspec(firstresult=True)
-def tox_get_python_executable(name):
+def tox_get_python_executable(envconfig):
     """ return a python executable for the given python base name.
     The first plugin/hook which returns an executable path will determine it.
+
+    ``envconfig`` is the testenv configuration which contains
+    per-testenv configuration, notably the ``.envname`` and ``.basepython``
+    setting.
     """

diff -r 581c658b9b3978c753213450cce5b8222100d232 -r 5bf717febabda1de4f8db338e983832d54c25e59 tox/interpreters.py
--- a/tox/interpreters.py
+++ b/tox/interpreters.py
@@ -11,26 +11,22 @@
         self.executable2info = {}
         self.hook = hook
 
-    def get_executable(self, name):
+    def get_executable(self, envconfig):
         """ return path object to the executable for the given
         name (e.g. python2.6, python2.7, python etc.)
         if name is already an existing path, return name.
         If an interpreter cannot be found, return None.
         """
         try:
-            return self.name2executable[name]
+            return self.name2executable[envconfig.envname]
         except KeyError:
-            exe = self.hook.tox_get_python_executable(name=name)
-            self.name2executable[name] = exe
+            exe = self.hook.tox_get_python_executable(envconfig=envconfig)
+            self.name2executable[envconfig.envname] = exe
             return exe
 
-    def get_info(self, name=None, executable=None):
-        if name is None and executable is None:
-            raise ValueError("need to specify name or executable")
-        if name:
-            if executable is not None:
-                raise ValueError("cannot specify both name, executable")
-            executable = self.get_executable(name)
+    def get_info(self, envconfig):
+        executable = self.get_executable(envconfig)
+        name = envconfig.basepython
         if not executable:
             return NoInterpreterInfo(name=name)
         try:
@@ -129,12 +125,13 @@
 
 if sys.platform != "win32":
     @hookimpl
-    def tox_get_python_executable(name):
-        return py.path.local.sysfind(name)
+    def tox_get_python_executable(envconfig):
+        return py.path.local.sysfind(envconfig.basepython)
 
 else:
     @hookimpl
-    def tox_get_python_executable(name):
+    def tox_get_python_executable(envconfig):
+        name = envconfig.basepython
         p = py.path.local.sysfind(name)
         if p:
             return p

Repository URL: https://bitbucket.org/hpk42/tox/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list