diff options
author | Holger Krekel <holger@merlinux.eu> | 2016-06-20 18:19:01 +0200 |
---|---|---|
committer | Holger Krekel <holger@merlinux.eu> | 2016-06-20 18:19:01 +0200 |
commit | 524486c4e2c9138f115708303de1d527a51b596d (patch) | |
tree | c4b16e29ee51e7548afbdd276881863f0456726e /tests | |
parent | fe8a1ba5216c71421f8a83ef62f3aabed634371b (diff) | |
parent | d467ba8e26bb70d4abc7b951332701ffca7fc118 (diff) | |
download | tox-524486c4e2c9138f115708303de1d527a51b596d.tar.gz |
Merged in jayvdb/tox (pull request #185)
Unescape \{..\} according to docs.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_config.py | 114 | ||||
-rw-r--r-- | tests/test_interpreters.py | 2 | ||||
-rw-r--r-- | tests/test_venv.py | 12 |
3 files changed, 118 insertions, 10 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index 7c0e411..2b81fa3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -274,6 +274,34 @@ class TestIniParserAgainstCommandsKey: ["echo", "cmd", "1", "2", "3", "4", "cmd", "2"], ] + def test_command_substitution_from_other_section_posargs(self, newconfig): + """Ensure subsitition from other section with posargs succeeds""" + config = newconfig(""" + [section] + key = thing {posargs} arg2 + [testenv] + commands = + {[section]key} + """) + reader = SectionReader("testenv", config._cfg) + reader.addsubstitutions([r"argpos"]) + x = reader.getargvlist("commands") + assert x == [['thing', 'argpos', 'arg2']] + + def test_command_section_and_posargs_substitution(self, newconfig): + """Ensure subsitition from other section with posargs succeeds""" + config = newconfig(""" + [section] + key = thing arg1 + [testenv] + commands = + {[section]key} {posargs} endarg + """) + reader = SectionReader("testenv", config._cfg) + reader.addsubstitutions([r"argpos"]) + x = reader.getargvlist("commands") + assert x == [['thing', 'arg1', 'argpos', 'endarg']] + def test_command_env_substitution(self, newconfig): """Ensure referenced {env:key:default} values are substituted correctly.""" config = newconfig(""" @@ -618,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(""" @@ -1006,6 +1083,20 @@ class TestConfigTestEnv: argv = conf.commands assert argv[0] == ["echo"] + def test_substitution_double(self, newconfig): + inisource = """ + [params] + foo = bah + foo2 = [params]foo + + [testenv:py27] + commands = + echo {{[params]foo2}} + """ + conf = newconfig([], inisource).envconfigs['py27'] + argv = conf.commands + assert argv[0] == ['echo', 'bah'] + def test_posargs_backslashed_or_quoted(self, tmpdir, newconfig): inisource = """ [testenv:py27] @@ -1410,10 +1501,10 @@ class TestGlobalOptions: def test_minversion(self, tmpdir, newconfig, monkeypatch): inisource = """ [tox] - minversion = 3.0 + minversion = 10.0 """ - config = newconfig([], inisource) - assert config.minversion == "3.0" + with py.test.raises(tox.exception.MinVersionError): + newconfig([], inisource) def test_skip_missing_interpreters_true(self, tmpdir, newconfig, monkeypatch): inisource = """ @@ -1837,6 +1928,23 @@ class TestCmdInvocation: "*ERROR*tox.ini*not*found*", ]) + def test_override_workdir(self, tmpdir, cmd, initproj): + baddir = "badworkdir-123" + gooddir = "overridden-234" + initproj("overrideworkdir-0.5", filedefs={ + 'tox.ini': ''' + [tox] + toxworkdir=%s + ''' % baddir, + }) + result = cmd.run("tox", "--workdir", gooddir, "--showconfig") + assert not result.ret + stdout = result.stdout.str() + assert gooddir in stdout + assert baddir not in stdout + assert py.path.local(gooddir).check() + assert not py.path.local(baddir).check() + def test_showconfig_with_force_dep_version(self, cmd, initproj): initproj('force_dep_version', filedefs={ 'tox.ini': ''' diff --git a/tests/test_interpreters.py b/tests/test_interpreters.py index d2cfa27..c658380 100644 --- a/tests/test_interpreters.py +++ b/tests/test_interpreters.py @@ -41,7 +41,7 @@ def test_tox_get_python_executable(): if sys.platform == "win32": pydir = "python%s" % ver.replace(".", "") x = py.path.local("c:\%s" % pydir) - print (x) + print(x) if not x.check(): continue else: diff --git a/tests/test_venv.py b/tests/test_venv.py index 4ab3b06..30bdf3c 100644 --- a/tests/test_venv.py +++ b/tests/test_venv.py @@ -137,8 +137,8 @@ def test_install_deps_wildcard(newmocksession): assert len(l) == 2 args = l[-1].args assert l[-1].cwd == venv.envconfig.config.toxinidir - assert "pip" in str(args[0]) - assert args[1] == "install" + assert "pip" in str(args[2]) + assert args[3] == "install" # arg = "--download-cache=" + str(venv.envconfig.downloadcache) # assert arg in args[2:] args = [arg for arg in args if str(arg).endswith("dep1-1.1.zip")] @@ -167,8 +167,8 @@ def test_install_downloadcache(newmocksession, monkeypatch, tmpdir, envdc): assert len(l) == 2 args = l[-1].args assert l[-1].cwd == venv.envconfig.config.toxinidir - assert "pip" in str(args[0]) - assert args[1] == "install" + assert "pip" in str(args) + assert args[3] == "install" assert "dep1" in args assert "dep2" in args deps = list(filter(None, [x[1] for x in venv._getliveconfig().deps])) @@ -365,7 +365,7 @@ def test_install_python3(tmpdir, newmocksession): venv._install(["hello"], action=action) assert len(l) == 1 args = l[0].args - assert 'pip' in str(args[0]) + assert "pip" in [str(x) for x in args] for x in args: assert "--download-cache" not in args, args @@ -597,7 +597,7 @@ def test_run_install_command(newmocksession): venv.run_install_command(packages=["whatever"], action=action) l = mocksession._pcalls assert len(l) == 1 - assert 'pip' in l[0].args[0] + assert 'pip' in l[0].args[2] assert 'install' in l[0].args env = l[0].env assert env is not None |