Skip to content

Commit 54e82c5

Browse files
committed
refactor(tests): convert test_load.py tests to use NamedTuple fixtures
1 parent 2ff09e3 commit 54e82c5

File tree

1 file changed

+100
-27
lines changed

1 file changed

+100
-27
lines changed

tests/cli/test_load.py

+100-27
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,39 @@ def test_regression_00132_session_name_with_dots(
359359
cli.cli(["load", *cli_args])
360360

361361

362+
class ZshAutotitleTestFixture(t.NamedTuple):
363+
"""Test fixture for zsh auto title warning tests."""
364+
365+
test_id: str
366+
cli_args: list[str]
367+
368+
369+
ZSH_AUTOTITLE_TEST_FIXTURES: list[ZshAutotitleTestFixture] = [
370+
ZshAutotitleTestFixture(
371+
test_id="load_dot_detached",
372+
cli_args=["load", ".", "-d"],
373+
),
374+
ZshAutotitleTestFixture(
375+
test_id="load_yaml_detached",
376+
cli_args=["load", ".tmuxp.yaml", "-d"],
377+
),
378+
]
379+
380+
362381
@pytest.mark.parametrize(
363-
"cli_args",
364-
[["load", ".", "-d"], ["load", ".tmuxp.yaml", "-d"]],
382+
list(ZshAutotitleTestFixture._fields),
383+
ZSH_AUTOTITLE_TEST_FIXTURES,
384+
ids=[test.test_id for test in ZSH_AUTOTITLE_TEST_FIXTURES],
365385
)
366386
def test_load_zsh_autotitle_warning(
387+
test_id: str,
367388
cli_args: list[str],
368389
tmp_path: pathlib.Path,
369390
monkeypatch: pytest.MonkeyPatch,
370391
capsys: pytest.CaptureFixture[str],
371392
server: Server,
372393
) -> None:
373-
"""Test loading ZSH without DISABLE_AUTO_TITLE raises warning."""
394+
"""Test warning when ZSH auto title is enabled."""
374395
# create dummy tmuxp yaml so we don't get yelled at
375396
yaml_config = tmp_path / ".tmuxp.yaml"
376397
yaml_config.write_text(
@@ -417,19 +438,34 @@ def test_load_zsh_autotitle_warning(
417438
assert "Please set" not in result.out
418439

419440

441+
class LogFileTestFixture(t.NamedTuple):
442+
"""Test fixture for log file tests."""
443+
444+
test_id: str
445+
cli_args: list[str]
446+
447+
448+
LOG_FILE_TEST_FIXTURES: list[LogFileTestFixture] = [
449+
LogFileTestFixture(
450+
test_id="load_with_log_file",
451+
cli_args=["load", ".", "--log-file", "log.txt", "-d"],
452+
),
453+
]
454+
455+
420456
@pytest.mark.parametrize(
421-
"cli_args",
422-
[
423-
(["load", ".", "--log-file", "log.txt", "-d"]),
424-
],
457+
list(LogFileTestFixture._fields),
458+
LOG_FILE_TEST_FIXTURES,
459+
ids=[test.test_id for test in LOG_FILE_TEST_FIXTURES],
425460
)
426461
def test_load_log_file(
462+
test_id: str,
427463
cli_args: list[str],
428464
tmp_path: pathlib.Path,
429465
monkeypatch: pytest.MonkeyPatch,
430466
capsys: pytest.CaptureFixture[str],
431467
) -> None:
432-
"""Test loading via tmuxp load with --log-file."""
468+
"""Test loading with a log file."""
433469
# create dummy tmuxp yaml that breaks to prevent actually loading tmux
434470
tmuxp_config_path = tmp_path / ".tmuxp.yaml"
435471
tmuxp_config_path.write_text(
@@ -478,23 +514,37 @@ def test_load_plugins(
478514
assert plugin.__class__ in test_plugin_class_types
479515

480516

517+
class PluginVersionTestFixture(t.NamedTuple):
518+
"""Test fixture for plugin version tests."""
519+
520+
test_id: str
521+
cli_args: list[str]
522+
inputs: list[str]
523+
524+
525+
PLUGIN_VERSION_SKIP_TEST_FIXTURES: list[PluginVersionTestFixture] = [
526+
PluginVersionTestFixture(
527+
test_id="skip_version_fail",
528+
cli_args=["load", "tests/fixtures/workspace/builder/plugin_versions_fail.yaml"],
529+
inputs=["y\n"],
530+
),
531+
]
532+
533+
481534
@pytest.mark.skip("Not sure how to clean up the tmux session this makes")
482535
@pytest.mark.parametrize(
483-
("cli_args", "inputs"),
484-
[
485-
(
486-
["load", "tests/fixtures/workspace/builder/plugin_versions_fail.yaml"],
487-
["y\n"],
488-
),
489-
],
536+
list(PluginVersionTestFixture._fields),
537+
PLUGIN_VERSION_SKIP_TEST_FIXTURES,
538+
ids=[test.test_id for test in PLUGIN_VERSION_SKIP_TEST_FIXTURES],
490539
)
491540
def test_load_plugins_version_fail_skip(
492541
monkeypatch_plugin_test_packages: None,
542+
test_id: str,
493543
cli_args: list[str],
494544
inputs: list[str],
495545
capsys: pytest.CaptureFixture[str],
496546
) -> None:
497-
"""Test tmuxp load with plugins failing version constraints can continue."""
547+
"""Test plugin version failure with skip."""
498548
with contextlib.suppress(SystemExit):
499549
cli.cli(cli_args)
500550

@@ -503,23 +553,29 @@ def test_load_plugins_version_fail_skip(
503553
assert "[Loading]" in result.out
504554

505555

556+
PLUGIN_VERSION_NO_SKIP_TEST_FIXTURES: list[PluginVersionTestFixture] = [
557+
PluginVersionTestFixture(
558+
test_id="no_skip_version_fail",
559+
cli_args=["load", "tests/fixtures/workspace/builder/plugin_versions_fail.yaml"],
560+
inputs=["n\n"],
561+
),
562+
]
563+
564+
506565
@pytest.mark.parametrize(
507-
("cli_args", "inputs"),
508-
[
509-
(
510-
["load", "tests/fixtures/workspace/builder/plugin_versions_fail.yaml"],
511-
["n\n"],
512-
),
513-
],
566+
list(PluginVersionTestFixture._fields),
567+
PLUGIN_VERSION_NO_SKIP_TEST_FIXTURES,
568+
ids=[test.test_id for test in PLUGIN_VERSION_NO_SKIP_TEST_FIXTURES],
514569
)
515570
def test_load_plugins_version_fail_no_skip(
516571
monkeypatch_plugin_test_packages: None,
572+
test_id: str,
517573
cli_args: list[str],
518574
inputs: list[str],
519575
monkeypatch: pytest.MonkeyPatch,
520576
capsys: pytest.CaptureFixture[str],
521577
) -> None:
522-
"""Test tmuxp load with plugins failing version constraints can exit."""
578+
"""Test plugin version failure without skip."""
523579
monkeypatch.setattr("sys.stdin", io.StringIO("".join(inputs)))
524580

525581
with contextlib.suppress(SystemExit):
@@ -530,16 +586,33 @@ def test_load_plugins_version_fail_no_skip(
530586
assert "[Not Skipping]" in result.out
531587

532588

589+
class PluginMissingTestFixture(t.NamedTuple):
590+
"""Test fixture for plugin missing tests."""
591+
592+
test_id: str
593+
cli_args: list[str]
594+
595+
596+
PLUGIN_MISSING_TEST_FIXTURES: list[PluginMissingTestFixture] = [
597+
PluginMissingTestFixture(
598+
test_id="missing_plugin",
599+
cli_args=["load", "tests/fixtures/workspace/builder/plugin_missing_fail.yaml"],
600+
),
601+
]
602+
603+
533604
@pytest.mark.parametrize(
534-
"cli_args",
535-
[(["load", "tests/fixtures/workspace/builder/plugin_missing_fail.yaml"])],
605+
list(PluginMissingTestFixture._fields),
606+
PLUGIN_MISSING_TEST_FIXTURES,
607+
ids=[test.test_id for test in PLUGIN_MISSING_TEST_FIXTURES],
536608
)
537609
def test_load_plugins_plugin_missing(
538610
monkeypatch_plugin_test_packages: None,
611+
test_id: str,
539612
cli_args: list[str],
540613
capsys: pytest.CaptureFixture[str],
541614
) -> None:
542-
"""Test tmuxp load with plugins missing raise an error."""
615+
"""Test loading with missing plugin."""
543616
with contextlib.suppress(SystemExit):
544617
cli.cli(cli_args)
545618

0 commit comments

Comments
 (0)