Exemplo n.º 1
0
        def run_leo_startup_node(self):

            c = self.c
            p = g.findNodeAnywhere(c,'@ipy-startup')
            if p:
                print("Running @ipy-startup nodes")
                for n in LeoNode(p):
                    # self.push_from_leo(n)
                    CommandChainDispatcher(n)
Exemplo n.º 2
0
def test_command_chain_dispatcher_fofo():
    """Test a mixture of failing and succeeding hooks."""
    fail1 = Fail(u'fail1')
    fail2 = Fail(u'fail2')
    okay1 = Okay(u'okay1')
    okay2 = Okay(u'okay2')

    dp = CommandChainDispatcher([(0, fail1),
                                 # (5, okay1), # add this later
                                 (10, fail2),
                                 (15, okay2)])
    dp.add(okay1, 5)

    nt.assert_equal(dp(), u'okay1')

    nt.assert_true(fail1.called)
    nt.assert_true(okay1.called)
    nt.assert_false(fail2.called)
    nt.assert_false(okay2.called)
Exemplo n.º 3
0
def test_command_chain_dispatcher_fofo():
    """Test a mixture of failing and succeeding hooks."""
    fail1 = Fail(u'fail1')
    fail2 = Fail(u'fail2')
    okay1 = Okay(u'okay1')
    okay2 = Okay(u'okay2')

    dp = CommandChainDispatcher([(0, fail1),
                                 # (5, okay1), # add this later
                                 (10, fail2),
                                 (15, okay2)])
    dp.add(okay1, 5)

    nt.assert_equal(dp(), u'okay1')

    nt.assert_true(fail1.called)
    nt.assert_true(okay1.called)
    nt.assert_false(fail2.called)
    nt.assert_false(okay2.called)
Exemplo n.º 4
0
        def push_to_ipython(self):

            c,ip = self.c,self.ip
            if not c:
                return g.trace('can not happen: no c.')

            if not self.ip:
                return g.trace('can not happen: no ip.')

            c.inCommand = False # Disable the command lockout logic

            n = LeoNode(c.p)

            def f(self=self,n=n):
                self.push_ipython_script(n)
                return True
            d = CommandChainDispatcher()
            d.add(f)
            d()
Exemplo n.º 5
0
def test_command_chain_dispatcher_fofo():
    """Test a mixture of failing and succeeding hooks."""
    fail1 = Fail("fail1")
    fail2 = Fail("fail2")
    okay1 = Okay("okay1")
    okay2 = Okay("okay2")

    dp = CommandChainDispatcher([
        (0, fail1),
        # (5, okay1), # add this later
        (10, fail2),
        (15, okay2)
    ])
    dp.add(okay1, 5)

    assert dp() == "okay1"

    assert fail1.called is True
    assert okay1.called is True
    assert fail2.called is False
    assert okay2.called is False
Exemplo n.º 6
0
def test_command_chain_dispatcher_ff():
    """Test two failing hooks"""
    fail1 = Fail("fail1")
    fail2 = Fail("fail2")
    dp = CommandChainDispatcher([(0, fail1), (10, fail2)])

    with pytest.raises(TryNext) as e:
        dp()
    assert str(e.value) == "fail2"

    assert fail1.called is True
    assert fail2.called is True
Exemplo n.º 7
0
        def push_position_from_leo(self,p):

            try:
                d = CommandChainDispatcher(LeoNode(p))
                d()

            except AttributeError as e:
                if e.args == ("Commands instance has no attribute 'frame'",):
                    es("Error: ILeo not associated with .leo document")
                    es("Press alt+shift+I to fix!")
                else:
                    raise
Exemplo n.º 8
0
def test_command_chain_dispatcher_ff():
    """Test two failing hooks"""
    fail1 = Fail(u'fail1')
    fail2 = Fail(u'fail2')
    dp = CommandChainDispatcher([(0, fail1), (10, fail2)])

    try:
        dp()
    except TryNext as e:
        nt.assert_equal(str(e), u'fail2')
    else:
        assert False, "Expected exception was not raised."

    nt.assert_true(fail1.called)
    nt.assert_true(fail2.called)
Exemplo n.º 9
0
def test_command_chain_dispatcher_ff():
    """Test two failing hooks"""
    fail1 = Fail("fail1")
    fail2 = Fail("fail2")
    dp = CommandChainDispatcher([(0, fail1), (10, fail2)])

    try:
        dp()
    except TryNext as e:
        assert str(e) == "fail2"
    else:
        assert False, "Expected exception was not raised."

    assert fail1.called is True
    assert fail2.called is True
Exemplo n.º 10
0
def test_command_chain_dispatcher_eq_priority():
    okay1 = Okay(u'okay1')
    okay2 = Okay(u'okay2')
    dp = CommandChainDispatcher([(1, okay1)])
    dp.add(okay2, 1)
Exemplo n.º 11
0
    def add_re(self, regex, obj, priority=0):
        """ Adds a target regexp for dispatching """

        chain = self.regexs.get(regex, CommandChainDispatcher())
        chain.add(obj, priority)
        self.regexs[regex] = chain
Exemplo n.º 12
0
    def add_s(self, s, obj, priority=0):
        """ Adds a target 'string' for dispatching """

        chain = self.strs.get(s, CommandChainDispatcher())
        chain.add(obj, priority)
        self.strs[s] = chain
Exemplo n.º 13
0
def test_command_chain_dispatcher_eq_priority():
    okay1 = Okay(u"okay1")
    okay2 = Okay(u"okay2")
    dp = CommandChainDispatcher([(1, okay1)])
    dp.add(okay2, 1)
Exemplo n.º 14
0
 def ipush(self):
     """ Does push-to-ipython on the node """
     # push_from_leo(self)
     CommandChainDispatcher(self)
Exemplo n.º 15
0
        def expose_ileo_push(self,f,priority=0):

            # self.push_from_leo.add(f,priority)
            CommandChainDispatcher().add(f,priority)