Skip to content

Commit

Permalink
test_ignore_env_name_mismatch: unit tests for FilteredInfo
Browse files Browse the repository at this point in the history
Since FilteredInfo can accept generic filter_keys and filter_section, add test
cases to ensure the less common default branches are covered, even though the
plugins don't directly use them (yet)
  • Loading branch information
masenf committed Jan 15, 2023
1 parent a4fd770 commit 2682f02
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/unit/test_ignore_env_name_mismatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from unittest import mock

from tox.tox_env.api import ToxEnv, ToxEnvCreateArgs
Expand Down Expand Up @@ -46,3 +47,87 @@ def test_reusable_virtualenv_runner_cache(env_name, tox_env):

assert info._content
assert not info._content[ToxEnv.__name__]


SECTION_BLANK = ""
SECTION_FOO = "foo"
TOP_LEVEL_KEY_BLANK = {"empty": None}
TOP_LEVEL_KEY_FOO = {"bar": None}


@pytest.fixture
def cached_info(tmp_path):
content = {
SECTION_BLANK: TOP_LEVEL_KEY_BLANK.copy(),
SECTION_FOO: TOP_LEVEL_KEY_FOO.copy(),
}
(tmp_path / ".tox-info.json").write_text(json.dumps(content))
return content


@pytest.mark.usefixtures("cached_info")
@pytest.mark.parametrize(
("filter_keys", "filter_section", "args", "exp_eq", "exp_old"),
[
(None, None, ({}, SECTION_BLANK), False, TOP_LEVEL_KEY_BLANK),
(None, None, (TOP_LEVEL_KEY_BLANK, SECTION_BLANK), True, TOP_LEVEL_KEY_BLANK),
(
None,
None,
({"foo": "bar", **TOP_LEVEL_KEY_BLANK}, SECTION_BLANK),
False,
TOP_LEVEL_KEY_BLANK,
),
(
["foo"],
None,
({"foo": "bar", **TOP_LEVEL_KEY_BLANK}, SECTION_BLANK),
True,
TOP_LEVEL_KEY_BLANK,
),
(
["foo"],
None,
({"foo": "bar", **TOP_LEVEL_KEY_FOO}, SECTION_FOO),
True,
TOP_LEVEL_KEY_FOO,
),
(
["foo"],
SECTION_FOO,
({"foo": "bar", **TOP_LEVEL_KEY_BLANK}, SECTION_BLANK),
False,
TOP_LEVEL_KEY_BLANK,
),
(
["foo"],
SECTION_FOO,
({"foo": "bar", **TOP_LEVEL_KEY_FOO}, SECTION_FOO),
True,
TOP_LEVEL_KEY_FOO,
),
(
["foo"],
SECTION_FOO,
(TOP_LEVEL_KEY_FOO, SECTION_FOO),
True,
TOP_LEVEL_KEY_FOO,
),
(
["bar"],
SECTION_FOO,
(TOP_LEVEL_KEY_FOO, SECTION_FOO),
False,
TOP_LEVEL_KEY_FOO,
),
],
)
def test_filtered_info(tmp_path, filter_keys, filter_section, args, exp_eq, exp_old):
info = tox_ignore_env_name_mismatch.FilteredInfo(
tmp_path,
filter_keys=filter_keys,
filter_section=filter_section,
)
with info.compare(*args) as (eq, old):
assert eq == exp_eq
assert old == exp_old

0 comments on commit 2682f02

Please sign in to comment.