Skip to content

Commit

Permalink
fix replacement of sections with dash
Browse files Browse the repository at this point in the history
closes #1985 - also accepting a dash as a part of statically defined environment names

Co-authored-by: Jürgen Gmach <juergen.gmach@googlemail.com>
Co-authored-by: Miroslav Šedivý <eumiro@gmail.com>
  • Loading branch information
3 people committed Apr 6, 2021
1 parent 00723c5 commit 13ad028
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tox/config/loader/ini/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _replace_match(

_REPLACE_REF = re.compile(
rf"""
(\[(?P<full_env>{BASE_TEST_ENV}(:(?P<env>[^]]+))?|(?P<section>\w+))\])? # env/section
(\[(?P<full_env>{BASE_TEST_ENV}(:(?P<env>[^]]+))?|(?P<section>[-\w]+))\])? # env/section
(?P<key>[a-zA-Z0-9_]+) # key
(:(?P<default>.*))? # default value
""",
Expand Down
15 changes: 15 additions & 0 deletions tests/config/loader/ini/replace/test_replace_tox_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,18 @@ def test_replace_from_tox_other_tox_section_same_name(tox_ini_conf: ToxIniCreato
conf_a = tox_ini_conf("[testenv:a]\nx={[testenv:b]c}\nc=d\n[testenv:b]}").get_env("a")
conf_a.add_config(keys="x", of_type=str, default="", desc="d")
assert conf_a["x"] == "{[testenv:b]c}"


@pytest.mark.parametrize(
"envname, exp",
(
("testenv:foobar", "1"),
("testenv:foo-bar", "1"),
("foo-bar", "1"),
("foobar", "1"),
),
)
def test_replace_valid_section_names(tox_ini_conf: ToxIniCreator, envname, exp) -> None:
conf_a = tox_ini_conf(f"[{envname}]\na={exp}\n[testenv:a]\nx = {{[{envname}]a}}").get_env("a")
conf_a.add_config(keys="x", of_type=str, default="o", desc="o")
assert conf_a["x"] == exp

0 comments on commit 13ad028

Please sign in to comment.