##// END OF EJS Templates
Fix adding functions to CommandChainDispatcher with equal priority on Python 3....
Thomas Kluyver -
Show More
@@ -41,7 +41,8 b' somewhere in your configuration files or ipython command line.'
41 # the file COPYING, distributed as part of this software.
41 # the file COPYING, distributed as part of this software.
42 #*****************************************************************************
42 #*****************************************************************************
43
43
44 import os, bisect
44 import os
45 import operator
45 import subprocess
46 import subprocess
46 import sys
47 import sys
47
48
@@ -146,7 +147,8 b' class CommandChainDispatcher:'
146
147
147 def add(self, func, priority=0):
148 def add(self, func, priority=0):
148 """ Add a func to the cmd chain with given priority """
149 """ Add a func to the cmd chain with given priority """
149 bisect.insort(self.chain,(priority,func))
150 self.chain.append((priority, func))
151 self.chain.sort(key=operator.itemgetter(0))
150
152
151 def __iter__(self):
153 def __iter__(self):
152 """ Return all objects in chain.
154 """ Return all objects in chain.
@@ -73,3 +73,9 b' def test_command_chain_dispatcher_fofo():'
73 nt.assert_true(okay1.called)
73 nt.assert_true(okay1.called)
74 nt.assert_false(fail2.called)
74 nt.assert_false(fail2.called)
75 nt.assert_false(okay2.called)
75 nt.assert_false(okay2.called)
76
77 def test_command_chain_dispatcher_eq_priority():
78 okay1 = Okay(u'okay1')
79 okay2 = Okay(u'okay2')
80 dp = CommandChainDispatcher([(1, okay1)])
81 dp.add(okay2, 1)
General Comments 0
You need to be logged in to leave comments. Login now