Esempio n. 1
0
def test_add_local_alias(alias):
    """Ensure alias added for a single mode is only available in this mode."""
    assert aliases.get(alias.mode)[alias.name] == alias.command
    other = set(api.modes.ALL) - {alias.mode}
    for mode in other:
        with pytest.raises(KeyError, match=alias.name):
            aliases.get(mode)[alias.name]  # pylint: disable=expression-not-assigned
Esempio n. 2
0
def alias(text, mode):
    """Replace alias with the actual command.

    Returns:
        The replaced text if text was an alias else text.
    """
    cmd = text.split()[0]
    if cmd in aliases.get(mode):
        return text.replace(cmd, aliases.get(mode)[cmd])
    return text
Esempio n. 3
0
def alias(text: str, mode: api.modes.Mode) -> str:
    """Replace alias with the actual command.

    Returns:
        The replaced text if text was an alias else text.
    """
    cmd = text.split()[0]
    if cmd in aliases.get(mode):
        text = text.replace(cmd, aliases.get(mode)[cmd])
        return wildcards.expand_internal(text, mode)
    return text
Esempio n. 4
0
 def on_enter(self, _text: str, mode: api.modes.Mode) -> None:
     """Create command list for appropriate mode when commandline is entered."""
     self.clear()
     cmdlist = []
     # Include commands
     for name, command in api.commands.items(mode):
         if not command.hide:
             cmdlist.append((name, command.description))
     # Include aliases
     for alias, cmd in aliases.get(mode).items():
         desc = "Alias for '%s'." % (cmd)
         cmdlist.append((alias, desc))
     self.set_data(cmdlist)
Esempio n. 5
0
def test_read_aliases(configpath):
    """Ensure new aliases are read correctly."""
    global_aliases = aliases.get(api.modes.IMAGE)
    assert "anything" in global_aliases
    assert global_aliases["anything"] == "scroll left"
Esempio n. 6
0
def check_alias_non_existent(name):
    assert name not in aliases.get(api.modes.GLOBAL)
Esempio n. 7
0
 def formatted_aliases(self, mode: api.modes.Mode) -> List[Tuple[str, str]]:
     """Return list of aliases with explanation for this mode."""
     return [
         (f":{alias}", f"Alias for '{command}'")
         for alias, command in aliases.get(mode).items()
     ]
Esempio n. 8
0
def test_get_global_alias_from_image_mode():
    assert "q" in aliases.get(api.modes.IMAGE)
Esempio n. 9
0
def test_add_alias_for_different_mode():
    aliases.alias("test", ["quit"], mode="image")
    assert aliases.get(api.modes.IMAGE)["test"] == "quit"
    assert "test" not in aliases.get(api.modes.GLOBAL)
    del aliases._aliases[api.modes.IMAGE]["test"]
Esempio n. 10
0
def test_add_alias():
    aliases.alias("test", ["quit"])
    assert aliases.get(api.modes.GLOBAL)["test"] == "quit"
    del aliases._aliases[api.modes.GLOBAL]["test"]
Esempio n. 11
0
def test_add_global_alias(alias):
    """Ensure alias added for global mode is available in all global modes."""
    for mode in (*api.modes.GLOBALS, api.modes.GLOBAL):
        assert aliases.get(mode)[alias.name] == alias.command