summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Ostrowski <aostr123@gmail.com>2016-06-20 17:27:44 +0200
committerAndrzej Ostrowski <aostr123@gmail.com>2016-06-20 17:27:44 +0200
commitdc873c46cc856c050a7431d68e4e26e98e9de891 (patch)
treecb0c21dee0c7daaef614c3bd865edce32dbde2ae
parent22b31834581010dd3377be2e34d58fa8b642d9e6 (diff)
parent7f6e81ed3cc787c38fe7b3068bee5497c989ad11 (diff)
downloadtox-dc873c46cc856c050a7431d68e4e26e98e9de891.tar.gz
Merged in issue336 (pull request #198)
#336 make flakes pass
-rw-r--r--tests/test_config.py49
-rw-r--r--tox/config.py23
2 files changed, 67 insertions, 5 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index 82248d8..863e55c 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -646,6 +646,55 @@ class TestIniParser:
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 --git a/tox/config.py b/tox/config.py
index f4c65dc..362459e 100644
--- a/tox/config.py
+++ b/tox/config.py
@@ -225,7 +225,10 @@ def parseconfig(args=None, plugins=()):
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 @@ class parseini:
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 @@ is_section_substitution = re.compile("{\[[^{}\s]+\]\S+?}").match
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