Skip to content

Commit 97a6520

Browse files
committed
Add tests
1 parent 834ac35 commit 97a6520

File tree

1 file changed

+183
-1
lines changed

1 file changed

+183
-1
lines changed

tests/unit/config/test_config.py

Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ def test_envdir_set_manually_with_substitutions(self, newconfig):
9191
envconfig = config.envconfigs["dev"]
9292
assert envconfig.envdir == config.toxworkdir.join("foobar")
9393

94+
def test_envdir_set_manually_with_pound(self, newconfig):
95+
config = newconfig(
96+
[],
97+
"""
98+
[testenv:dev]
99+
envdir = {toxworkdir}/foo#bar
100+
""",
101+
)
102+
envconfig = config.envconfigs["dev"]
103+
assert envconfig.envdir == config.toxworkdir.join("foo#bar")
104+
105+
def test_envdir_set_manually_with_whitespace(self, newconfig):
106+
config = newconfig(
107+
[],
108+
"""
109+
[testenv:dev]
110+
envdir = {toxworkdir}/foo bar
111+
""",
112+
)
113+
envconfig = config.envconfigs["dev"]
114+
assert envconfig.envdir == config.toxworkdir.join("foo bar")
115+
94116
def test_force_dep_version(self, initproj):
95117
"""
96118
Make sure we can override dependencies configured in tox.ini when using the command line
@@ -496,6 +518,85 @@ def test_regression_issue595(self, newconfig):
496518
assert config.envconfigs["bar"].setenv["VAR"] == "x"
497519
assert "VAR" not in config.envconfigs["baz"].setenv
498520

521+
def test_command_substitution_pound(self, tmpdir, newconfig):
522+
"""Ensure pound in path is kept in commands."""
523+
config = newconfig(
524+
"""
525+
[tox]
526+
toxworkdir = {toxinidir}/.tox#dir
527+
528+
[testenv:py27]
529+
commands = '{envpython}' '{toxworkdir}'{/}'foo#bar'
530+
""",
531+
)
532+
533+
assert config.toxworkdir.realpath() == tmpdir.join(".tox#dir").realpath()
534+
535+
envconfig = config.envconfigs["py27"]
536+
537+
assert envconfig.envbindir.realpath() in [
538+
tmpdir.join(".tox#dir", "py27", "bin").realpath(),
539+
tmpdir.join(".tox#dir", "py27", "Scripts").realpath(),
540+
]
541+
542+
assert envconfig.commands[0] == [
543+
str(envconfig.envbindir.join("python")),
544+
str(config.toxworkdir.join("foo#bar")),
545+
]
546+
547+
def test_command_substitution_whitespace(self, tmpdir, newconfig):
548+
"""Ensure spaces in path is kept in commands."""
549+
config = newconfig(
550+
"""
551+
[tox]
552+
toxworkdir = {toxinidir}/.tox dir
553+
554+
[testenv:py27]
555+
commands = '{envpython}' '{toxworkdir}'{/}'foo bar'
556+
""",
557+
)
558+
559+
assert config.toxworkdir.realpath() == tmpdir.join(".tox dir").realpath()
560+
561+
envconfig = config.envconfigs["py27"]
562+
563+
assert envconfig.envbindir.realpath() in [
564+
tmpdir.join(".tox dir", "py27", "bin").realpath(),
565+
tmpdir.join(".tox dir", "py27", "Scripts").realpath(),
566+
]
567+
568+
assert envconfig.commands[0] == [
569+
str(envconfig.envbindir.join("python")),
570+
str(config.toxworkdir.join("foo bar").realpath()),
571+
]
572+
573+
def test_command_env_substitution_bracket(self, tmpdir, newconfig):
574+
"""Ensure bracket in path is kept in commands using setenv."""
575+
config = newconfig(
576+
"""
577+
[tox]
578+
toxworkdir = {toxinidir}/.tox{dir
579+
580+
[testenv:py27]
581+
setenv = VAR = '{toxworkdir}'{/}'foo{bar'
582+
commands = '{envpython}' '{env:VAR}'
583+
""",
584+
)
585+
586+
assert config.toxworkdir.realpath() == tmpdir.join(".tox{dir").realpath()
587+
588+
envconfig = config.envconfigs["py27"]
589+
590+
assert envconfig.envbindir.realpath() in [
591+
tmpdir.join(".tox{dir", "py27", "bin").realpath(),
592+
tmpdir.join(".tox{dir", "py27", "Scripts").realpath(),
593+
]
594+
595+
assert envconfig.commands[0] == [
596+
str(envconfig.envbindir.join("python")),
597+
str(config.toxworkdir.join("foo{bar").realpath()),
598+
]
599+
499600

500601
class TestIniParser:
501602
def test_getstring_single(self, newconfig):
@@ -1084,6 +1185,46 @@ def test_envbindir(self, newconfig):
10841185
envconfig = config.envconfigs["python"]
10851186
assert envconfig.envpython == envconfig.envbindir.join("python")
10861187

1188+
def test_envbindir_with_pound(self, newconfig):
1189+
config = newconfig(
1190+
"""
1191+
[tox]
1192+
toxworkdir = {toxinidir}/.tox#dir
1193+
[testenv]
1194+
basepython=python
1195+
""",
1196+
)
1197+
assert len(config.envconfigs) == 1
1198+
envconfig = config.envconfigs["python"]
1199+
1200+
assert ".tox#dir" in str(envconfig.envbindir)
1201+
assert ".tox#dir" in str(envconfig.envpython)
1202+
1203+
assert "'" not in str(envconfig.envbindir)
1204+
assert "'" not in str(envconfig.envpython)
1205+
1206+
assert envconfig.envpython == envconfig.envbindir.join("python")
1207+
1208+
def test_envbindir_with_whitespace(self, newconfig):
1209+
config = newconfig(
1210+
"""
1211+
[tox]
1212+
toxworkdir = {toxinidir}/.tox dir
1213+
[testenv]
1214+
basepython=python
1215+
""",
1216+
)
1217+
assert len(config.envconfigs) == 1
1218+
envconfig = config.envconfigs["python"]
1219+
1220+
assert ".tox dir" in str(envconfig.envbindir)
1221+
assert ".tox dir" in str(envconfig.envpython)
1222+
1223+
assert "'" not in str(envconfig.envbindir)
1224+
assert "'" not in str(envconfig.envpython)
1225+
1226+
assert envconfig.envpython == envconfig.envbindir.join("python")
1227+
10871228
@pytest.mark.parametrize("bp", ["jython", "pypy", "pypy3"])
10881229
def test_envbindir_jython(self, newconfig, bp):
10891230
config = newconfig(
@@ -1511,7 +1652,7 @@ def test_rewrite_posargs(self, tmpdir, newconfig):
15111652
argv = conf.commands
15121653
assert argv[0] == ["cmd1", "hello"]
15131654

1514-
def test_rewrite_simple_posargs(self, tmpdir, newconfig):
1655+
def test_rewrite_posargs_simple(self, tmpdir, newconfig):
15151656
inisource = """
15161657
[testenv:py27]
15171658
args_are_paths = True
@@ -1531,6 +1672,47 @@ def test_rewrite_simple_posargs(self, tmpdir, newconfig):
15311672
argv = conf.commands
15321673
assert argv[0] == ["cmd1", "hello"]
15331674

1675+
def test_rewrite_posargs_pound(self, tmpdir, newconfig):
1676+
inisource = """
1677+
[testenv:py27]
1678+
args_are_paths = True
1679+
changedir = test#dir
1680+
commands = cmd1 {posargs:hello}
1681+
"""
1682+
conf = newconfig([], inisource).envconfigs["py27"]
1683+
argv = conf.commands
1684+
assert argv[0] == ["cmd1", "hello"]
1685+
1686+
if sys.platform != "win32":
1687+
conf = newconfig(["test#dir/hello"], inisource).envconfigs["py27"]
1688+
argv = conf.commands
1689+
assert argv[0] == ["cmd1", "test#dir/hello"]
1690+
1691+
tmpdir.ensure("test#dir", "hello")
1692+
conf = newconfig(["test#dir/hello"], inisource).envconfigs["py27"]
1693+
argv = conf.commands
1694+
assert argv[0] == ["cmd1", "hello"]
1695+
1696+
def test_rewrite_posargs_whitespace(self, tmpdir, newconfig):
1697+
inisource = """
1698+
[testenv:py27]
1699+
args_are_paths = True
1700+
changedir = test dir
1701+
commands = cmd1 {posargs:hello}
1702+
"""
1703+
conf = newconfig([], inisource).envconfigs["py27"]
1704+
argv = conf.commands
1705+
assert argv[0] == ["cmd1", "hello"]
1706+
1707+
conf = newconfig(["test dir/hello"], inisource).envconfigs["py27"]
1708+
argv = conf.commands
1709+
assert argv[0] == ["cmd1", "test dir/hello"]
1710+
1711+
tmpdir.ensure("test dir", "hello")
1712+
conf = newconfig(["test dir/hello"], inisource).envconfigs["py27"]
1713+
argv = conf.commands
1714+
assert argv[0] == ["cmd1", "hello"]
1715+
15341716
@pytest.mark.parametrize(
15351717
"envlist, deps",
15361718
[

0 commit comments

Comments
 (0)