From 4dd11abae221fdd76d863487fac16ee45b05c96b Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Mon, 19 Mar 2012 10:18:21 -0400 Subject: Fixed #85. Odict now handles link errors correctly. Also added a test. Thanks for the report. --- markdown/odict.py | 6 +++--- tests/test_apis.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/markdown/odict.py b/markdown/odict.py index bf3ef07..36d5553 100644 --- a/markdown/odict.py +++ b/markdown/odict.py @@ -150,13 +150,13 @@ class OrderedDict(dict): """ Change location of an existing item. """ n = self.keyOrder.index(key) del self.keyOrder[n] - i = self.index_for_location(location) try: + i = self.index_for_location(location) if i is not None: self.keyOrder.insert(i, key) else: self.keyOrder.append(key) - except Error: + except Exception as e: # restore to prevent data loss and reraise self.keyOrder.insert(n, key) - raise Error + raise e diff --git a/tests/test_apis.py b/tests/test_apis.py index 218c009..0296f27 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -214,6 +214,14 @@ class TestOrderedDict(unittest.TestCase): [('first', 'This'), ('fourth', 'self'), ('third', 'a'), ('fifth', 'test')]) + def textBadLink(self): + """ Test OrderedDict change order with bad location. """ + self.assertRaises(ValueError, self.odict.link('fourth', '