diff --git a/pyproject.toml b/pyproject.toml index f162a3c2a2..303d32cc86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,12 +69,6 @@ pytest-mock = [ {version="<3.0.0", python="<3"}, {version="*", python=">=3"} ] -tmuxp-test-plugin-bwb = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bwb/"} -tmuxp-test-plugin-bs = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bs/"} -tmuxp-test-plugin-r = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_r/"} -tmuxp-test-plugin-owc = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_owc/"} -tmuxp-test-plugin-awf = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_awf/"} -tmuxp-test-plugin-fail = { path = "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_fail/"} ### Coverage ### codecov = "*" diff --git a/tests/conftest.py b/tests/conftest.py index 7ed9c2d2f9..1de3ec58df 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- - import logging +import os import pytest @@ -11,6 +11,20 @@ logger = logging.getLogger(__name__) +@pytest.fixture(scope='function') +def monkeypatch_plugin_test_packages(monkeypatch): + paths = [ + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bwb/", + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bs/", + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_r/", + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_owc/", + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_awf/", + "tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_fail/", + ] + for path in paths: + monkeypatch.syspath_prepend(os.path.abspath(os.path.relpath(path))) + + @pytest.fixture(scope='function') def socket_name(request): return 'tmuxp_test%s' % next(namer) diff --git a/tests/test_cli.py b/tests/test_cli.py index e5a7f93ed8..bfd23457e9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -15,16 +15,15 @@ import click import kaptan from click.testing import CliRunner -from tmuxp_test_plugin_bwb.plugin import PluginBeforeWorkspaceBuilder import libtmux from libtmux.common import has_lt_version from libtmux.exc import LibTmuxException from tmuxp import cli, config, exc from tmuxp.cli import ( - _reattach, - _load_attached, _load_append_windows_to_current_session, + _load_attached, + _reattach, command_debug_info, command_ls, get_config_dir, @@ -995,7 +994,9 @@ def test_ls_cli(monkeypatch, tmpdir): assert cli_output == '\n'.join(stems) + '\n' -def test_load_plugins(): +def test_load_plugins(monkeypatch_plugin_test_packages): + from tmuxp_test_plugin_bwb.plugin import PluginBeforeWorkspaceBuilder + plugins_config = loadfixture("workspacebuilder/plugin_bwb.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -1023,7 +1024,9 @@ def test_load_plugins(): ) ], ) -def test_load_plugins_version_fail_skip(cli_args, inputs): +def test_load_plugins_version_fail_skip( + monkeypatch_plugin_test_packages, cli_args, inputs +): runner = CliRunner() results = runner.invoke(cli.cli, cli_args, input=''.join(inputs)) @@ -1039,7 +1042,9 @@ def test_load_plugins_version_fail_skip(cli_args, inputs): ) ], ) -def test_load_plugins_version_fail_no_skip(cli_args, inputs): +def test_load_plugins_version_fail_no_skip( + monkeypatch_plugin_test_packages, cli_args, inputs +): runner = CliRunner() results = runner.invoke(cli.cli, cli_args, input=''.join(inputs)) @@ -1049,14 +1054,16 @@ def test_load_plugins_version_fail_no_skip(cli_args, inputs): @pytest.mark.parametrize( "cli_args", [(['load', 'tests/fixtures/workspacebuilder/plugin_missing_fail.yaml'])] ) -def test_load_plugins_plugin_missing(cli_args): +def test_load_plugins_plugin_missing(monkeypatch_plugin_test_packages, cli_args): runner = CliRunner() results = runner.invoke(cli.cli, cli_args) assert '[Plugin Error]' in results.output -def test_plugin_system_before_script(server, monkeypatch): +def test_plugin_system_before_script( + monkeypatch_plugin_test_packages, server, monkeypatch +): # this is an implementation test. Since this testsuite may be ran within # a tmux session by the developer himself, delete the TMUX variable # temporarily. @@ -1072,7 +1079,7 @@ def test_plugin_system_before_script(server, monkeypatch): assert session.name == 'plugin_test_bs' -def test_reattach_plugins(server): +def test_reattach_plugins(monkeypatch_plugin_test_packages, server): config_plugins = loadfixture("workspacebuilder/plugin_r.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -1174,6 +1181,7 @@ def test_load_attached_within_tmux_detached(server, monkeypatch): assert builder.session.switch_client.call_count == 1 + def test_load_append_windows_to_current_session(server, monkeypatch): yaml_config = loadfixture("workspacebuilder/two_pane.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -1195,7 +1203,6 @@ def test_load_append_windows_to_current_session(server, monkeypatch): assert len(server._list_windows()) == 6 - def test_debug_info_cli(monkeypatch, tmpdir): monkeypatch.setenv('SHELL', '/bin/bash') diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 488465e0bd..88372c8fcf 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -24,6 +24,11 @@ ) +@pytest.fixture(autouse=True) +def autopatch_sitedir(monkeypatch_plugin_test_packages): + pass + + def test_all_pass(): AllVersionPassPlugin() diff --git a/tests/test_workspacebuilder.py b/tests/test_workspacebuilder.py index ce3584dc43..b38abadb3e 100644 --- a/tests/test_workspacebuilder.py +++ b/tests/test_workspacebuilder.py @@ -14,8 +14,8 @@ from libtmux.test import retry, temp_session from tmuxp import config, exc from tmuxp._compat import text_type -from tmuxp.workspacebuilder import WorkspaceBuilder from tmuxp.cli import load_plugins +from tmuxp.workspacebuilder import WorkspaceBuilder from . import example_dir, fixtures_dir from .fixtures._util import loadfixture @@ -676,7 +676,9 @@ def test_before_load_true_if_test_passes_with_args(server): builder.build(session=session) -def test_plugin_system_before_workspace_builder(session): +def test_plugin_system_before_workspace_builder( + monkeypatch_plugin_test_packages, session +): config_plugins = loadfixture("workspacebuilder/plugin_bwb.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -692,7 +694,7 @@ def test_plugin_system_before_workspace_builder(session): assert proc.stdout[0] == "'plugin_test_bwb'" -def test_plugin_system_on_window_create(session): +def test_plugin_system_on_window_create(monkeypatch_plugin_test_packages, session): config_plugins = loadfixture("workspacebuilder/plugin_owc.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -708,7 +710,7 @@ def test_plugin_system_on_window_create(session): assert proc.stdout[0] == "'plugin_test_owc'" -def test_plugin_system_after_window_finished(session): +def test_plugin_system_after_window_finished(monkeypatch_plugin_test_packages, session): config_plugins = loadfixture("workspacebuilder/plugin_awf.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -741,7 +743,9 @@ def test_plugin_system_on_window_create_multiple_windows(session): assert "'plugin_test_owc_mw_2'" in proc.stdout -def test_plugin_system_after_window_finished_multiple_windows(session): +def test_plugin_system_after_window_finished_multiple_windows( + monkeypatch_plugin_test_packages, session +): config_plugins = loadfixture("workspacebuilder/plugin_awf_multiple_windows.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -758,7 +762,7 @@ def test_plugin_system_after_window_finished_multiple_windows(session): assert "'plugin_test_awf_mw_2'" in proc.stdout -def test_plugin_system_multiple_plugins(session): +def test_plugin_system_multiple_plugins(monkeypatch_plugin_test_packages, session): config_plugins = loadfixture("workspacebuilder/plugin_multiple_plugins.yaml") sconfig = kaptan.Kaptan(handler='yaml') @@ -858,9 +862,9 @@ def test_find_current_active_pane(server, monkeypatch): # Assign an active pane to the session second_session = server.list_sessions()[1] - first_pane_on_second_session_id = ( - second_session.list_windows()[0].list_panes()[0]["pane_id"] - ) + first_pane_on_second_session_id = second_session.list_windows()[0].list_panes()[0][ + "pane_id" + ] monkeypatch.setenv("TMUX_PANE", first_pane_on_second_session_id) builder = WorkspaceBuilder(sconf=sconfig, server=server)