Skip to content

Test suite: Move tests to typing.NamedTuple #423

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

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Changes from all 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
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force

<!-- Maintainers, insert changes / features for the next release here -->

### Development

- Refactor of two testsuites to used `NamedTuple` parametrization (#423):

- test_config_variations
- test_updating_remote

### Breaking changes

- Python 3.7 Dropped (#421)
94 changes: 61 additions & 33 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
@@ -62,41 +62,55 @@ def write_config_remote(
)


@pytest.mark.parametrize(
"config_tpl,remote_list",
[
[
"""
class ConfigVariationTest(t.NamedTuple):
test_id: str
config_tpl: str
remote_list: list[str]


CONFIG_VARIATION_FIXTURES = [
ConfigVariationTest(
test_id="default",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}: git+file://{dir}
""",
["origin"],
],
[
"""
remote_list=["origin"],
),
ConfigVariationTest(
test_id="expanded_repo_style",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
""",
["repo"],
],
[
"""
remote_list=["repo"],
),
ConfigVariationTest(
test_id="expanded_repo_style_with_remote",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
remotes:
secondremote: git+file://{dir}
""",
["secondremote"],
],
],
remote_list=["secondremote"],
),
]


@pytest.mark.parametrize(
list(ConfigVariationTest._fields),
CONFIG_VARIATION_FIXTURES,
ids=[test.test_id for test in CONFIG_VARIATION_FIXTURES],
)
def test_config_variations(
tmp_path: pathlib.Path,
capsys: pytest.CaptureFixture[str],
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
test_id: str,
config_tpl: str,
capsys: pytest.CaptureFixture[str],
remote_list: list[str],
) -> None:
"""Test config output with variation of config formats"""
@@ -131,39 +145,53 @@ def test_config_variations(
assert current_remote.fetch_url == repo_url


@pytest.mark.parametrize(
"config_tpl,has_extra_remotes",
[
[
"""
class UpdatingRemoteFixture(t.NamedTuple):
test_id: str
config_tpl: str
has_extra_remotes: bool


UPDATING_REMOTE_FIXTURES = [
UpdatingRemoteFixture(
test_id="no_remotes",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}: git+file://{dir}
""",
False,
],
[
"""
has_extra_remotes=False,
),
UpdatingRemoteFixture(
test_id="no_remotes_expanded_repo_style",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
""",
False,
],
[
"""
has_extra_remotes=False,
),
UpdatingRemoteFixture(
test_id="has_remotes_expanded_repo_style",
config_tpl="""
{tmp_path}/study/myrepo:
{CLONE_NAME}:
repo: git+file://{dir}
remotes:
mirror_repo: git+file://{dir}
""",
True,
],
],
has_extra_remotes=True,
),
]


@pytest.mark.parametrize(
list(UpdatingRemoteFixture._fields),
UPDATING_REMOTE_FIXTURES,
ids=[test.test_id for test in UPDATING_REMOTE_FIXTURES],
)
def test_updating_remote(
tmp_path: pathlib.Path,
create_git_remote_repo: CreateProjectCallbackFixtureProtocol,
test_id: str,
config_tpl: str,
has_extra_remotes: bool,
) -> None: