Skip to content

Commit 0ef8e16

Browse files
committed
finished invididual plugin method testing. Moved the plugin loading into the workspacebuilder and changed the reattach to take in a builder object instead of a session so that it can access those plugins.
1 parent 53f672b commit 0ef8e16

File tree

13 files changed

+150
-73
lines changed

13 files changed

+150
-73
lines changed

tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_awf/tmuxp_test_plugin_awf/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ def __init__(self):
55
self.message = f'[+] This is the Tmuxp Test Plugin'
66

77
def after_window_finished(self, window):
8-
pass
8+
if window.name == 'editor':
9+
window.rename_window('plugin_test_awf')

tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_bs/tmuxp_test_plugin_bs/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ def __init__(self):
55
self.message = f'[+] This is the Tmuxp Test Plugin'
66

77
def before_script(self, session):
8-
pass
8+
print('Changing session_name to plugin_test_bs')
9+
session.rename_session('plugin_test_bs')

tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_owc/tmuxp_test_plugin_owc/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ def __init__(self):
66

77
def on_window_create(self, window):
88
if window.name == 'editor':
9-
pass
9+
window.rename_window('plugin_test_owc')

tests/fixtures/pluginsystem/plugins/tmuxp_test_plugin_r/tmuxp_test_plugin_r/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ def __init__(self):
55
self.message = f'[+] This is the Tmuxp Test Plugin'
66

77
def reattach(self, session):
8-
pass
8+
session.rename_session('plugin_test_r')

tests/fixtures/workspacebuilder/plugin_awf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
session_name: plugin-test-awf
22
plugins:
3-
- 'tmuxp_test_plugin_awf.plugin.TestPluginAfterWindowFinished'
3+
- 'tmuxp_test_plugin_awf.plugin.PluginAfterWindowFinished'
44
windows:
55
- window_name: editor
66
layout: tiled

tests/fixtures/workspacebuilder/plugin_bs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
session_name: plugin-test-bs
22
plugins:
3-
- 'tmuxp_test_plugin_bs.plugin.TestPluginBeforeScript'
3+
- 'tmuxp_test_plugin_bs.plugin.PluginBeforeScript'
44
windows:
55
- window_name: editor
66
layout: tiled

tests/fixtures/workspacebuilder/plugin_bwb.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
session_name: plugin-test-bwb
22
plugins:
3-
- 'tmuxp_test_plugin_bwb.plugin.TestPluginBeforeWorkspaceBuild'
3+
- 'tmuxp_test_plugin_bwb.plugin.PluginBeforeWorkspaceBuilder'
44
windows:
55
- window_name: editor
66
layout: tiled

tests/fixtures/workspacebuilder/plugin_owc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
session_name: plugin-test-owc
22
plugins:
3-
- 'tmuxp_test_plugin_owc.plugin.TestPluginOnWindowCreate'
3+
- 'tmuxp_test_plugin_owc.plugin.PluginOnWindowCreate'
44
windows:
55
- window_name: editor
66
layout: tiled

tests/fixtures/workspacebuilder/plugin_r.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
session_name: plugin-test-r
22
plugins:
3-
- 'tmuxp_test_plugin_r.plugin.TestPluginReattach'
3+
- 'tmuxp_test_plugin_r.plugin.PluginReattach'
44
windows:
55
- window_name: editor
66
layout: tiled

tests/test_cli.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import pytest
99

10+
import kaptan
11+
1012
import click
1113
from click.testing import CliRunner
1214

@@ -20,11 +22,12 @@
2022
is_pure_name,
2123
load_workspace,
2224
scan_config,
23-
load_plugins,
25+
_reattach
2426
)
27+
from tmuxp.workspacebuilder import WorkspaceBuilder
2528

2629
from .fixtures._util import curjoin, loadfixture
27-
from tmuxp_test_plugin_bwb.plugin import PluginBeforeWorkspaceBuilder
30+
2831

2932
def test_creates_config_dir_not_exists(tmpdir):
3033
"""cli.startup() creates config dir if not exists."""
@@ -268,18 +271,6 @@ def check_cmd(config_arg):
268271
assert 'config not found in config dir' in check_cmd('moo')
269272

270273

271-
def test_load_plugins():
272-
session_config = curjoin("workspacebuildter/plugin_bwb.yaml")
273-
plugins = load_plugins(session_config)
274-
assert len(plugins) == 1
275-
276-
test_plugin_class_types = [
277-
PluginBeforeWorkspaceBuilder().__class__,
278-
]
279-
for plugin in plugins:
280-
assert plugin.__class__ in test_plugin_class_types
281-
282-
283274
def test_load_workspace(server, monkeypatch):
284275
# this is an implementation test. Since this testsuite may be ran within
285276
# a tmux session by the developer himself, delete the TMUX variable
@@ -966,3 +957,25 @@ def test_ls_cli(monkeypatch, tmpdir):
966957
runner = CliRunner()
967958
cli_output = runner.invoke(command_ls).output
968959
assert cli_output == '\n'.join(stems) + '\n'
960+
961+
962+
def test_reattach_plugins(server):
963+
config_plugins = loadfixture("workspacebuilder/plugin_r.yaml")
964+
965+
sconfig = kaptan.Kaptan(handler='yaml')
966+
sconfig = sconfig.import_config(config_plugins).get()
967+
sconfig = config.expand(sconfig)
968+
969+
# open it detached
970+
builder = WorkspaceBuilder(sconf=sconfig, server=server)
971+
builder.build()
972+
973+
try:
974+
_reattach(builder)
975+
except libtmux.exc.LibTmuxException as error:
976+
pass
977+
978+
979+
proc = builder.session.cmd('display-message', '-p', "'#S'")
980+
981+
assert proc.stdout[0] == "'plugin_test_r'"

0 commit comments

Comments
 (0)