Commits

Ronny Pfannschmidt  committed a57776f

support custom test context via env var

  • Participants
  • Parent commits e05ee5c

Comments (0)

Files changed (3)

File context-discovery

+# HG changeset patch
+# Parent 2f09e8e28076d9d0d9f9dc14152cb1a74f13d8bf
+allow to set test context via env var
+
+diff --git a/tests/test_config.py b/tests/test_config.py
+--- a/tests/test_config.py
++++ b/tests/test_config.py
+@@ -3,7 +3,7 @@ import os, sys
+ from textwrap import dedent
+ 
+ import py
+-from tox._config import IniReader, CommandParser
++from tox._config import IniReader, CommandParser, getcontextname
+ 
+ class TestVenvConfig:
+     def test_config_parsing_minimal(self, tmpdir, newconfig):
+@@ -720,6 +720,24 @@ class TestIndexServer:
+         assert config.indexserver['name1'].url == "abc"
+ 
+ 
++class TestContext:
++
++    def test_context_normal(self, monkeypatch):
++        monkeypatch.delenv('HUDSON_URL',raising=False)
++        monkeypatch.delenv('TOX_CONTEXT',raising=False)
++        assert getcontextname() is None
++
++    def test_jenkins_context(self, monkeypatch):
++        monkeypatch.setenv('HUDSON_URL','test')
++        # atm hudson overrules other contexts
++        monkeypatch.setenv('TOX_CONTEXT','test')
++        assert getcontextname() == 'jenkins'
++
++    def test_userdefined_context(self, monkeypatch):
++        monkeypatch.delenv('HUDSON_URL',raising=False)
++        monkeypatch.setenv('TOX_CONTEXT','test')
++        assert getcontextname() == 'test'
++
+ class TestParseEnv:
+ 
+     def test_parse_recreate(self, newconfig):
+diff --git a/tox/_config.py b/tox/_config.py
+--- a/tox/_config.py
++++ b/tox/_config.py
+@@ -586,4 +586,4 @@ class CommandParser(object):
+ def getcontextname():
+     if 'HUDSON_URL' in os.environ:
+         return 'jenkins'
+-    return None
++    return os.environ.get('TOX_CONTEXT')

File referential-substitution

-# HG changeset patch
-# Parent c28e706bfcf8dcd15a1ef9da906dbc1e9a868596
-use dollar sign to allow referential substitusion with values from other sections
-
-diff --git a/tests/test_config.py b/tests/test_config.py
---- a/tests/test_config.py
-+++ b/tests/test_config.py
-@@ -480,6 +480,82 @@ class TestConfigTestEnv:
-         argv = conf.commands
-         assert argv[0] == ["cmd1", "hello"]
- 
-+    def test_take_dependencies_from_other_testenv(self, newconfig):
-+        inisource="""
-+            [testenv]
-+            deps=
-+                pytest
-+                pytest-cov
-+            [testenv:py24]
-+            deps=
-+                {testenv$deps}
-+                fun
-+        """
-+        conf = newconfig([], inisource).envconfigs['py24']
-+        packages = [dep.name for dep in conf.deps]
-+        assert packages == ['pytest', 'pytest-cov', 'fun']
-+
-+    def test_take_dependencies_from_other_section(self, newconfig):
-+        inisource="""
-+            [testing:pytest]
-+            deps=
-+                pytest
-+                pytest-cov
-+            [testing:mock]
-+            deps=
-+                mock
-+            [testenv]
-+            deps=
-+                {testing:pytest$deps}
-+                {testing:mock$deps}
-+                fun
-+        """
-+        conf = newconfig([], inisource)
-+        env = conf.envconfigs['python']
-+        packages = [dep.name for dep in env.deps]
-+        assert packages == ['pytest', 'pytest-cov', 'mock', 'fun']
-+
-+    def test_multilevel_substitution(self, newconfig):
-+        inisource="""
-+            [testing:pytest]
-+            deps=
-+                pytest
-+                pytest-cov
-+            [testing:mock]
-+            deps=
-+                mock
-+
-+            [testing]
-+            deps=
-+                {testing:pytest$deps}
-+                {testing:mock$deps}
-+
-+            [testenv]
-+            deps=
-+                {testing$deps}
-+                fun
-+        """
-+        conf = newconfig([], inisource)
-+        env = conf.envconfigs['python']
-+        packages = [dep.name for dep in env.deps]
-+        assert packages == ['pytest', 'pytest-cov', 'mock', 'fun']
-+
-+    def test_recursive_substitution_cycle_fails(self, newconfig):
-+        inisource="""
-+            [testing:pytest]
-+            deps=
-+                {testing:mock$deps}
-+            [testing:mock]
-+            deps=
-+                {testing:pytest$deps}
-+ 
-+            [testenv]
-+            deps=
-+                {testing:pytest$deps}
-+        """
-+        py.test.raises(ValueError, newconfig, [], inisource)
-+
-+
- class TestGlobalOptions:
-     def test_notest(self, newconfig):
-         config = newconfig([], "")
-diff --git a/tox/_config.py b/tox/_config.py
---- a/tox/_config.py
-+++ b/tox/_config.py
-@@ -277,6 +277,7 @@ class IniReader:
-         self._cfg = cfgparser
-         self.fallbacksections = fallbacksections or []
-         self._subs = {}
-+        self._subststack = []
- 
-     def addsubstitions(self, _posargs=None, **kw):
-         self._subs.update(kw)
-@@ -386,7 +387,11 @@ class IniReader:
-             else:
-                 x = default
-         if replace and x and hasattr(x, 'replace'):
--            x = self._replace(x)
-+            self._subststack.append((section, name))
-+            try:
-+                x = self._replace(x)
-+            finally:
-+                assert self._subststack.pop() == (section, name)
-         #print "getdefault", section, name, "returned", repr(x)
-         return x
- 
-@@ -400,6 +405,19 @@ class IniReader:
-                     (key, envkey))
-             return os.environ[envkey]
-         if key not in self._subs:
-+            if'$' in key:
-+                section, item = key.rsplit('$', 1)
-+
-+                if section in self._cfg and item in self._cfg[section]:
-+                    if (section, item) in self._subststack:
-+                        raise ValueError('%s already in %s' %((section, item), self._subststack))
-+                    x = str(self._cfg[section][item])
-+                    self._subststack.append((section, item))
-+                    try:
-+                        return self._replace(x)
-+                    finally:
-+                        self._subststack.pop()
-+
-             raise tox.exception.ConfigError(
-                 "substitution key %r not found" % key)
-         return str(self._subs[key])
-referential-substitution
+context-discovery