summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorholger krekel <holger@merlinux.eu>2016-06-20 17:40:38 +0200
committerholger krekel <holger@merlinux.eu>2016-06-20 17:40:38 +0200
commitcef9d6b5edf6c40362b0cf40c81201f7092607c4 (patch)
treed000893d48950409d5831228e5d559cd9ef4b606
parentdc11f23e50f7814d332f164892a5f99109a07cb4 (diff)
parentdc873c46cc856c050a7431d68e4e26e98e9de891 (diff)
downloadtox-cef9d6b5edf6c40362b0cf40c81201f7092607c4.tar.gz
merge
-rw-r--r--tests/test_config.py51
-rw-r--r--tox.ini3
-rw-r--r--tox/_pytestplugin.py2
-rw-r--r--tox/config.py31
-rw-r--r--tox/session.py1
5 files changed, 75 insertions, 13 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index 86eb9f1..08b2f23 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("""
@@ -1441,7 +1490,7 @@ class TestGlobalOptions:
minversion = 10.0
"""
with py.test.raises(tox.exception.MinVersionError):
- config = newconfig([], inisource)
+ newconfig([], inisource)
def test_skip_missing_interpreters_true(self, tmpdir, newconfig, monkeypatch):
inisource = """
diff --git a/tox.ini b/tox.ini
index 3dd30dc..a2bbd96 100644
--- a/tox.ini
+++ b/tox.ini
@@ -34,7 +34,7 @@ platform=linux
deps = pytest-flakes>=0.2
pytest-pep8
-commands =
+commands =
py.test --flakes -m flakes tox tests
py.test --pep8 -m pep8 tox tests
@@ -60,3 +60,4 @@ pep8maxlinelength = 99
# E731 - do not assign a lambda expression, use a def
pep8ignore =
*.py W503 E402 E731
+flakes-ignore = ImportStarUsage
diff --git a/tox/_pytestplugin.py b/tox/_pytestplugin.py
index 4dfc497..785070d 100644
--- a/tox/_pytestplugin.py
+++ b/tox/_pytestplugin.py
@@ -195,7 +195,7 @@ class Cmd:
return py.std.subprocess.Popen(argv, stdout=stdout, stderr=stderr, **kw)
def run(self, *argv):
- if argv[0] == "tox" and sys.version_info[:2] < (2,7):
+ if argv[0] == "tox" and sys.version_info[:2] < (2, 7):
pytest.skip("can not run tests involving calling tox on python2.6. "
"(and python2.6 is about to be deprecated anyway)")
argv = [str(x) for x in argv]
diff --git a/tox/config.py b/tox/config.py
index 2d2a536..bc7ca02 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:
@@ -523,10 +526,10 @@ def tox_addoption(parser):
parser.add_testenv_attribute_obj(InstallcmdOption())
parser.add_testenv_attribute(
- name = "list_dependencies_command",
- type = "argv",
- default = "python -m pip freeze",
- help = "list dependencies for a virtual environment")
+ name="list_dependencies_command",
+ type="argv",
+ default="python -m pip freeze",
+ help="list dependencies for a virtual environment")
parser.add_testenv_attribute_obj(DepOption())
@@ -655,12 +658,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")
@@ -876,8 +885,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
diff --git a/tox/session.py b/tox/session.py
index 1d51b92..cb5cc66 100644
--- a/tox/session.py
+++ b/tox/session.py
@@ -537,7 +537,6 @@ class Session:
# write out version dependency information
action = self.newaction(venv, "envreport")
with action:
- python = venv.getcommandpath("python")
args = venv.envconfig.list_dependencies_command
output = venv._pcall(args,
cwd=self.config.toxinidir,