[Pytest-commit] commit/tox: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jun 20 11:09:13 EDT 2016


2 new commits in tox:

https://bitbucket.org/hpk42/tox/commits/7d13d24f0d04/
Changeset:   7d13d24f0d04
Branch:      config-in-setup-cfg
User:        Walter Scheper
Date:        2016-03-11 02:43:49+00:00
Summary:     Support configuration through setup.cfg

When the usual search for a config file fails, try loading setup.cfg
with a section prefix of tox. Modeled on coverage's use of setup.cfg as
an alternative config file.
Affected #:  2 files

diff -r 4dbfb1f1eb86b35cbd2c83461e1e294651e89cf6 -r 7d13d24f0d0463663c75a5b4ccac7c5a8eb37b6f tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -632,6 +632,55 @@
         py.test.raises(tox.exception.ConfigError, 'reader.getbool("key5")')
 
 
+class TestIniParserPrefix:
+    def test_basic_section_access(self, tmpdir, newconfig):
+        config = newconfig("""
+            [p:section]
+            key=value
+        """)
+        reader = SectionReader("section", config._cfg, prefix="p")
+        x = reader.getstring("key")
+        assert x == "value"
+        assert not reader.getstring("hello")
+        x = reader.getstring("hello", "world")
+        assert x == "world"
+
+    def test_fallback_sections(self, tmpdir, newconfig):
+        config = newconfig("""
+            [p:mydefault]
+            key2=value2
+            [p:section]
+            key=value
+        """)
+        reader = SectionReader("section", config._cfg, prefix="p",
+                               fallbacksections=['p:mydefault'])
+        x = reader.getstring("key2")
+        assert x == "value2"
+        x = reader.getstring("key3")
+        assert not x
+        x = reader.getstring("key3", "world")
+        assert x == "world"
+
+    def test_value_matches_prefixed_section_substituion(self):
+        assert is_section_substitution("{[p:setup]commands}")
+
+    def test_value_doesn_match_prefixed_section_substitution(self):
+        assert is_section_substitution("{[p: ]commands}") is None
+        assert is_section_substitution("{[p:setup]}") is None
+        assert is_section_substitution("{[p:setup] commands}") is None
+
+    def test_other_section_substitution(self, newconfig):
+        config = newconfig("""
+            [p:section]
+            key = rue
+            [p:testenv]
+            key = t{[p:section]key}
+            """)
+        reader = SectionReader("testenv", config._cfg, prefix="p")
+        x = reader.getstring("key")
+        assert x == "true"
+
+
 class TestConfigTestEnv:
     def test_commentchars_issue33(self, tmpdir, newconfig):
         config = newconfig("""

diff -r 4dbfb1f1eb86b35cbd2c83461e1e294651e89cf6 -r 7d13d24f0d0463663c75a5b4ccac7c5a8eb37b6f tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -224,7 +224,10 @@
             if inipath.check():
                 break
         else:
-            feedback("toxini file %r not found" % (basename), sysexit=True)
+            inipath = py.path.local().join('setup.cfg')
+            if not inipath.check():
+                feedback("toxini file %r not found" % (basename), sysexit=True)
+
     try:
         parseini(config, inipath)
     except tox.exception.InterpreterNotFound:
@@ -644,12 +647,18 @@
         self._cfg = py.iniconfig.IniConfig(config.toxinipath)
         config._cfg = self._cfg
         self.config = config
+
+        if inipath.basename == 'setup.cfg':
+            prefix = 'tox'
+        else:
+            prefix = None
         ctxname = getcontextname()
         if ctxname == "jenkins":
-            reader = SectionReader("tox:jenkins", self._cfg, fallbacksections=['tox'])
+            reader = SectionReader("tox:jenkins", self._cfg, prefix=prefix,
+                                   fallbacksections=['tox'])
             distshare_default = "{toxworkdir}/distshare"
         elif not ctxname:
-            reader = SectionReader("tox", self._cfg)
+            reader = SectionReader("tox", self._cfg, prefix=prefix)
             distshare_default = "{homedir}/.tox/distshare"
         else:
             raise ValueError("invalid context")
@@ -853,8 +862,12 @@
 
 
 class SectionReader:
-    def __init__(self, section_name, cfgparser, fallbacksections=None, factors=()):
-        self.section_name = section_name
+    def __init__(self, section_name, cfgparser, fallbacksections=None,
+                 factors=(), prefix=None):
+        if prefix is None:
+            self.section_name = section_name
+        else:
+            self.section_name = "%s:%s" % (prefix, section_name)
         self._cfg = cfgparser
         self.fallbacksections = fallbacksections or []
         self.factors = factors


https://bitbucket.org/hpk42/tox/commits/9f48a8fc6246/
Changeset:   9f48a8fc6246
User:        aostr123
Date:        2016-06-20 15:09:00+00:00
Summary:     Merged in wscheper/tox/config-in-setup-cfg (pull request #192)

Support configuration through setup.cfg
Affected #:  2 files

diff -r 1503c3a65bc8035d091155fcf410cf24d07dd677 -r 9f48a8fc624684ca6b5ea93ff36463850b3854b7 tests/test_config.py
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -646,6 +646,55 @@
         py.test.raises(tox.exception.ConfigError, 'reader.getbool("key5")')
 
 
+class TestIniParserPrefix:
+    def test_basic_section_access(self, tmpdir, newconfig):
+        config = newconfig("""
+            [p:section]
+            key=value
+        """)
+        reader = SectionReader("section", config._cfg, prefix="p")
+        x = reader.getstring("key")
+        assert x == "value"
+        assert not reader.getstring("hello")
+        x = reader.getstring("hello", "world")
+        assert x == "world"
+
+    def test_fallback_sections(self, tmpdir, newconfig):
+        config = newconfig("""
+            [p:mydefault]
+            key2=value2
+            [p:section]
+            key=value
+        """)
+        reader = SectionReader("section", config._cfg, prefix="p",
+                               fallbacksections=['p:mydefault'])
+        x = reader.getstring("key2")
+        assert x == "value2"
+        x = reader.getstring("key3")
+        assert not x
+        x = reader.getstring("key3", "world")
+        assert x == "world"
+
+    def test_value_matches_prefixed_section_substituion(self):
+        assert is_section_substitution("{[p:setup]commands}")
+
+    def test_value_doesn_match_prefixed_section_substitution(self):
+        assert is_section_substitution("{[p: ]commands}") is None
+        assert is_section_substitution("{[p:setup]}") is None
+        assert is_section_substitution("{[p:setup] commands}") is None
+
+    def test_other_section_substitution(self, newconfig):
+        config = newconfig("""
+            [p:section]
+            key = rue
+            [p:testenv]
+            key = t{[p:section]key}
+            """)
+        reader = SectionReader("testenv", config._cfg, prefix="p")
+        x = reader.getstring("key")
+        assert x == "true"
+
+
 class TestConfigTestEnv:
     def test_commentchars_issue33(self, tmpdir, newconfig):
         config = newconfig("""

diff -r 1503c3a65bc8035d091155fcf410cf24d07dd677 -r 9f48a8fc624684ca6b5ea93ff36463850b3854b7 tox/config.py
--- a/tox/config.py
+++ b/tox/config.py
@@ -225,7 +225,10 @@
             if inipath.check():
                 break
         else:
-            feedback("toxini file %r not found" % (basename), sysexit=True)
+            inipath = py.path.local().join('setup.cfg')
+            if not inipath.check():
+                feedback("toxini file %r not found" % (basename), sysexit=True)
+
     try:
         parseini(config, inipath)
     except tox.exception.InterpreterNotFound:
@@ -652,12 +655,18 @@
         self._cfg = py.iniconfig.IniConfig(config.toxinipath)
         config._cfg = self._cfg
         self.config = config
+
+        if inipath.basename == 'setup.cfg':
+            prefix = 'tox'
+        else:
+            prefix = None
         ctxname = getcontextname()
         if ctxname == "jenkins":
-            reader = SectionReader("tox:jenkins", self._cfg, fallbacksections=['tox'])
+            reader = SectionReader("tox:jenkins", self._cfg, prefix=prefix,
+                                   fallbacksections=['tox'])
             distshare_default = "{toxworkdir}/distshare"
         elif not ctxname:
-            reader = SectionReader("tox", self._cfg)
+            reader = SectionReader("tox", self._cfg, prefix=prefix)
             distshare_default = "{homedir}/.tox/distshare"
         else:
             raise ValueError("invalid context")
@@ -871,8 +880,12 @@
 
 
 class SectionReader:
-    def __init__(self, section_name, cfgparser, fallbacksections=None, factors=()):
-        self.section_name = section_name
+    def __init__(self, section_name, cfgparser, fallbacksections=None,
+                 factors=(), prefix=None):
+        if prefix is None:
+            self.section_name = section_name
+        else:
+            self.section_name = "%s:%s" % (prefix, section_name)
         self._cfg = cfgparser
         self.fallbacksections = fallbacksections or []
         self.factors = factors

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