Skip to content

Commit

Permalink
Fix adding functions to CommandChainDispatcher with equal priority on…
Browse files Browse the repository at this point in the history
… Python 3.

Closes ipythongh-1916
  • Loading branch information
takluyver committed Jun 12, 2012
1 parent a84a429 commit aaae6cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions IPython/core/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def calljed(self,filename, linenum):
# the file COPYING, distributed as part of this software.
#*****************************************************************************

import os, bisect
import os
import operator
import subprocess
import sys

Expand Down Expand Up @@ -146,7 +147,8 @@ def __str__(self):

def add(self, func, priority=0):
""" Add a func to the cmd chain with given priority """
bisect.insort(self.chain,(priority,func))
self.chain.append((priority, func))
self.chain.sort(key=operator.itemgetter(0))

def __iter__(self):
""" Return all objects in chain.
Expand Down
6 changes: 6 additions & 0 deletions IPython/core/tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ def test_command_chain_dispatcher_fofo():
nt.assert_true(okay1.called)
nt.assert_false(fail2.called)
nt.assert_false(okay2.called)

def test_command_chain_dispatcher_eq_priority():
okay1 = Okay(u'okay1')
okay2 = Okay(u'okay2')
dp = CommandChainDispatcher([(1, okay1)])
dp.add(okay2, 1)

0 comments on commit aaae6cc

Please sign in to comment.