File: test_accelerators.py

package info (click to toggle)
meld 3.22.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,784 kB
  • sloc: python: 14,675; xml: 317; sh: 82; makefile: 26
file content (38 lines) | stat: -rw-r--r-- 1,182 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
from gi.repository import Gtk

from meld.accelerators import VIEW_ACCELERATORS


def test_accelerator_parse():
    for accel_strings in VIEW_ACCELERATORS.values():
        if isinstance(accel_strings, str):
            accel_strings = [accel_strings]

        for accel_string in accel_strings:
            key, mods = Gtk.accelerator_parse(accel_string)
            assert key


def test_accelerator_duplication():
    accels = set()

    allowed_duplicates = {
        # Allowed because they're different copy actions across views
        Gtk.accelerator_parse("<Alt>Left"),
        Gtk.accelerator_parse("<Alt>Right"),
        # Allowed because they're different panel show/hide across views
        Gtk.accelerator_parse("F9"),
    }

    for accel_strings in VIEW_ACCELERATORS.values():
        if isinstance(accel_strings, str):
            accel_strings = [accel_strings]

        for accel_string in accel_strings:
            accel = Gtk.accelerator_parse(accel_string)

            if accel not in allowed_duplicates:
                assert (
                    accel not in accels
                ), f"Duplicate accelerator {accel_string}"
            accels.add(accel)