|
7 | 7 | import pytest |
8 | 8 |
|
9 | 9 | from tox.config import get_plugin_manager |
| 10 | +from tox.interpreters import ExecFailed |
| 11 | +from tox.interpreters import InterpreterInfo |
10 | 12 | from tox.interpreters import Interpreters |
| 13 | +from tox.interpreters import NoInterpreterInfo |
| 14 | +from tox.interpreters import pyinfo |
11 | 15 | from tox.interpreters import run_and_get_interpreter_info |
| 16 | +from tox.interpreters import sitepackagesdir |
12 | 17 | from tox.interpreters import tox_get_python_executable |
13 | 18 |
|
14 | 19 |
|
@@ -70,7 +75,8 @@ class envconfig: |
70 | 75 | envconfig.basepython = name |
71 | 76 | p = tox_get_python_executable(envconfig) |
72 | 77 | assert p |
73 | | - popen = subprocess.Popen([str(p), '-V'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
| 78 | + popen = subprocess.Popen([str(p), '-V'], stderr=subprocess.PIPE, |
| 79 | + stdout=subprocess.PIPE) |
74 | 80 | stdout, stderr = popen.communicate() |
75 | 81 | assert not stdout or not stderr |
76 | 82 | assert ver in stderr.decode('ascii') or ver in stdout.decode('ascii') |
@@ -130,3 +136,92 @@ class envconfig: |
130 | 136 | info = interpreters.get_info(envconfig) |
131 | 137 | s = interpreters.get_sitepackagesdir(info, "") |
132 | 138 | assert s |
| 139 | + |
| 140 | + |
| 141 | +def test_pyinfo(monkeypatch): |
| 142 | + monkeypatch.setattr(sys, "version_info", [42, 4242]) |
| 143 | + monkeypatch.setattr(sys, "platform", "an unladen swallow") |
| 144 | + result = pyinfo() |
| 145 | + assert len(result) == 2 |
| 146 | + assert result["version_info"] == (42, 4242) |
| 147 | + assert result["sysplatform"] == "an unladen swallow" |
| 148 | + |
| 149 | + |
| 150 | +def test_sitepackagesdir(monkeypatch): |
| 151 | + import distutils.sysconfig as sysconfig |
| 152 | + test_envdir = "holy grail" |
| 153 | + test_dir = "Now go away or I will taunt you a second time." |
| 154 | + |
| 155 | + def dummy_get_python_lib(prefix): |
| 156 | + assert prefix is test_envdir |
| 157 | + return test_dir |
| 158 | + |
| 159 | + monkeypatch.setattr(sysconfig, "get_python_lib", dummy_get_python_lib) |
| 160 | + assert sitepackagesdir(test_envdir) == {"dir": test_dir} |
| 161 | + |
| 162 | + |
| 163 | +def test_exec_failed(): |
| 164 | + x = ExecFailed("my-executable", "my-source", "my-out", "my-err") |
| 165 | + assert isinstance(x, Exception) |
| 166 | + assert x.executable == "my-executable" |
| 167 | + assert x.source == "my-source" |
| 168 | + assert x.out == "my-out" |
| 169 | + assert x.err == "my-err" |
| 170 | + |
| 171 | + |
| 172 | +class TestInterpreterInfo: |
| 173 | + |
| 174 | + def info(self, name="my-name", executable="my-executable", |
| 175 | + version_info="my-version-info", sysplatform="my-sys-platform"): |
| 176 | + return InterpreterInfo(name, executable, version_info, sysplatform) |
| 177 | + |
| 178 | + def test_runnable(self): |
| 179 | + assert self.info().runnable |
| 180 | + |
| 181 | + @pytest.mark.parametrize("missing_arg", ("executable", "version_info")) |
| 182 | + def test_assert_on_missing_args(self, missing_arg): |
| 183 | + with pytest.raises(AssertionError): |
| 184 | + self.info(**{missing_arg: None}) |
| 185 | + |
| 186 | + def test_data(self): |
| 187 | + x = self.info("larry", "moe", "shemp", "curly") |
| 188 | + assert x.name == "larry" |
| 189 | + assert x.executable == "moe" |
| 190 | + assert x.version_info == "shemp" |
| 191 | + assert x.sysplatform == "curly" |
| 192 | + |
| 193 | + def test_str(self): |
| 194 | + x = self.info(executable="foo", version_info="bar") |
| 195 | + assert str(x) == "<executable at foo, version_info bar>" |
| 196 | + |
| 197 | + |
| 198 | +class TestNoInterpreterInfo: |
| 199 | + |
| 200 | + def test_runnable(self): |
| 201 | + assert not NoInterpreterInfo("foo").runnable |
| 202 | + assert not NoInterpreterInfo("foo", executable=sys.executable).runnable |
| 203 | + |
| 204 | + def test_default_data(self): |
| 205 | + x = NoInterpreterInfo("foo") |
| 206 | + assert x.name == "foo" |
| 207 | + assert x.executable is None |
| 208 | + assert x.version_info is None |
| 209 | + assert x.out is None |
| 210 | + assert x.err == "not found" |
| 211 | + |
| 212 | + def test_set_data(self): |
| 213 | + x = NoInterpreterInfo("migraine", executable="my-executable", |
| 214 | + out="my-out", err="my-err") |
| 215 | + assert x.name == "migraine" |
| 216 | + assert x.executable == "my-executable" |
| 217 | + assert x.version_info is None |
| 218 | + assert x.out == "my-out" |
| 219 | + assert x.err == "my-err" |
| 220 | + |
| 221 | + def test_str_without_executable(self): |
| 222 | + x = NoInterpreterInfo("coconut") |
| 223 | + assert str(x) == "<executable not found for: coconut>" |
| 224 | + |
| 225 | + def test_str_with_executable(self): |
| 226 | + x = NoInterpreterInfo("coconut", executable="bang/em/together") |
| 227 | + assert str(x) == "<executable at bang/em/together, not runnable>" |
0 commit comments