Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix replacement of sections with dash #2000

Merged
merged 4 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/1985.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Enable replacements (a.k.a section substitions) for section names containing a dash in sections
without the ``testenv:`` prefix - by :user:`jugmac00`, :user:`obestwalter`, :user:`eumiro`.
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(
"env_name, exp",
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
(
("testenv:foobar", "1"),
("testenv:foo-bar", "1"),
("foo-bar", "1"),
("foobar", "1"),
),
)
def test_replace_valid_section_names(tox_ini_conf: ToxIniCreator, env_name: str, exp: str) -> None:
conf_a = tox_ini_conf(f"[{env_name}]\na={exp}\n[testenv:a]\nx = {{[{env_name}]a}}").get_env("a")
conf_a.add_config(keys="x", of_type=str, default="o", desc="o")
assert conf_a["x"] == exp