Ejemplo n.º 1
0
    def __init__(self, opts):
        super().__init__(opts)

        self.start_err: typing.Optional[log.LogEntry] = None

        self.view: view.View = view.View()
        self.events = eventstore.EventStore()
        self.events.sig_add.connect(self.sig_add_log)

        self.stream_path = None
        self.keymap = keymap.Keymap(self)
        defaultkeys.map(self.keymap)
        self.options.errored.connect(self.options_error)

        self.view_stack = []

        self.addons.add(*addons.default_addons())
        self.addons.add(
            intercept.Intercept(),
            self.view,
            self.events,
            readfile.ReadFile(),
            consoleaddons.ConsoleAddon(self),
            keymap.KeymapConfig(),
        )

        def sigint_handler(*args, **kwargs):
            self.prompt_for_exit()

        signal.signal(signal.SIGINT, sigint_handler)

        self.window = None
Ejemplo n.º 2
0
    def __init__(self, opts):
        super().__init__(opts)

        self.view: view.View = view.View()
        self.events = eventstore.EventStore()
        self.events.sig_add.connect(self.sig_add_log)

        self.stream_path = None
        self.keymap = keymap.Keymap(self)
        defaultkeys.map(self.keymap)
        self.options.errored.connect(self.options_error)

        self.view_stack = []

        self.addons.add(*addons.default_addons())
        self.addons.add(
            intercept.Intercept(),
            self.view,
            self.events,
            readfile.ReadFile(),
            consoleaddons.ConsoleAddon(self),
            keymap.KeymapConfig(),
            errorcheck.ErrorCheck(log_to_stderr=True),
        )

        self.window = None
Ejemplo n.º 3
0
def test_load_path(tmpdir):
    dst = str(tmpdir.join("conf"))

    kmc = keymap.KeymapConfig()
    with taddons.context(kmc) as tctx:
        km = keymap.Keymap(tctx.master)
        tctx.master.keymap = km

        with open(dst, 'wb') as f:
            f.write(b"\xff\xff\xff")
        with pytest.raises(keymap.KeyBindingError, match="expected UTF8"):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("'''")
        with pytest.raises(keymap.KeyBindingError):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("""
                    -   key: key1
                        ctx: [unknown]
                        cmd: >
                            foo bar
                            foo bar
                """)
        with pytest.raises(keymap.KeyBindingError):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("""
                    -   key: key1
                        ctx: [chooser]
                        help: one
                        cmd: >
                            foo bar
                            foo bar
                """)
        kmc.load_path(km, dst)
        assert (km.get("chooser", "key1"))

        km.add("key123", "str", ["flowlist", "flowview"])
        with open(dst, 'w') as f:
            f.write("""
                    -   key: key123
                        ctx: [options]
                        cmd: foo
                """)
        kmc.load_path(km, dst)
        for b in km.bindings:
            if b.key == "key123":
                assert b.contexts == ["options"]
                break
Ejemplo n.º 4
0
def test_parse():
    kmc = keymap.KeymapConfig()
    with taddons.context(kmc):
        assert kmc.parse("") == []
        assert kmc.parse("\n\n\n   \n") == []
        with pytest.raises(keymap.KeyBindingError,
                           match="expected a list of keys"):
            kmc.parse("key: val")
        with pytest.raises(keymap.KeyBindingError,
                           match="expected a list of keys"):
            kmc.parse("val")
        with pytest.raises(keymap.KeyBindingError,
                           match="Unknown key attributes"):
            kmc.parse("""
                    -   key: key1
                        nonexistent: bar
                """)
        with pytest.raises(keymap.KeyBindingError,
                           match="Missing required key attributes"):
            kmc.parse("""
                    -   help: key1
                """)
        with pytest.raises(keymap.KeyBindingError,
                           match="Invalid type for cmd"):
            kmc.parse("""
                    -   key: key1
                        cmd: [ cmd ]
                """)
        with pytest.raises(keymap.KeyBindingError,
                           match="Invalid type for ctx"):
            kmc.parse("""
                    -   key: key1
                        ctx: foo
                        cmd: cmd
                """)
        assert kmc.parse("""
                -   key: key1
                    ctx: [one, two]
                    help: one
                    cmd: >
                        foo bar
                        foo bar
            """) == [{
            "key": "key1",
            "ctx": ["one", "two"],
            "help": "one",
            "cmd": "foo bar foo bar\n"
        }]
Ejemplo n.º 5
0
def test_load_path(tmpdir):
    dst = str(tmpdir.join("conf"))

    kmc = keymap.KeymapConfig()
    with taddons.context(kmc) as tctx:
        km = keymap.Keymap(tctx.master)
        tctx.master.keymap = km

        with open(dst, 'wb') as f:
            f.write(b"\xff\xff\xff")
        with pytest.raises(keymap.KeyBindingError, match="expected UTF8"):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("'''")
        with pytest.raises(keymap.KeyBindingError):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("""
                    -   key: key1
                        ctx: [unknown]
                        cmd: >
                            foo bar
                            foo bar
                """)
        with pytest.raises(keymap.KeyBindingError):
            kmc.load_path(km, dst)

        with open(dst, 'w') as f:
            f.write("""
                    -   key: key1
                        ctx: [chooser]
                        help: one
                        cmd: >
                            foo bar
                            foo bar
                """)
        kmc.load_path(km, dst)
        assert (km.get("chooser", "key1"))