File: test_plugin_helpers.py

package info (click to toggle)
tmuxp 1.62.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 7,989; makefile: 202; sh: 21
file content (42 lines) | stat: -rw-r--r-- 1,438 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Tmuxp test plugin for asserting version constraints."""

from __future__ import annotations

import typing as t

from tmuxp.plugin import TmuxpPlugin

if t.TYPE_CHECKING:
    from typing_extensions import Unpack

    from tmuxp._internal.types import PluginConfigSchema

    from ._types import PluginTestConfigSchema


class MyTestTmuxpPlugin(TmuxpPlugin):
    """Base class for testing tmuxp plugins with version constraints."""

    def __init__(self, **config: Unpack[PluginTestConfigSchema]) -> None:
        assert isinstance(config, dict)
        tmux_version = config.pop("tmux_version", None)
        libtmux_version = config.pop("libtmux_version", None)
        tmuxp_version = config.pop("tmuxp_version", None)

        t.cast("PluginConfigSchema", config)

        assert "tmux_version" not in config

        # tests/fixtures/pluginsystem/partials/test_plugin_helpers.py:24: error: Extra
        # argument "tmux_version" from **args for "__init__" of "TmuxpPlugin"  [misc]
        super().__init__(**config)  # type:ignore

        # WARNING! This should not be done in anything but a test
        if tmux_version:
            self.version_constraints["tmux"]["version"] = tmux_version
        if libtmux_version:
            self.version_constraints["libtmux"]["version"] = libtmux_version
        if tmuxp_version:
            self.version_constraints["tmuxp"]["version"] = tmuxp_version

        self._version_check()