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
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
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
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)
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"
def check_alias_non_existent(name): assert name not in aliases.get(api.modes.GLOBAL)
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() ]
def test_get_global_alias_from_image_mode(): assert "q" in aliases.get(api.modes.IMAGE)
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"]
def test_add_alias(): aliases.alias("test", ["quit"]) assert aliases.get(api.modes.GLOBAL)["test"] == "quit" del aliases._aliases[api.modes.GLOBAL]["test"]
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